Crate squire

Crate squire 

Source
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 ffi module gives lower-level unsafe access to the SQLite API.
iter
Iterator implementations for Rows.

Structs§

BindIndex
A SQLite prepared statement parameter index, used when binding values to a statement.
BindIndexes
Binding
Borrowed
A borrowed 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
Database
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 an SQL source input of an Error.
Execution
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.
PrepareOptions
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.
StatementColumns
StatementParameters

Enums§

AbortError
AuthorizationError
BusyError
CantOpenError
ConstraintError
CorruptError
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
IntegrationError
An error from a crate that Squire integrates with.
IoError
LockedError
ParameterError
An error passing prepared statement parameter(s) to SQLite.
ReadOnlyError
Type
The datatype of a SQLite column value.

Traits§

Bind
A value which can be bound as a parameter in SQLite prepared statements.
ColumnIndexes
Columns
Fetch
IntoLocation
Parameters
Query
An 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.