Skip to main content

Crate rhosql

Crate rhosql 

Source
Expand description

§Rhosql

Simple SQLite driver.

The existing rusqlite crate is just not sufficient for me, so i made my own.

§Usage

use rhosql::Connection;

// derive macro
#[derive(rhosql::FromRow)]
struct Post {
    id: i32,
    name: String,
}

let mut db = Connection::open_in_memory()?;

// execute single statement
rhosql::query("create table post(name)", &mut db).execute()?;

let id = rhosql::query("insert into post(name) values(?1)", &mut db)
    .bind("Control")
    .execute()?;

// using custom struct
let posts = rhosql::query("select rowid,* from post", &mut db).fetch_all::<Post>()?;

assert_eq!(posts[0].id as i64, id);
assert_eq!(posts[0].name, "Control");

// using tuple
let posts = rhosql::query("select rowid,* from post", &mut db).fetch_all::<(i32, String)>()?;

assert_eq!(posts[0].0 as i64, id);
assert_eq!(posts[0].1, "Control");

// iterator based
let mut posts = rhosql::query("select rowid,* from post", &mut db).fetch()?;

while let Some(post) = posts.next_row::<Post>()? {
    assert_eq!(post.id as i64, id);
    assert_eq!(post.name, "Control");
}

Modules§

query
Types for query api.
sqlite
A safe interface to sqlite ffi.

Structs§

Connection
Database connection.
Row
Row buffer.
RowStream
Bounded prepared statement and ready for iteration.
SerializeConnection

Enums§

Error
An error which can occur in sqlite operation.
ValueRef
A borrowed sqlite value.

Traits§

Decode
A type that can be construced from sqlite value.
FromRow
A type that can be construced from sqlite row.
SqliteStr
Conversion between sqlite and rust string

Functions§

query
Query api.

Type Aliases§

Result
Represent success or error for sqlite operation.

Derive Macros§

FromRow
Automatically implement FromRow for custom struct.