Embedded Database Integration
Embedded Mode compiles MagnumDB directly into your Rust binary. In this mode, application code interacts directly with Database, Config, and Executor structs without any network sockets or IPC overhead.
Configuration Options
src/config.rs
rust
use magnumdb::Config;
let config = Config::default()
.with_path("./my_app_data")
.with_buffer_pool_size(1024) // 1024 pages = 4 MB cache
.with_wal_enabled(true);Complete Embedded Workflow
src/main.rs
rust
1234567891011121314151617181920use magnumdb::{Config, Database}; use magnumdb::sql::{Executor, Parser}; fn main() -> anyhow::Result<()> { let config = Config::default().with_path("./embedded_db"); let mut db = Database::open(config)?; let mut exec = Executor::new(&mut db); // DDL exec.execute(Parser::parse("CREATE TABLE items (id INT PRIMARY KEY, title TEXT);")?)?; // DML exec.execute(Parser::parse("INSERT INTO items VALUES (1, 'Notebook'), (2, 'Pen');")?)?; // Query let result = exec.execute(Parser::parse("SELECT * FROM items WHERE id = 1;")?)?; println!("{}", result); Ok(()) }