35 releases (6 breaking)

Uses new Rust 2024

new 0.7.1 Apr 8, 2026
0.7.0 Mar 30, 2026
0.6.1 Mar 26, 2026
0.5.11 Mar 23, 2026
0.1.5 Jan 28, 2026

#445 in Development tools

Download history 15/week @ 2026-01-21 35/week @ 2026-01-28 104/week @ 2026-02-04 81/week @ 2026-02-11 96/week @ 2026-02-18 91/week @ 2026-02-25 243/week @ 2026-03-04 152/week @ 2026-03-11 172/week @ 2026-03-18 47/week @ 2026-03-25 46/week @ 2026-04-01

464 downloads per month
Used in 2 crates

Apache-2.0

1MB
25K SLoC

ModKit Database abstraction crate.

This crate provides a unified interface for working with different databases (SQLite, PostgreSQL, MySQL) through SQLx, with optional SeaORM integration. It emphasizes typed connection options over DSN string manipulation and implements strict security controls (e.g., SQLite PRAGMA whitelist).

Features

  • pg, mysql, sqlite: enable SQLx backends
  • sea-orm: add SeaORM integration for type-safe operations
  • preview-outbox: enable the transactional outbox pipeline (experimental — API may change)

New Architecture

The crate now supports:

  • Typed DbConnectOptions using sqlx ConnectOptions (no DSN string building)
  • Per-module database factories with configuration merging
  • SQLite PRAGMA whitelist for security
  • Environment variable expansion in passwords and DSNs

Example (DbManager API)

use modkit_db::{DbManager, GlobalDatabaseConfig, DbConnConfig};
use figment::{Figment, providers::Serialized};
use std::path::PathBuf;
use std::sync::Arc;

// Create configuration using Figment
let figment = Figment::new()
    .merge(Serialized::defaults(serde_json::json!({
        "db": {
            "servers": {
                "main": {
                    "host": "localhost",
                    "port": 5432,
                    "user": "app",
                    "password": "${DB_PASSWORD}",
                    "dbname": "app_db"
                }
            }
        },
        "test_module": {
            "database": {
                "server": "main",
                "dbname": "module_db"
            }
        }
    })));

// Create DbManager
let home_dir = PathBuf::from("/app/data");
let db_manager = Arc::new(DbManager::from_figment(figment, home_dir).unwrap());

// Use in runtime with DbOptions::Manager(db_manager)
// Modules can then use: ctx.db_required_async().await?

ModKit DB

Database abstractions for CyberFabric / ModKit with optional SeaORM integration.

Overview

The cf-modkit-db crate provides:

  • Typed database configuration / connection options
  • SQLx backend support (SQLite / Postgres / MySQL via features)
  • SeaORM integration
  • Secure-by-default ORM wrapper (see secure module)
  • Per-module migration runner (see migration_runner module)

Features

  • pg, mysql, sqlite: enable SQLx backends

Security Model

Modules cannot access raw database connections. All database operations go through the SecureConn API which enforces tenant isolation at compile time. Migrations are provided as definitions and executed by the runtime with a privileged connection.

License

Licensed under Apache-2.0.

Dependencies

~88MB
~1.5M SLoC