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
impl OverdriveDb
Sourcepub fn open_with_options(path: &str, opts: OpenOptions) -> Result<Self>
pub fn open_with_options(path: &str, opts: OpenOptions) -> Result<Self>
Open with engine and/or password options.
Sourcepub fn create_table(&mut self, name: &str) -> Result<()>
pub fn create_table(&mut self, name: &str) -> Result<()>
Create a table.
Sourcepub fn drop_table(&mut self, name: &str) -> Result<()>
pub fn drop_table(&mut self, name: &str) -> Result<()>
Drop a table.
Sourcepub fn list_tables(&self) -> Result<Vec<String>>
pub fn list_tables(&self) -> Result<Vec<String>>
List all tables.
Sourcepub fn table_exists(&self, name: &str) -> Result<bool>
pub fn table_exists(&self, name: &str) -> Result<bool>
Check if a table exists.
Sourcepub fn insert(&mut self, table: &str, doc: &Value) -> Result<String>
pub fn insert(&mut self, table: &str, doc: &Value) -> Result<String>
Insert a JSON document. Returns the generated _id.
Sourcepub fn insert_batch(
&mut self,
table: &str,
docs: &[Value],
) -> Result<Vec<String>>
pub fn insert_batch( &mut self, table: &str, docs: &[Value], ) -> Result<Vec<String>>
Insert multiple documents. Returns a Vec of generated _ids.
Sourcepub fn get(&self, table: &str, id: &str) -> Result<Option<Value>>
pub fn get(&self, table: &str, id: &str) -> Result<Option<Value>>
Get a document by _id. Returns None if not found.
Sourcepub fn update(&mut self, table: &str, id: &str, patch: &Value) -> Result<bool>
pub fn update(&mut self, table: &str, id: &str, patch: &Value) -> Result<bool>
Update a document by _id. Returns true if updated.
Sourcepub fn delete(&mut self, table: &str, id: &str) -> Result<bool>
pub fn delete(&mut self, table: &str, id: &str) -> Result<bool>
Delete a document by _id. Returns true if deleted.
Sourcepub fn query(&mut self, sql: &str) -> Result<Vec<Value>>
pub fn query(&mut self, sql: &str) -> Result<Vec<Value>>
Execute a SQL query. Returns rows as a Vec of JSON Values.
Sourcepub fn search(&self, table: &str, text: &str) -> Result<Vec<Value>>
pub fn search(&self, table: &str, text: &str) -> Result<Vec<Value>>
Full-text search across a table.
Sourcepub fn begin_transaction(&mut self, iso: IsolationLevel) -> Result<Transaction>
pub fn begin_transaction(&mut self, iso: IsolationLevel) -> Result<Transaction>
Begin an MVCC transaction.
Sourcepub fn commit_transaction(&mut self, txn: &Transaction) -> Result<()>
pub fn commit_transaction(&mut self, txn: &Transaction) -> Result<()>
Commit a transaction.
Sourcepub fn abort_transaction(&mut self, txn: &Transaction) -> Result<()>
pub fn abort_transaction(&mut self, txn: &Transaction) -> Result<()>
Abort (rollback) a transaction.
Sourcepub fn transaction<F, T>(&mut self, iso: IsolationLevel, f: F) -> Result<T>
pub fn transaction<F, T>(&mut self, iso: IsolationLevel, f: F) -> Result<T>
Run a closure inside a transaction — auto commits on Ok, aborts on Err.
Sourcepub fn verify_integrity(&self) -> Result<Value>
pub fn verify_integrity(&self) -> Result<Value>
Run an integrity check. Returns a JSON report.
Trait Implementations§
Source§impl Drop for OverdriveDb
impl Drop for OverdriveDb
impl Send for OverdriveDb
Auto Trait Implementations§
impl Freeze for OverdriveDb
impl RefUnwindSafe for OverdriveDb
impl !Sync for OverdriveDb
impl Unpin for OverdriveDb
impl UnsafeUnpin for OverdriveDb
impl UnwindSafe for OverdriveDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more