451 lines
No EOL
25 KiB
HTML
451 lines
No EOL
25 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="generator" content="rustdoc">
|
||
<meta name="description" content="API documentation for the Rust `rusqlite` crate.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, rusqlite">
|
||
|
||
<title>rusqlite - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../normalize.css">
|
||
<link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
|
||
|
||
<link rel="stylesheet" type="text/css" href="../dark.css">
|
||
<link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
|
||
<script src="../storage.js"></script>
|
||
|
||
|
||
|
||
|
||
</head>
|
||
<body class="rustdoc mod">
|
||
<!--[if lte IE 8]>
|
||
<div class="warning">
|
||
This old browser is unsupported and will most likely display funky
|
||
things.
|
||
</div>
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
<div class="sidebar-menu">☰</div>
|
||
|
||
<p class='location'>Crate rusqlite</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'rusqlite', ty: 'mod', relpath: '../'};</script></div>
|
||
</nav>
|
||
|
||
<div class="theme-picker">
|
||
<button id="theme-picker" aria-label="Pick another theme!">
|
||
<img src="../brush.svg" width="18" alt="Pick another theme!">
|
||
</button>
|
||
<div id="theme-choices"></div>
|
||
</div>
|
||
<script src="../theme.js"></script>
|
||
<nav class="sub">
|
||
<form class="search-form js-only">
|
||
<div class="search-container">
|
||
<input class="search-input" name="search"
|
||
autocomplete="off"
|
||
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
||
type="search">
|
||
</div>
|
||
</form>
|
||
</nav>
|
||
|
||
<section id='main' class="content">
|
||
<h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>rusqlite</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a class='srclink' href='../src/rusqlite/lib.rs.html#1-1472' title='goto source code'>[src]</a></span></h1>
|
||
<div class='docblock'><p>Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose
|
||
an interface similar to <a href="https://github.com/sfackler/rust-postgres">rust-postgres</a>.</p>
|
||
|
||
<pre class="rust rust-example-rendered">
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rusqlite</span>;
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">time</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Timespec</span>;
|
||
<span class="kw">use</span> <span class="ident">rusqlite</span>::<span class="ident">Connection</span>;
|
||
|
||
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>)]</span>
|
||
<span class="kw">struct</span> <span class="ident">Person</span> {
|
||
<span class="ident">id</span>: <span class="ident">i32</span>,
|
||
<span class="ident">name</span>: <span class="ident">String</span>,
|
||
<span class="ident">time_created</span>: <span class="ident">Timespec</span>,
|
||
<span class="ident">data</span>: <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">u8</span><span class="op">>></span>
|
||
}
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
<span class="kw">let</span> <span class="ident">conn</span> <span class="op">=</span> <span class="ident">Connection</span>::<span class="ident">open_in_memory</span>().<span class="ident">unwrap</span>();
|
||
|
||
<span class="ident">conn</span>.<span class="ident">execute</span>(<span class="string">"CREATE TABLE person (
|
||
id INTEGER PRIMARY KEY,
|
||
name TEXT NOT NULL,
|
||
time_created TEXT NOT NULL,
|
||
data BLOB
|
||
)"</span>, <span class="kw-2">&</span>[]).<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="ident">me</span> <span class="op">=</span> <span class="ident">Person</span> {
|
||
<span class="ident">id</span>: <span class="number">0</span>,
|
||
<span class="ident">name</span>: <span class="string">"Steven"</span>.<span class="ident">to_string</span>(),
|
||
<span class="ident">time_created</span>: <span class="ident">time</span>::<span class="ident">get_time</span>(),
|
||
<span class="ident">data</span>: <span class="prelude-val">None</span>
|
||
};
|
||
<span class="ident">conn</span>.<span class="ident">execute</span>(<span class="string">"INSERT INTO person (name, time_created, data)
|
||
VALUES (?1, ?2, ?3)"</span>,
|
||
<span class="kw-2">&</span>[<span class="kw-2">&</span><span class="ident">me</span>.<span class="ident">name</span>, <span class="kw-2">&</span><span class="ident">me</span>.<span class="ident">time_created</span>, <span class="kw-2">&</span><span class="ident">me</span>.<span class="ident">data</span>]).<span class="ident">unwrap</span>();
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stmt</span> <span class="op">=</span> <span class="ident">conn</span>.<span class="ident">prepare</span>(<span class="string">"SELECT id, name, time_created, data FROM person"</span>).<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="ident">person_iter</span> <span class="op">=</span> <span class="ident">stmt</span>.<span class="ident">query_map</span>(<span class="kw-2">&</span>[], <span class="op">|</span><span class="ident">row</span><span class="op">|</span> {
|
||
<span class="ident">Person</span> {
|
||
<span class="ident">id</span>: <span class="ident">row</span>.<span class="ident">get</span>(<span class="number">0</span>),
|
||
<span class="ident">name</span>: <span class="ident">row</span>.<span class="ident">get</span>(<span class="number">1</span>),
|
||
<span class="ident">time_created</span>: <span class="ident">row</span>.<span class="ident">get</span>(<span class="number">2</span>),
|
||
<span class="ident">data</span>: <span class="ident">row</span>.<span class="ident">get</span>(<span class="number">3</span>)
|
||
}
|
||
}).<span class="ident">unwrap</span>();
|
||
|
||
<span class="kw">for</span> <span class="ident">person</span> <span class="kw">in</span> <span class="ident">person_iter</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Found person {:?}"</span>, <span class="ident">person</span>.<span class="ident">unwrap</span>());
|
||
}
|
||
}</pre>
|
||
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="limits/index.html"
|
||
title='mod rusqlite::limits'>limits</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Run-Time Limits</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="mod" href="types/index.html"
|
||
title='mod rusqlite::types'>types</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Traits dealing with SQLite data types.</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.AndThenRows.html"
|
||
title='struct rusqlite::AndThenRows'>AndThenRows</a></td>
|
||
<td class='docblock-short'>
|
||
<p>An iterator over the mapped resulting rows of a query, with an Error type
|
||
unifying with Error.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.CachedStatement.html"
|
||
title='struct rusqlite::CachedStatement'>CachedStatement</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Cacheable statement.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Connection.html"
|
||
title='struct rusqlite::Connection'>Connection</a></td>
|
||
<td class='docblock-short'>
|
||
<p>A connection to a SQLite database.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.MappedRows.html"
|
||
title='struct rusqlite::MappedRows'>MappedRows</a></td>
|
||
<td class='docblock-short'>
|
||
<p>An iterator over the mapped resulting rows of a query.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.OpenFlags.html"
|
||
title='struct rusqlite::OpenFlags'>OpenFlags</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Flags for opening SQLite database connections.
|
||
See <a href="http://www.sqlite.org/c3ref/open.html">sqlite3_open_v2</a> for details.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Row.html"
|
||
title='struct rusqlite::Row'>Row</a></td>
|
||
<td class='docblock-short'>
|
||
<p>A single result row of a query.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Rows.html"
|
||
title='struct rusqlite::Rows'>Rows</a></td>
|
||
<td class='docblock-short'>
|
||
<p>An handle for the resulting rows of a query.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Savepoint.html"
|
||
title='struct rusqlite::Savepoint'>Savepoint</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Represents a savepoint on a database connection.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Statement.html"
|
||
title='struct rusqlite::Statement'>Statement</a></td>
|
||
<td class='docblock-short'>
|
||
<p>A prepared statement.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="struct" href="struct.Transaction.html"
|
||
title='struct rusqlite::Transaction'>Transaction</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Represents a transaction on a database connection.</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="enum" href="enum.DatabaseName.html"
|
||
title='enum rusqlite::DatabaseName'>DatabaseName</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Name for a database within a SQLite connection.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="enum" href="enum.DropBehavior.html"
|
||
title='enum rusqlite::DropBehavior'>DropBehavior</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Options for how a Transaction or Savepoint should behave when it is dropped.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="enum" href="enum.Error.html"
|
||
title='enum rusqlite::Error'>Error</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Enum listing possible errors from rusqlite.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="enum" href="enum.ErrorCode.html"
|
||
title='enum rusqlite::ErrorCode'>ErrorCode</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Error Codes</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="enum" href="enum.TransactionBehavior.html"
|
||
title='enum rusqlite::TransactionBehavior'>TransactionBehavior</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Options for transaction behavior. See <a href="http://www.sqlite.org/lang_transaction.html">BEGIN
|
||
TRANSACTION</a> for details.</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="trait" href="trait.RowIndex.html"
|
||
title='trait rusqlite::RowIndex'>RowIndex</a></td>
|
||
<td class='docblock-short'>
|
||
<p>A trait implemented by types that can index into columns of a row.</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="fn" href="fn.bypass_sqlite_initialization.html"
|
||
title='fn rusqlite::bypass_sqlite_initialization'>bypass_sqlite_initialization</a><a title='unsafe function' href='#'><sup>⚠</sup></a></td>
|
||
<td class='docblock-short'>
|
||
<p>rusqlite's check for a safe SQLite threading mode requires SQLite 3.7.0 or later. If you are
|
||
running against a SQLite older than that, rusqlite attempts to ensure safety by performing
|
||
configuration and initialization of SQLite itself the first time you attempt to open a
|
||
connection. By default, rusqlite panics if that initialization fails, since that could mean
|
||
SQLite has been initialized in single-thread mode.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="fn" href="fn.bypass_sqlite_version_check.html"
|
||
title='fn rusqlite::bypass_sqlite_version_check'>bypass_sqlite_version_check</a><a title='unsafe function' href='#'><sup>⚠</sup></a></td>
|
||
<td class='docblock-short'>
|
||
<p>rusqlite performs a one-time check that the runtime SQLite version is at least as new as
|
||
the version of SQLite found when rusqlite was built. Bypassing this check may be dangerous;
|
||
e.g., if you use features of SQLite that are not present in the runtime version. If you are
|
||
sure the runtime version is compatible with the build-time version for your usage, you can
|
||
bypass the version check by calling this function before your first connection attempt.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="fn" href="fn.version.html"
|
||
title='fn rusqlite::version'>version</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Returns the SQLite version as a string; e.g., <code>"3.16.2"</code> for version 3.16.2.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="fn" href="fn.version_number.html"
|
||
title='fn rusqlite::version_number'>version_number</a></td>
|
||
<td class='docblock-short'>
|
||
<p>Returns the SQLite version as an integer; e.g., <code>3016002</code> for version 3.16.2.</p>
|
||
|
||
</td>
|
||
</tr></table><h2 id='types' class='section-header'><a href="#types">Type Definitions</a></h2>
|
||
<table>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.Result.html"
|
||
title='type rusqlite::Result'>Result</a></td>
|
||
<td class='docblock-short'>
|
||
<p>A typedef of the result returned by many methods.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteConnection.html"
|
||
title='type rusqlite::SqliteConnection'>SqliteConnection</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Connection</code>. <code>SqliteConnection</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteError.html"
|
||
title='type rusqlite::SqliteError'>SqliteError</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Error</code>. <code>SqliteError</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteOpenFlags.html"
|
||
title='type rusqlite::SqliteOpenFlags'>SqliteOpenFlags</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>OpenFlags</code>. <code>SqliteOpenFlags</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteResult.html"
|
||
title='type rusqlite::SqliteResult'>SqliteResult</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Result</code>. <code>SqliteResult</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteRow.html"
|
||
title='type rusqlite::SqliteRow'>SqliteRow</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Row</code>. <code>SqliteRow</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteRows.html"
|
||
title='type rusqlite::SqliteRows'>SqliteRows</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Rows</code>. <code>SqliteRows</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteStatement.html"
|
||
title='type rusqlite::SqliteStatement'>SqliteStatement</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Statement</code>. <code>SqliteStatement</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteTransaction.html"
|
||
title='type rusqlite::SqliteTransaction'>SqliteTransaction</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>Transaction</code>. <code>SqliteTransaction</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr>
|
||
<tr class=' module-item'>
|
||
<td><a class="type" href="type.SqliteTransactionBehavior.html"
|
||
title='type rusqlite::SqliteTransactionBehavior'>SqliteTransactionBehavior</a></td>
|
||
<td class='docblock-short'>
|
||
[<div class='stab deprecated'>Deprecated</div>] <p>Old name for <code>TransactionBehavior</code>. <code>SqliteTransactionBehavior</code> is deprecated.</p>
|
||
|
||
</td>
|
||
</tr></table></section>
|
||
<section id='search' class="content hidden"></section>
|
||
|
||
<section class="footer"></section>
|
||
|
||
<aside id="help" class="hidden">
|
||
<div>
|
||
<h1 class="hidden">Help</h1>
|
||
|
||
<div class="shortcuts">
|
||
<h2>Keyboard Shortcuts</h2>
|
||
|
||
<dl>
|
||
<dt><kbd>?</kbd></dt>
|
||
<dd>Show this help dialog</dd>
|
||
<dt><kbd>S</kbd></dt>
|
||
<dd>Focus the search field</dd>
|
||
<dt><kbd>↑</kbd></dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt><kbd>↓</kbd></dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt><kbd>↹</kbd></dt>
|
||
<dd>Switch tab</dd>
|
||
<dt><kbd>⏎</kbd></dt>
|
||
<dd>Go to active search result</dd>
|
||
<dt><kbd>+</kbd></dt>
|
||
<dd>Expand all sections</dd>
|
||
<dt><kbd>-</kbd></dt>
|
||
<dd>Collapse all sections</dd>
|
||
</dl>
|
||
</div>
|
||
|
||
<div class="infos">
|
||
<h2>Search Tricks</h2>
|
||
|
||
<p>
|
||
Prefix searches with a type followed by a colon (e.g.
|
||
<code>fn:</code>) to restrict the search to a given type.
|
||
</p>
|
||
|
||
<p>
|
||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||
<code>struct</code>, <code>enum</code>,
|
||
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
||
and <code>const</code>.
|
||
</p>
|
||
|
||
<p>
|
||
Search functions by type signature (e.g.
|
||
<code>vec -> usize</code> or <code>* -> vec</code>)
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../";
|
||
window.currentCrate = "rusqlite";
|
||
</script>
|
||
<script src="../main.js"></script>
|
||
<script defer src="../search-index.js"></script>
|
||
</body>
|
||
</html> |