Skip to main content

OverDriveDB

Struct OverDriveDB 

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

OverDrive InCode SDK — Embeddable document database

Use this struct to create, open, and interact with OverDrive databases directly in your application. No server required.

Implementations§

Source§

impl OverDriveDB

Source

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

Open an existing database or create a new one.

File permissions are automatically hardened on open (chmod 600 / Windows ACL).

Source

pub fn create(path: &str) -> SdkResult<Self>

Create a new database. Returns an error if the file already exists.

Source

pub fn open_existing(path: &str) -> SdkResult<Self>

Open an existing database. Returns an error if the file doesn’t exist.

Source

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

Force sync all data to disk.

Source

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

Close the database and release all resources.

Source

pub fn destroy(path: &str) -> SdkResult<()>

Delete a database file from disk.

Source

pub fn path(&self) -> &str

Get the database file path.

Source

pub fn version() -> String

Get the SDK version.

Source

pub fn open_encrypted(path: &str, key_env_var: &str) -> SdkResult<Self>

Open a database with an encryption key loaded securely from an environment variable.

Never hardcode the key — always read from env or a secrets manager.

// In your shell: $env:ODB_KEY="my-secret-32-char-aes-key!!!!"
use overdrive::OverDriveDB;
let mut db = OverDriveDB::open_encrypted("app.odb", "ODB_KEY").unwrap();
Source

pub fn backup(&self, dest_path: &str) -> SdkResult<()>

Create an encrypted backup of the database to dest_path.

Syncs all in-memory data to disk first, then copies the .odb and .wal files. Store the backup in a separate physical location or cloud storage.

db.backup("backups/app_2026-03-04.odb").unwrap();
Source

pub fn cleanup_wal(&self) -> SdkResult<()>

Delete the WAL (Write-Ahead Log) file after a confirmed commit.

Call this after commit_transaction() to prevent attackers from replaying the WAL file to restore deleted data.

let txn = db.begin_transaction(IsolationLevel::ReadCommitted).unwrap();
// ... writes ...
db.commit_transaction(&txn).unwrap();
db.cleanup_wal().unwrap(); // Remove stale WAL
Source

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

Create a new table (schemaless, NoSQL mode).

Source

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

Drop (delete) a table and all its data.

Source

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

List all tables in the database.

Source

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

Check if a table exists.

Source

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

Insert a JSON document into a table. Returns the auto-generated _id.

let id = db.insert("users", &serde_json::json!({
    "name": "Alice",
    "age": 30,
    "tags": ["admin", "developer"]
})).unwrap();
println!("Inserted: {}", id);
Source

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

Insert multiple documents in a batch. Returns a list of generated _ids.

Source

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

Get a document by its _id.

Source

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

Update a document by its _id. Returns true if the document was found and updated.

db.update("users", &id, &serde_json::json!({
    "age": 31,
    "email": "alice@newmail.com"
})).unwrap();
Source

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

Delete a document by its _id. Returns true if found and deleted.

Source

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

Count all documents in a table.

Source

pub fn scan(&self, table: &str) -> SdkResult<Vec<Value>>

Scan all documents in a table (no filter).

Source

pub fn query(&mut self, sql: &str) -> SdkResult<QueryResult>

Execute an SQL query and return results.

Supports: SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, DROP TABLE, SHOW TABLES

let result = db.query("SELECT * FROM users WHERE age > 25 ORDER BY name LIMIT 10").unwrap();
for row in &result.rows {
    println!("{}", row);
}
Source

pub fn query_safe( &mut self, sql_template: &str, params: &[&str], ) -> SdkResult<QueryResult>

Execute a parameterized SQL query — the safe way to include user input.

Use ? as placeholders in the SQL template; values are sanitized and escaped before substitution. Any param containing SQL injection patterns (DROP, DELETE, --, ;) is rejected with SecurityError.

// SAFE: user input via params, never via string concat
let name: &str = get_user_input(); // could be "Alice'; DROP TABLE users--"
let result = db.query_safe(
    "SELECT * FROM users WHERE name = ?",
    &[name],
).unwrap(); // Blocked: SecurityError if injection detected
Source

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

Full-text search across a table.

Source

pub fn stats(&self) -> SdkResult<Stats>

Get database statistics (expanded with MVCC info).

Source

pub fn begin_transaction( &mut self, isolation: IsolationLevel, ) -> SdkResult<TransactionHandle>

Begin a new MVCC transaction with the specified isolation level.

let txn = db.begin_transaction(IsolationLevel::ReadCommitted).unwrap();
// ... perform reads/writes ...
db.commit_transaction(&txn).unwrap();
Source

pub fn commit_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>

Commit a transaction, making all its changes permanent.

Source

pub fn abort_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>

Abort (rollback) a transaction, discarding all its changes.

Source

pub fn verify_integrity(&self) -> SdkResult<IntegrityReport>

Verify the integrity of the database.

Checks B-Tree consistency, page checksums, and MVCC version chains. Returns a detailed report.

let report = db.verify_integrity().unwrap();
assert!(report.is_valid);
println!("Checked {} pages across {} tables", report.pages_checked, report.tables_verified);

Trait Implementations§

Source§

impl Drop for OverDriveDB

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.