DuckDB for moondb: the embedded analytical engine, loaded as a shared library on native and as DuckDB's own WebAssembly build on js, one driver for both.
moon add moonbitstack/moonduckdblet db = @moonduckdb.DuckdbDriver::open(":memory:")
db.exec_script("CREATE TABLE hero (id INTEGER PRIMARY KEY, name VARCHAR)")
db.execute("INSERT INTO hero VALUES (?, ?)", [Int(1), Text("Nova")]) |> ignore
let rows = db.query("SELECT name FROM hero WHERE id = ?", [Int(1)])
println(rows[0].text_by("name")) // Novadrivers/duckdb/scripts/fetch_engine.sh # downloads the pinned release for this platform
# → drivers/duckdb/engine/linux-amd64/libduckdb.soMOONDUCKDB_LIBRARY=/path/to/libduckdb.so moon test --target nativedrivers/duckdb/scripts/fetch_wasm_engine.sh # npm-installs the pinned build
export MOONDUCKDB_ENGINE=$(drivers/duckdb/scripts/fetch_wasm_engine.sh)async fn demo() -> Unit raise @moondb.DbError {
let db = @moonduckdb.DuckdbDriver::open(":memory:")
db.execute("CREATE TABLE t (id INTEGER, n VARCHAR)", []) |> ignore
db.execute("INSERT INTO t VALUES (?, ?)", [Int(1), Text("a")]) |> ignore
let rows = db.query("SELECT n FROM t", [])
println(rows[0].text(0)) // a
db.close()
}| DuckDB | Value |
|---|---|
| BOOLEAN | Bool |
| TINYINT … BIGINT, UTINYINT … UINTEGER | Int64 |
| UBIGINT | Int64, or Text above 2⁶³−1 |
| FLOAT, DOUBLE | Double |
| VARCHAR | Text |
| BLOB | Blob |
| DATE, TIME, TIMESTAMP, INTERVAL | Text (the engine's own rendering) |
| DECIMAL, HUGEINT, UUID, LIST, STRUCT, MAP | Text |
| NULL | Null |
pub struct DuckdbDriver {
handle : Int64
closed : Bool
}impl Driver for DuckdbDriverfn DuckdbDriver::execute(self : DuckdbDriver, sql : String, params : Array[Value]) -> ExecResult raise DbErrorfn DuckdbDriver::query(self : DuckdbDriver, sql : String, params : Array[Value]) -> Array[Row] raise DbErrorfn DuckdbDriver::query_stream(self : DuckdbDriver, sql : String, params : Array[Value]) -> &Cursor raise DbErrorimpl Stmt for DuckdbStmtInstall
Download zipDuckDB for moondb: the embedded analytical engine, loaded as a shared library on native and as DuckDB's own WebAssembly build on js, one driver for both.