Crate rusqlite [] [src]

Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres.

extern crate rusqlite;
extern crate time;

use time::Timespec;
use rusqlite::SqliteConnection;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    time_created: Timespec,
    data: Option<Vec<u8>>
}

fn main() {
    let conn = SqliteConnection::open_in_memory().unwrap();

    conn.execute("CREATE TABLE person (
                  id              INTEGER PRIMARY KEY,
                  name            TEXT NOT NULL,
                  time_created    TEXT NOT NULL,
                  data            BLOB
                  )", &[]).unwrap();
    let me = Person {
        id: 0,
        name: "Steven".to_string(),
        time_created: time::get_time(),
        data: None
    };
    conn.execute("INSERT INTO person (name, time_created, data)
                  VALUES ($1, $2, $3)",
                 &[&me.name, &me.time_created, &me.data]).unwrap();

    let mut stmt = conn.prepare("SELECT id, name, time_created, data FROM person").unwrap();
    let mut person_iter = stmt.query_map(&[], |row| {
        Person {
            id: row.get(0),
            name: row.get(1),
            time_created: row.get(2),
            data: row.get(3)
        }
    }).unwrap();

    for person in person_iter {
        println!("Found person {:?}", person.unwrap());
    }
}

Reexports

pub use transaction::{SqliteTransactionDeferred, SqliteTransactionImmediate, SqliteTransactionExclusive};

Modules

types

Traits dealing with SQLite data types.

Structs

AndThenRows

An iterator over the mapped resulting rows of a query, with an Error type unifying with SqliteError.

MappedRows

An iterator over the mapped resulting rows of a query.

SqliteConnection

A connection to a SQLite database.

SqliteError

Encompasses an error result from a call to the SQLite C API.

SqliteOpenFlags

Flags for opening SQLite database connections. See sqlite3_open_v2 for details.

SqliteRow

A single result row of a query.

SqliteRows

An iterator over the resulting rows of a query.

SqliteStatement

A prepared statement.

SqliteTransaction

Represents a transaction on a database connection.

Enums

SqliteTransactionBehavior

Options for transaction behavior. See BEGIN TRANSACTION for details.

Constants

SQLITE_OPEN_CREATE
SQLITE_OPEN_FULL_MUTEX
SQLITE_OPEN_MEMORY
SQLITE_OPEN_NO_MUTEX
SQLITE_OPEN_PRIVATE_CACHE
SQLITE_OPEN_READ_ONLY
SQLITE_OPEN_READ_WRITE
SQLITE_OPEN_SHARED_CACHE
SQLITE_OPEN_URI

Type Definitions

SqliteResult

A typedef of the result returned by many methods.