Struct Database

Source
pub struct Database {
    pub db: *mut sqlite3,
}

Fields§

§db: *mut sqlite3

Implementations§

Source§

impl Database

Source

pub fn open(path: &str) -> Result<Database>

open an existing sqlite3 database or create a new one.

let database = Database::open(":memory:")?;
Source

pub fn open_with_flags(path: &str, flags: c_int) -> Result<Database>

open a sqlite3 database with explicit flags

use sqlite3_sys as ffi;

let database = Database::open_with_flags(
    ":memory:",
    ffi::SQLITE_OPEN_CREATE | ffi::SQLITE_OPEN_READWRITE
)?;
Source

pub fn prepare(&self, sql: &str) -> Result<Statement<'_>>

prepare a query to be executed

let statement = database.prepare("select 1+2;")?;
Source

pub fn execute(&self, sql: &str, params: impl Bindable) -> Result<()>

Execute an sqlite query.

It is expected that the query does to returns any data, if you need to return data, you should use .query().

Source

pub fn collect<R>(&self, sql: &str, params: impl Bindable) -> Result<R>
where R: Collectable,

Execute a query and collect the results.

Your query must return the same column count as type R If the column index is out of range, you will get Err(SQLITE_RANGE)

let result : (i32, String, f64) = database.collect("select 100, 'hello', 3.14;", ())?;
Source

pub fn for_each<T>( &self, sql: &str, params: impl Bindable, iterable: impl Iterable<(), T>, ) -> Result<()>

for_each iterates over multile rows of data using a colusure

let mut sum = 0;
database.for_each("select 2 union select 3", (), |x: i32| { sum += x; })?;
// sum is 5

Trait Implementations§

Source§

impl Drop for Database

Source§

fn drop(&mut self)

closes the *mut sqlite3 handle on Drop

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.