moondb

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.

waxing crescent

moonmysql

The MySQL/MariaDB implementation of the contract.

  • execute
  • query
  • transaction
  • ping
read the statute →
waxing gibbous

moonpostgres

The PostgreSQL implementation of the contract.

  • execute
  • query
  • transaction
  • ping
read the statute →
full moon

moonsqlite

The SQLite implementation of the contract — embedded, no server.

  • execute
  • query
  • transaction
  • ping
read the statute →
moondb · the interface layer Apache-2.0 targets: wasm-gc · js · native trait Driver · value Value · error DbError
Implement a driver Read the full API