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
464 downloads per month
Used in 2 crates
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: enableSQLxbackendssea-orm: addSeaORMintegration for type-safe operationspreview-outbox: enable the transactional outbox pipeline (experimental — API may change)
New Architecture
The crate now supports:
- Typed
DbConnectOptionsusing sqlxConnectOptions(no DSN string building) - Per-module database factories with configuration merging
SQLitePRAGMA 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
securemodule) - Per-module migration runner (see
migration_runnermodule)
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