minisqlite 是用 Rust 对 SQLite 的完整重实现,涵盖其 SQL 方言、查询规划器、执行器、事务和磁盘文件格式,能够直接读写 SQLite 数据库文件。

Stars

241

7 天增长

+53

Fork 数

23

开放 Issue

1

开源协议

暂无数据

最近更新

2026-07-17

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

该项目以其全面性(14 个 crate 约 20 万行 Rust 代码、5650 项测试、库代码中零 unsafe)和刻意精简的公共 API(一个类型,四个方法)而突出,是替代 C 绑定 SQLite 的安全、架构良好的选择。

适合谁使用

  • 需要嵌入 SQL 数据库但希望避免 FFI 依赖的 Rust 开发者
  • 研究查询规划、执行和存储引擎底层原理的数据库工程师或学生
  • 寻找小巧、安全且完全兼容 SQLite 重实现的系统程序员
  • 对结构清晰、易于修改的数据库内核感兴趣的开源贡献者

典型使用场景

  • 为 Rust 应用(如移动端、桌面工具或服务器)提供嵌入数据库,读写 SQLite 文件
  • 在 Rust 项目中替代 sqlite3 绑定,消除 C 依赖,降低构建复杂度
  • 作为教育沙盒,学习关系数据库引擎从解析到 B 树和 WAL 恢复的工作原理
  • 使用纯 Rust 栈实现跨平台数据交换,利用通用的 SQLite 文件格式

项目优势

  • 完整的 SQLite 3 方言支持:查询、DML、DDL、约束、触发器、窗口函数、JSON 和 PRAGMA
  • 全面的测试套件(5650 项测试),包含从 SQLite 文档抄录的符合性测试和字节级固件测试,确保格式正确性
  • 库 crate 中无 unsafe 代码,不依赖外部 C 库即可保证内存安全
  • 模块化架构,14 个 crate,强制接缝和清晰的依赖方向,使代码库易于导航和修改

使用前须知

  • 不提供预处理语句、命令行界面或 C API,仅提供小巧的 Rust 公共 API(execute/query 方法)
  • 并发仅支持进程内多连接,无跨进程文件锁(无 -shm 协议),不适合多进程访问
  • 查询优化器缺少基于统计信息的代价估算,仅使用结构规则(如唯一性、前缀长度),可能导致复杂查询的次优计划

README 快速开始

minisqlite

A reimplementation of SQLite in Rust: the SQL dialect, the query planner and executor, transactions, and the storage engine, down to the official on-disk file format. It opens database files that sqlite3 wrote and writes files that sqlite3 reads back.

It is a library with a deliberately small surface: one type, four methods. The implementation is about 200,000 lines of Rust across 14 crates, with 5,650 tests, one external dependency (elsa, for the page cache), and no unsafe in library code.

use minisqlite::{Connection, Value};
use std::path::Path;

let mut db = Connection::open(Path::new("app.db"))?; // or Connection::open_in_memory()

db.execute(
    "CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT NOT NULL);
     INSERT INTO users(name) VALUES ('alice'), ('bob');",
)?;

let r = db.query("SELECT id, name FROM users WHERE name LIKE 'a%'")?;
assert_eq!(r.columns, ["id", "name"]);
assert!(matches!(&r.rows[0][1], Value::Text(name) if name == "alice"));

That is the whole public API: Connection::{open, open_in_memory, execute, query}, plus the re-exported Value, Row, QueryResult, and Error types. execute runs any number of ;-separated statements; query returns the last statement's result set. Value has exactly the five SQLite storage classes: Null, Integer(i64), Real(f64), Text(String), Blob(Vec). There is no CLI, no C API, and no prepared-statement interface.

Build and test with a recent stable toolchain (the workspace uses edition 2024):

cargo build --workspace
cargo test  --workspace    # 5,650 tests, about 90 s
cargo bench                # scalability + durability measurement harness

File compatibility

The on-disk format is SQLite's format 3, in both directions:

$ sqlite3 app.db "CREATE TABLE t(x); INSERT INTO t VALUES ('written by sqlite3')"
$ # ... open app.db with minisqlite, read that row, INSERT 'written by minisqlite' ...
$ sqlite3 app.db "SELECT x FROM t; PRAGMA integrity_check"
written by sqlite3
written by minisqlite
ok

This includes the hard cases: WAL databases with a live -wal file, UTF-16LE and UTF-16BE text encodings, auto-vacuum databases with pointer-map pages, overflow chains, freelists, page sizes from 512 to 65536 bytes, and databases with reserved bytes at the end of each page. The format tes

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

l0ng-ai
精选
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

开发者工具CLI 与终端
359
steelbrain
精选
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

桌面应用
143
m-novotny
精选
m-novotny GitHub avatar

memguard-rs

A Rust library that provides secure memory handling primitives including zeroization on drop, memory locking, constant-time comparison, and compile-time guarded regions, with zero dependencies and no_std support.

嵌入式与物联网安全
131