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::Connection;

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

fn main() {
    let conn = Connection::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());
    }
}

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 Error.

Connection

A connection to a SQLite database.

MappedRows

An iterator over the mapped resulting rows of a query.

OpenFlags

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

Row

A single result row of a query.

Rows

An iterator over the resulting rows of a query.

Statement

A prepared statement.

Transaction

Represents a transaction on a database connection.

Enums

DatabaseName

Name for a database within a SQLite connection.

Error

Enum listing possible errors from rusqlite.

TransactionBehavior

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

Result

A typedef of the result returned by many methods.

SqliteConnection

Old name for Connection. SqliteConnection is deprecated.

SqliteError

Old name for Error. SqliteError is deprecated.

SqliteOpenFlags

Old name for OpenFlags. SqliteOpenFlags is deprecated.

SqliteResult

Old name for Result. SqliteResult is deprecated.

SqliteRow

Old name for Row. SqliteRow is deprecated.

SqliteRows

Old name for Rows. SqliteRows is deprecated.

SqliteStatement

Old name for Statement. SqliteStatement is deprecated.

SqliteTransaction

Old name for Transaction. SqliteTransaction is deprecated.