Expand description
Squire provides an idiomatic and performant Rust interface for SQLite.
ⓘ
use squire::{Columns, Connection, Database};
#[derive(Columns, PartialEq, Eq, Clone, Debug)]
struct User {
id: u64,
username: String,
email: Option<String>,
}
let connection = Connection::open(Database::memory())?;
connection.execute(
"CREATE TABLE users (
id INTEGER PRIMARY KEY,
username TEXT NOT NULL,
email TEXT
) STRICT",
(), // no parameters
)?;
let mut add_user = connection.prepare("INSERT INTO users (username, email) VALUES (?, ?)")?;
add_user.execute(("alice", "alice@example.com"))?;
add_user.execute(("bob", None::<&str>))?;
let mut select_users = connection.prepare("SELECT * FROM users")?;
let users: Vec<User> = select_users.query(())?.all()?;
assert_eq!(
users,
vec![
User { id: 1, username: "alice".to_owned(), email: Some("alice@example.com".to_owned()) },
User { id: 2, username: "bob".to_owned(), email: None },
],
);Modules§
- ffi
- The
ffimodule gives lower-levelunsafeaccess to the SQLite API. - iter
Iteratorimplementations forRows.
Structs§
- Bind
Index - A SQLite prepared statement parameter index, used when binding values to a statement.
- Bind
Indexes - Binding
- Borrowed
- A borrowed reference that can be used for zero-copy parameter binding and column value access.
- Column
Index - A SQLite column index, used for reading values out of queried rows.
- Connection
- A connection to one or more open SQLite database(s).
- Connection
Builder - Database
- Error
- An error returned by Squire.
- Error
Code - A SQLite error return code.
- Error
Container - Wraps an
IntegrationErrormember that is not cloneable inArc. - Error
Location - The offset within an SQL source input of an
Error. - Execution
- Json
jsonandserde - A value which is stored in SQLite serialized as JSON.
- Jsonb
jsonbandserde - A value which is stored in SQLite serialized as JSONB.
- Prepare
Options - Controls the behavior of preparing a
Statement. - Reservation
- A request for SQLite to allocate a blob of a certain size.
- Row
- RowId
- Rows
- Statement
- A prepared statement; an SQL statement that SQLite has compiled and made ready to bind and execute.
- Statement
Columns - Statement
Parameters
Enums§
- Abort
Error - Authorization
Error - Busy
Error - Cant
Open Error - Constraint
Error - Corrupt
Error - Error
Category - The category of
Errorthat occurred. - Error
Reason - Extended SQLite result codes that provide more specific information about errors.
- Fetch
Error - An error reading a SQLite column value into its Rust type.
- General
Error - Integration
Error - An error from a crate that Squire integrates with.
- IoError
- Locked
Error - Parameter
Error - An error passing prepared statement parameter(s) to SQLite.
- Read
Only Error - Type
- The datatype of a SQLite column value.
Traits§
- Bind
- A value which can be bound as a parameter in SQLite prepared statements.
- Column
Indexes - Columns
- Fetch
- Into
Location - Parameters
- Query
- An SQL query which can prepare itself into a
Statement, bind itself asParametersto the statement (if any), and read any desired output from the statement execution.