Expand description
Squire provides an idiomatic and performant Rust interface for SQLite.
use squire::{Columns, Connection, Memory};
#[derive(Columns, PartialEq, Eq, Clone, Debug)]
struct User {
id: u64,
username: String,
email: Option<String>,
}
let connection = Connection::open(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§
Structs§
- Bind
Index - A SQLite prepared statement parameter index, used when binding values to a statement.
- Binding
- A mutable set of parameters bound to a
Statement. - Borrowed
- A 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 - Configure a
Connectionto be opened. - 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 a SQL source input of an
Error. - Execution
- An executing query of a
Statement. - Function
Options functions - Json
jsonandserde - A value which is stored in SQLite serialized as JSON.
- Jsonb
jsonbandserde - A value which is stored in SQLite serialized as JSONB.
- Local
- A local filesystem SQLite database
Endpoint. - Memory
- An in-memory, ephemeral SQLite database
Endpoint. - Prepare
Options - Controls the behavior of preparing a
Statement. - Reservation
- A request for SQLite to allocate a blob of a certain size.
- Row
- Access individual columns in a row returned from
Execution. - RowId
- A SQLite row ID.
- Rows
- Access the
Columnsof each row returned by a query. - Statement
- A prepared statement; a SQL statement that SQLite has compiled and made ready to bind and execute.
- Statement
Columns - Inspect the columns that a
Statementwill return. - Statement
Parameters - Inspect the binding parameters that a
Statementaccepts. - Uri
- A SQLite database URI
Endpoint.
Enums§
- Abort
Error - Specific reasons for an
ErrorCategory::Aborted. - Authorization
Error - Specific reasons for an
ErrorCategory::Aborted. - Busy
Error - Specific reason for an
ErrorCategory::Busy. - Byte
Order utf-16 - Cant
Open Error - Specific reason for an
ErrorCategory::CantOpen. - Constraint
Error - Specific reason for an
ErrorCategory::Constraint. - Corrupt
Error - Specific reason for an
ErrorCategory::Corrupt. - Encoding
- Text encodings recognized by SQLite.
- 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 - Specific reason for an
ErrorCategory::Unknown. - Integration
Error - An error from a crate that Squire integrates with.
- IoError
- Specific reason for an
ErrorCategory::Io. - Locked
Error - Specific reason for an
ErrorCategory::Locked. - Parameter
Error - An error passing prepared statement parameter(s) to SQLite.
- Read
Only Error - Specific reason for an
ErrorCategory::ReadOnly. - RowError
- An error retrieving a row from SQLite.
- Text
Encoding Error - An error interpreting bytes through a text encoding (e.g., UTF-8).
- 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 - Specifies the
ColumnIndexvalues needed byColumns. - Columns
- Fetches the values of each column in a row.
- Endpoint
- Specifies which SQLite database to open.
- Fetch
- A value which can be read from a column or function argument.
- Into
Endpoint - A value which can be used as a database
Endpoint. - Parameters
- Binds the values of each parameter of a
Statement. - Query
- A 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.
Type Aliases§
Derive Macros§
- Columns
derive - Derive macro for implementing the
Columnstrait. - Parameters
derive - Derive macro for implementing the
Parameterstrait.