Quickstart
This guide gets you from zero to running SQL queries in under 5 minutes.
1. Create a Project
cargo new my-tensordb-appcd my-tensordb-appcargo add tensordb2. Open a Database
use tensordb::{Database, Config};
fn main() -> tensordb::Result<()> { // Open (or create) a database at the given path let db = Database::open("my_data", Config::default())?;
println!("TensorDB ready!"); Ok(())}The Config::default() gives you sensible defaults: 4 shards, 4MB memtable, bloom filters, fast write path enabled.
3. Create Tables and Insert Data
// Create a table with typed columnsdb.sql("CREATE TABLE products ( id TEXT, name TEXT, price REAL, category TEXT)", &[])?;
// Insert rows — each becomes an immutable factdb.sql("INSERT INTO products VALUES ('p1', 'Widget', 9.99, 'tools')", &[])?;db.sql("INSERT INTO products VALUES ('p2', 'Gadget', 24.99, 'electronics')", &[])?;db.sql("INSERT INTO products VALUES ('p3', 'Gizmo', 14.99, 'tools')", &[])?;4. Query Your Data
// Basic SELECTlet results = db.sql("SELECT name, price FROM products WHERE category = 'tools'", &[])?;for row in &results.rows { println!("{}: ${}", row[0], row[1]);}// Output:// Widget: $9.99// Gizmo: $14.99
// Aggregationlet stats = db.sql("SELECT category, COUNT(*), AVG(price) FROM products GROUP BY category", &[])?;
// Ordering and limitslet top = db.sql("SELECT name, price FROM products ORDER BY price DESC LIMIT 1", &[])?;5. Time Travel
Every write records a commit_ts (commit timestamp). You can query any past state:
// Insert more datadb.sql("INSERT INTO products VALUES ('p1', 'Widget Pro', 19.99, 'tools')", &[])?;
// Query the current statelet now = db.sql("SELECT name, price FROM products WHERE id = 'p1'", &[])?;// Returns: Widget Pro, $19.99
// Query the state as of an earlier commitlet past = db.sql("SELECT name, price FROM products WHERE id = 'p1' AS OF 1", &[])?;// Returns: Widget, $9.996. Bitemporal Queries
TensorDB separates when data was recorded (system time) from when data was valid (business time):
use tensordb::Value;
// Write a fact with an explicit business-time rangedb.put_temporal( "policy/POL-001/rate", Value::Real(4.25), 1704067200, // valid_from: Jan 1, 2024 1735689600, // valid_to: Dec 31, 2024)?;
// Query: what rate was valid on June 15, 2024?let result = db.sql( "SELECT * FROM __keys__ WHERE key = 'policy/POL-001/rate' VALID AT 1718409600", &[])?;Next Steps
- Configuration — Tune performance and storage parameters
- SQL Reference — Full SQL syntax guide
- Architecture — Understand the internals
- Bitemporal Model — Deep dive into time dimensions