A pure MoonBit embedded relational SQL engine
Dependencies
状态说明:解析、类型检查、全语句执行、逻辑 B+Tree 和 open/close 二进制页恢复已实现。单文件由 4096B superblock、catalog/schema 页、B+Tree leaf/internal 页组成;当前没有 WAL/事务,进程在 close 前崩溃可能丢失本次会话。原生 CLI 直接读取 stdin;.tables/.schema/.help/.ast 也复用可嵌入宿主的 run_line dispatcher。
moon check
moon test
moon run src/main --target native -- my-database.mdblet db = @lib.open(":memory:")
let _ = db.execute("CREATE TABLE users (id INTEGER, name TEXT, score REAL)")
let _ = db.execute("INSERT INTO users VALUES (1, 'Ada', 9), (2, 'Bob', 7.5)")
let result = db.execute("SELECT name FROM users WHERE score >= 8 ORDER BY name LIMIT 10")
db.close()| 功能 | 示例 |
|---|---|
| CREATE TABLE | CREATE TABLE t (id INTEGER, name TEXT, score REAL) |
| INSERT | INSERT INTO t VALUES (1,'a',1.5), (2,'b',2) |
| SELECT | SELECT * FROM t / SELECT id,name FROM t |
| UPDATE | UPDATE t SET name='x' WHERE id=1 |
| DELETE | DELETE FROM t WHERE id<>1 |
| DROP TABLE | DROP TABLE t |
| WHERE | = <> < > <= >= AND OR NOT,括号,AND 优先于 OR |
| 排序分页 | ORDER BY score DESC LIMIT 10 OFFSET 20 |
flowchart LR
SQL["SQL text"] --> Lexer["Lexer + source positions"]
Lexer --> Parser["Recursive-descent parser"]
Parser --> AST["Typed statement AST"]
AST --> Executor["Type check + executor"]
Executor --> Tree["B+Tree row store"]
Tree --> Pager["4096B pager boundary"]
Pager --> Pages["4096B superblock/catalog/leaf/internal pages"]
Pages --> Recovery["open decode / close rewrite"]moon check --deny-warn
moon test
moon check --target wasm
moon package --list
moon publishA pure MoonBit embedded relational SQL engine
Dependencies