Experimental community PostgreSQL adapter for moondb
git clone https://github.com/kaigeliang/moonbit-pg-bridge.git
cd moonbit-pg-bridge
moon update
moon build --target nativemoon add kaigeliang/moonbit-pg-bridge@0.1.0scripts/integration.sh --demo
PG_BRIDGE_TARGET=wasm scripts/integration.sh --demoDuplicate order rejected (23505). Savepoint rolled back.
Streamed committed orders: 1, 3///|
let rows = bridge.with_transaction(tx => {
tx.execute("CREATE TEMP TABLE demo_items (id int) ON COMMIT DROP", [])
|> ignore
tx.with_savepoint("add item", child => {
child.execute("INSERT INTO demo_items VALUES ($1)", [Int(7)]) |> ignore
})
tx.query("SELECT id FROM demo_items", [])
})for target in native wasm; do
moon check --target "$target" --deny-warn
moon build --target "$target"
moon test --target "$target"
PG_BRIDGE_TARGET="$target" scripts/integration.sh
done| File | Implementation lines |
|---|---|
| bridge.mbt | 274 |
| transaction.mbt | 204 |
| scope_sql.mbt | 91 |
| stream.mbt | 128 |
| Total | 697 |
awk 'NF && $1 !~ /^\/\// { ++lines[FILENAME]; ++total }
END { for (i = 1; i < ARGC; ++i) print ARGV[i], lines[ARGV[i]]
print "total", total }' bridge.mbt transaction.mbt scope_sql.mbt stream.mbtimpl AsyncDriver for Bridgeasync fn query_stream(self : Bridge, sql : String, params : Array[Value]) -> &AsyncCursor raise DbErrorasync fn[T] Bridge::with_savepoint(self : Bridge, name : String, f : async (TransactionScope) -> T) -> Tasync fn[T] Bridge::with_transaction(self : Bridge, f : async (TransactionScope) -> T, options? : TransactionOptions) -> Tpub struct TransactionScope {
// private fields
}async fn TransactionScope::execute(self : TransactionScope, sql : String, params : Array[Value]) -> ExecResult raise DbErrorasync fn TransactionScope::query(self : TransactionScope, sql : String, params : Array[Value]) -> Array[Row] raise DbErrorasync fn[T] TransactionScope::with_savepoint(self : TransactionScope, name : String, f : async (TransactionScope) -> T) -> Tasync fn[T] TransactionScope::with_stream(self : TransactionScope, sql : String, params : Array[Value], f : async (&AsyncCursor) -> T) -> T