Skip to main content

Crate squire

Crate squire 

Source
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§

ffi
The ffi module gives lower-level unsafe access to the SQLite API.
iter
Iterator implementations.

Structs§

BindIndex
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.
ColumnIndex
A SQLite column index, used for reading values out of queried rows.
Connection
A connection to one or more open SQLite database(s).
ConnectionBuilder
Configure a Connection to be opened.
Error
An error returned by Squire.
ErrorCode
A SQLite error return code.
ErrorContainer
Wraps an IntegrationError member that is not cloneable in Arc.
ErrorLocation
The offset within a SQL source input of an Error.
Execution
An executing query of a Statement.
FunctionOptionsfunctions
Jsonjson and serde
A value which is stored in SQLite serialized as JSON.
Jsonbjsonb and serde
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.
PrepareOptions
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 Columns of each row returned by a query.
Statement
A prepared statement; a SQL statement that SQLite has compiled and made ready to bind and execute.
StatementColumns
Inspect the columns that a Statement will return.
StatementParameters
Inspect the binding parameters that a Statement accepts.
Uri
A SQLite database URI Endpoint.

Enums§

AbortError
Specific reasons for an ErrorCategory::Aborted.
AuthorizationError
Specific reasons for an ErrorCategory::Aborted.
BusyError
Specific reason for an ErrorCategory::Busy.
ByteOrderutf-16
CantOpenError
Specific reason for an ErrorCategory::CantOpen.
ConstraintError
Specific reason for an ErrorCategory::Constraint.
CorruptError
Specific reason for an ErrorCategory::Corrupt.
Encoding
Text encodings recognized by SQLite.
ErrorCategory
The category of Error that occurred.
ErrorReason
Extended SQLite result codes that provide more specific information about errors.
FetchError
An error reading a SQLite column value into its Rust type.
GeneralError
Specific reason for an ErrorCategory::Unknown.
IntegrationError
An error from a crate that Squire integrates with.
IoError
Specific reason for an ErrorCategory::Io.
LockedError
Specific reason for an ErrorCategory::Locked.
ParameterError
An error passing prepared statement parameter(s) to SQLite.
ReadOnlyError
Specific reason for an ErrorCategory::ReadOnly.
RowError
An error retrieving a row from SQLite.
TextEncodingError
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.
ColumnIndexes
Specifies the ColumnIndex values needed by Columns.
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.
IntoEndpoint
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 as Parameters to the statement (if any), and read any desired output from the statement execution.

Type Aliases§

Result
A Result returned by Squire.

Derive Macros§

Columnsderive
Derive macro for implementing the Columns trait.
Parametersderive
Derive macro for implementing the Parameters trait.