MoonBit · database contract
moondb
A trait is a constitution. moondb fixes the calling convention every MoonBit database backend implements — and every ORM builds against. Drivers ratify it; the spec stays small, and stable.
Article I — the contract
The Driver trait
Eight operations. No more. A backend implements execute,
query, the three transaction brackets, and
close; ping and
query_stream come with sensible defaults. Values cross
the boundary as Value — never spliced into SQL — so
binding is injection-safe by construction.
pub(open) trait Driver { fn execute(Self, String, Array[Value]) -> ExecResult raise DbError fn query(Self, String, Array[Value]) -> Array[Row] raise DbError fn query_stream(Self, String, Array[Value]) -> &Cursor raise DbError = _ // default fn begin(Self) -> Unit raise DbError fn commit(Self) -> Unit raise DbError fn rollback(Self) -> Unit raise DbError fn close(Self) -> Unit fn ping(Self) -> Bool = _ // default }
Article II — the ratified implementations
Drivers
moondb is the law; these are the ratified amendments. Each is a package that
implements Driver against one backend. Their docs live
as sub-pages of this site.
moonmysql
The MySQL/MariaDB implementation of the contract.
- execute
- query
- transaction
- ping
moonpostgres
The PostgreSQL implementation of the contract.
- execute
- query
- transaction
- ping
moonsqlite
The SQLite implementation of the contract — embedded, no server.
- execute
- query
- transaction
- ping