Skip to main content

OverdriveDb

Struct OverdriveDb 

Source
pub struct OverdriveDb { /* private fields */ }
Expand description

OverDrive-DB embedded database handle.

All operations use odb as the idiomatic instance name:

let mut odb = OverdriveDb::open("app.odb").unwrap();
odb.insert("users", &serde_json::json!({"name":"Alice"})).unwrap();

Implementations§

Source§

impl OverdriveDb

Source

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

Open or create a database at path.

Source

pub fn open_with_options(path: &str, opts: OpenOptions) -> Result<Self>

Open with engine and/or password options.

Source

pub fn sync(&self) -> Result<()>

Flush all pending writes to disk.

Source

pub fn close(self) -> Result<()>

Close the database explicitly (also called on Drop).

Source

pub fn version() -> String

Return the native library version string.

Source

pub fn create_table(&mut self, name: &str) -> Result<()>

Create a table.

Source

pub fn drop_table(&mut self, name: &str) -> Result<()>

Drop a table.

Source

pub fn list_tables(&self) -> Result<Vec<String>>

List all tables.

Source

pub fn table_exists(&self, name: &str) -> Result<bool>

Check if a table exists.

Source

pub fn insert(&mut self, table: &str, doc: &Value) -> Result<String>

Insert a JSON document. Returns the generated _id.

Source

pub fn insert_batch( &mut self, table: &str, docs: &[Value], ) -> Result<Vec<String>>

Insert multiple documents. Returns a Vec of generated _ids.

Source

pub fn get(&self, table: &str, id: &str) -> Result<Option<Value>>

Get a document by _id. Returns None if not found.

Source

pub fn update(&mut self, table: &str, id: &str, patch: &Value) -> Result<bool>

Update a document by _id. Returns true if updated.

Source

pub fn delete(&mut self, table: &str, id: &str) -> Result<bool>

Delete a document by _id. Returns true if deleted.

Source

pub fn count(&self, table: &str) -> Result<usize>

Count documents in a table.

Source

pub fn query(&mut self, sql: &str) -> Result<Vec<Value>>

Execute a SQL query. Returns rows as a Vec of JSON Values.

Source

pub fn search(&self, table: &str, text: &str) -> Result<Vec<Value>>

Full-text search across a table.

Source

pub fn begin_transaction(&mut self, iso: IsolationLevel) -> Result<Transaction>

Begin an MVCC transaction.

Source

pub fn commit_transaction(&mut self, txn: &Transaction) -> Result<()>

Commit a transaction.

Source

pub fn abort_transaction(&mut self, txn: &Transaction) -> Result<()>

Abort (rollback) a transaction.

Source

pub fn transaction<F, T>(&mut self, iso: IsolationLevel, f: F) -> Result<T>
where F: FnOnce(&mut Self) -> Result<T>,

Run a closure inside a transaction — auto commits on Ok, aborts on Err.

Source

pub fn verify_integrity(&self) -> Result<Value>

Run an integrity check. Returns a JSON report.

Trait Implementations§

Source§

impl Drop for OverdriveDb

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for OverdriveDb

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.