Skip to main content

Crate featherdb

Crate featherdb 

Source
Expand description

§FeatherDB

An embedded SQL database for AI agents. Compiles into your binary — no servers, no sockets, no C dependencies.

Built on real database internals (B-trees, WAL, MVCC) with features agents actually need: concurrent writers, encryption at rest, API key auth, and per-session isolation.

§Quick Start

use featherdb::{Database, Result};

fn main() -> Result<()> {
    let db = Database::open("myapp.db")?;

    db.execute("CREATE TABLE tasks (
        id INTEGER PRIMARY KEY,
        title TEXT NOT NULL,
        status TEXT DEFAULT 'pending'
    )")?;

    db.execute("INSERT INTO tasks (id, title) VALUES (1, 'Build something cool')")?;

    let rows = db.query("SELECT * FROM tasks WHERE status = 'pending'")?;
    println!("Found {} pending tasks", rows.len());

    Ok(())
}

§Transactions

use featherdb::{Database, Result};

fn main() -> Result<()> {
    let db = Database::open("myapp.db")?;

    let mut txn = db.begin()?;
    txn.execute("INSERT INTO tasks (id, title) VALUES (2, 'Ship it')")?;
    txn.execute("INSERT INTO tasks (id, title) VALUES (3, 'Celebrate')")?;
    txn.commit()?; // atomic — both rows or neither

    Ok(())
}

§Encryption

use featherdb::{Config, Database, Result};

fn main() -> Result<()> {
    let config = Config::new("secrets.db").with_password("hunter2");
    let db = Database::open_with_config(config)?;
    // Every page is AES-256-GCM encrypted at rest
    Ok(())
}

Re-exports§

pub use session::Session;
pub use session::SessionConfig;
pub use session::SessionHandle;
pub use session::SessionId;
pub use session::SessionManager;
pub use session::SessionManagerConfig;
pub use session::SessionMetadata;
pub use session::SessionMode;
pub use session::SessionState;

Modules§

session
Session management for MCP session lifecycle.

Structs§

ApiKeyInfo
Public metadata about an API key (no secrets)
BufferPoolStatsSnapshot
Immutable snapshot of buffer pool statistics
CacheStats
Statistics for the plan cache
Catalog
The schema catalog - manages all table and index definitions
Column
Column definition
ColumnDef
Column definition for schema generation
CompressionStatsSnapshot
Immutable snapshot of compression statistics
Config
Database configuration options
Database
The main database handle
DatabaseMetrics
Comprehensive database metrics snapshot
DatabaseStats
Database statistics
DeleteBuilder
Builder for DELETE queries
ExecutionContext
Execution context containing database state
Executor
Query executor
GcMetricsSnapshot
Index
Index definition
InsertBuilder
Builder for INSERT queries
Lsn
Log Sequence Number - identifies a position in the WAL
Migration
A schema migration record
Optimizer
Query optimizer that applies transformation rules
PageId
Page identifier - uniquely identifies a page in the database file
Parser
SQL parser wrapper with enhanced error messages
Permissions
Permission flags for table-level access control.
PlanCache
LRU cache for query plans
PlanCacheSnapshot
Plan cache statistics snapshot
Planner
Query planner with enhanced error messages
PreparedStatement
A prepared statement with a cached, optimized query plan
QueryBuilder
Main entry point for the query builder
QueryMetricsSnapshot
Snapshot of query metrics at a point in time
Row
A row of values
SelectBuilder
Builder for SELECT queries
Snapshot
A consistent view of the database at a point in time
StorageQuota
Storage quota information
Table
Table definition
TableGrant
A grant of permissions on a table to an API key
Transaction
A database transaction
TransactionConfig
Configuration for transaction behavior
TransactionId
Transaction identifier
TransactionManager
Manages all transactions in the database
TransactionMetricsSnapshot
Snapshot of transaction metrics at a point in time
UpdateBuilder
Builder for UPDATE queries
WalStatsSnapshot
Immutable snapshot of WAL statistics

Enums§

AggregateFunction
Built-in aggregate functions
BinaryOp
Binary operations between expressions
ColumnConstraint
Column constraint
ColumnType
Column type definition
Error
Main error type for FeatherDB operations
EvictionPolicyType
Buffer pool eviction policy type
Expr
Expression tree
IndexType
Type of index
LogicalPlan
Logical plan - represents a query as a tree of relational operators
QueryOrdering
Sort ordering for ORDER BY
QueryResult
Query result - either rows or affected count Query result
TransactionMode
Transaction mode
TransactionStatus
Transaction status
UnaryOp
Unary operations on expressions
Value
A database value

Traits§

FromRow
Trait for types that can be constructed from a database row
FromValue
Trait for types that can be created from a database Value
TableSchema
Trait for types that have a table schema
ToRow
Trait for types that represent a database row
ToValue
Trait for types that can be converted to a database Value

Type Aliases§

Result
Result type alias using FeatherDB’s Error
SavepointId
Unique identifier for a savepoint

Derive Macros§

Table
Derive macro for generating table schema and row conversion implementations