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
impl OverDriveDB
Sourcepub fn open(path: &str) -> SdkResult<Self>
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).
Sourcepub fn create(path: &str) -> SdkResult<Self>
pub fn create(path: &str) -> SdkResult<Self>
Create a new database. Returns an error if the file already exists.
Sourcepub fn open_existing(path: &str) -> SdkResult<Self>
pub fn open_existing(path: &str) -> SdkResult<Self>
Open an existing database. Returns an error if the file doesn’t exist.
Sourcepub fn open_encrypted(path: &str, key_env_var: &str) -> SdkResult<Self>
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();Sourcepub fn backup(&self, dest_path: &str) -> SdkResult<()>
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();Sourcepub fn cleanup_wal(&self) -> SdkResult<()>
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 WALSourcepub fn create_table(&mut self, name: &str) -> SdkResult<()>
pub fn create_table(&mut self, name: &str) -> SdkResult<()>
Create a new table (schemaless, NoSQL mode).
Sourcepub fn drop_table(&mut self, name: &str) -> SdkResult<()>
pub fn drop_table(&mut self, name: &str) -> SdkResult<()>
Drop (delete) a table and all its data.
Sourcepub fn list_tables(&self) -> SdkResult<Vec<String>>
pub fn list_tables(&self) -> SdkResult<Vec<String>>
List all tables in the database.
Sourcepub fn table_exists(&self, name: &str) -> SdkResult<bool>
pub fn table_exists(&self, name: &str) -> SdkResult<bool>
Check if a table exists.
Sourcepub fn insert(&mut self, table: &str, doc: &Value) -> SdkResult<String>
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);Sourcepub fn insert_batch(
&mut self,
table: &str,
docs: &[Value],
) -> SdkResult<Vec<String>>
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.
Sourcepub fn get(&self, table: &str, id: &str) -> SdkResult<Option<Value>>
pub fn get(&self, table: &str, id: &str) -> SdkResult<Option<Value>>
Get a document by its _id.
Sourcepub fn update(
&mut self,
table: &str,
id: &str,
updates: &Value,
) -> SdkResult<bool>
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();Sourcepub fn delete(&mut self, table: &str, id: &str) -> SdkResult<bool>
pub fn delete(&mut self, table: &str, id: &str) -> SdkResult<bool>
Delete a document by its _id. Returns true if found and deleted.
Sourcepub fn scan(&self, table: &str) -> SdkResult<Vec<Value>>
pub fn scan(&self, table: &str) -> SdkResult<Vec<Value>>
Scan all documents in a table (no filter).
Sourcepub fn query(&mut self, sql: &str) -> SdkResult<QueryResult>
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);
}Sourcepub fn query_safe(
&mut self,
sql_template: &str,
params: &[&str],
) -> SdkResult<QueryResult>
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 detectedSourcepub fn search(&self, table: &str, text: &str) -> SdkResult<Vec<Value>>
pub fn search(&self, table: &str, text: &str) -> SdkResult<Vec<Value>>
Full-text search across a table.
Sourcepub fn begin_transaction(
&mut self,
isolation: IsolationLevel,
) -> SdkResult<TransactionHandle>
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();Sourcepub fn commit_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>
pub fn commit_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>
Commit a transaction, making all its changes permanent.
Sourcepub fn abort_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>
pub fn abort_transaction(&mut self, txn: &TransactionHandle) -> SdkResult<()>
Abort (rollback) a transaction, discarding all its changes.
Sourcepub fn verify_integrity(&self) -> SdkResult<IntegrityReport>
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);