### Using the FrankenSQLite CLI Source: https://frankensqlite.com/getting-started Commands for installing the CLI, managing databases, and switching output formats. ```bash 01# Install the CLI02cargo install fsqlite-cli03 04# Open or create a database05fsqlite my_database.db06 07# Run queries interactively08fsqlite> CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);09fsqlite> INSERT INTO users VALUES (1, 'Alice');10fsqlite> SELECT * FROM users;11-- 1 | Alice12 13# Output modes14fsqlite> .mode json15fsqlite> SELECT * FROM users;16-- [{"id": 1, "name": "Alice"}]17 18fsqlite> .mode csv19fsqlite> SELECT * FROM users;20-- id,name21-- 1,Alice ``` -------------------------------- ### Install FrankenSQLite via Cargo Source: https://frankensqlite.com/getting-started Add the dependency to your project using the cargo CLI or by manually editing your Cargo.toml file. ```toml 01# Add to your Cargo.toml02cargo add fsqlite03 04# Or add manually:05# [dependencies]06# fsqlite = "0.1" ``` -------------------------------- ### Install FrankenSQLite via Cargo Source: https://frankensqlite.com/ Use this command to add the FrankenSQLite crate to your Rust project dependencies. ```shell cargo add fsqlite ``` -------------------------------- ### Perform Basic Database Operations Source: https://frankensqlite.com/getting-started Open a connection, execute SQL commands, and query data using the fsqlite crate. ```rust 01 use fsqlite::Connection;02 use fsqlite_error::Result;03 use fsqlite_types::value::SqliteValue;04 05 fn main() -> Result<()> {06 let db = Connection::open("app.db")?;07 08 db.execute(09 "CREATE TABLE IF NOT EXISTS users (10 id INTEGER PRIMARY KEY,11 name TEXT NOT NULL,12 email TEXT UNIQUE13 )",14 )?;15 16 db.execute_with_params(17 "INSERT INTO users (name, email) VALUES (?1, ?2)",18 &[19 SqliteValue::Text("Alice".to_owned()),20 SqliteValue::Text("alice@example.com".to_owned()),21 ],22 )?;23 24 let stmt = db.prepare("SELECT id, name FROM users WHERE name = ?1")?;25 let rows = stmt.query_with_params(26 &[SqliteValue::Text("Alice".to_owned())],27 )?;28 29 for row in &rows {30 let id = row.get(0).expect("id column");31 let name = row.get(1).expect("name column");32 println!("Found: {id:?} — {name:?}");33 }34 35 Ok(())36} ``` -------------------------------- ### Configuring FrankenSQLite via PRAGMAs Source: https://frankensqlite.com/getting-started Settings for storage modes, encryption keys, and transaction monitoring tools. ```sql 01-- Storage modes: compatibility (default) or native ECS02PRAGMA fsqlite.mode = compatibility; -- Standard .sqlite3 format03PRAGMA fsqlite.mode = native; -- Erasure-Coded Stream format04 05-- Page-level encryption (XChaCha20-Poly1305)06PRAGMA fsqlite.key = 'your-secret-key';07 08-- Transaction observability09PRAGMA fsqlite_txn_stats; -- Lifecycle counters10PRAGMA fsqlite_transactions; -- Active transaction details11PRAGMA fsqlite_txn_advisor; -- Anti-pattern detection12PRAGMA fsqlite_txn_timeline_json; -- Chrome DevTools timeline13 14-- Tune advisor thresholds15PRAGMA fsqlite.txn_advisor_long_txn_ms = 5000;16PRAGMA fsqlite.txn_advisor_large_read_ops = 256; ``` -------------------------------- ### Concurrent Writing with MVCC Source: https://frankensqlite.com/getting-started Demonstrates multi-threaded writes without encountering SQLITE_BUSY errors. ```rust 01use fsqlite::Connection;02use fsqlite_types::value::SqliteValue;03use std::thread;04 05fn main() -> fsqlite_error::Result<()> {06 let db = Connection::open("concurrent.db")?;07 db.execute("CREATE TABLE counters (id INTEGER PRIMARY KEY, val INTEGER)")?;08 db.execute("INSERT INTO counters VALUES (1, 0), (2, 0), (3, 0), (4, 0)")?;09 10 let handles: Vec<_> = (1..=4).map(|id| {11 thread::spawn(move || {12 let conn = Connection::open("concurrent.db").unwrap();13 for _ in 0..1000 {14 conn.execute_with_params(15 "UPDATE counters SET val = val + 1 WHERE id = ?1",16 &[SqliteValue::Integer(id)],17 ).unwrap();18 }19 })20 }).collect();21 22 for h in handles { h.join().unwrap(); }23 // Each counter is exactly 1000 — no SQLITE_BUSY, no lost updates.24 Ok(())25} ``` -------------------------------- ### Enabling ECS Mode and Encryption Source: https://frankensqlite.com/getting-started Configures native Erasure-Coded Stream storage and page-level encryption for enhanced durability. ```rust 01use fsqlite::Connection;02use fsqlite_types::value::SqliteValue;03 04fn main() -> fsqlite_error::Result<()> {05 let db = Connection::open("secure.db")?;06 07 // Switch to native ECS format for maximum durability08 db.execute("PRAGMA fsqlite.mode = native")?;09 10 // Enable page-level encryption (XChaCha20-Poly1305 + Argon2id KDF)11 db.execute("PRAGMA fsqlite.key = 'hunter2-but-stronger'")?;12 13 // Configure RaptorQ repair symbol ratio (default: 0.1 = 10% overhead)14 db.execute("PRAGMA fsqlite.repair_ratio = 0.2")?; // 20% for extra safety15 16 // Business as usual — the API is identical17 db.execute("CREATE TABLE secrets (id INTEGER PRIMARY KEY, data BLOB)")?;18 db.execute_with_params(19 "INSERT INTO secrets (data) VALUES (?1)",20 &[SqliteValue::Blob(b"classified".to_vec())],21 )?;22 23 // Every page is encrypted at rest + protected by RaptorQ repair symbols.24 // Even if the disk suffers corruption, data is recoverable.25 Ok(())26} ``` -------------------------------- ### Performing Time-Travel Queries Source: https://frankensqlite.com/getting-started Uses commit sequence numbers to query the database state at a specific point in time. ```rust 01use fsqlite::Connection;02 03fn main() -> fsqlite_error::Result<()> {04 let db = Connection::open("history.db")?;05 db.execute("CREATE TABLE prices (item TEXT, price REAL)")?;06 db.execute("INSERT INTO prices VALUES ('widget', 9.99)")?;07 08 // Record the commit sequence number09 let csn_before = db.query_scalar("SELECT fsqlite_current_csn()")?;10 11 db.execute("UPDATE prices SET price = 14.99 WHERE item = 'widget'")?;12 13 // Query the current state14 let current = db.prepare("SELECT price FROM prices WHERE item = 'widget'")?;15 // => 14.9916 17 // Time-travel: query the database as it was before the update18 let historical = db.prepare(19 "SELECT price FROM prices FOR SYSTEM_TIME AS OF ?1 WHERE item = 'widget'",20 )?;21 let rows = historical.query_with_params(&[csn_before])?;22 // => 9.99 — the price before the update23 24 Ok(())25} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.