Scoped SQL adapter for moonbit-community/postgres
Dependencies
import {
"Hosi121/sql_session@0.1.0",
"Hosi121/postgres_session@0.1.0",
"moonbit-community/postgres@0.0.8",
"moonbitlang/async@0.22.1",
}let config = @pgpool.Config::new(
"127.0.0.1", user="app", password="password", dbname="app",
ssl_mode=@client.SslMode::Disable, // local test only; default is VerifyFull
application_name="example",
pool=@pgpool.PoolConfig::new(4, recycling_method=@pgpool.RecyclingMethod::clean()),
)
@postgres.with_database(config, async fn(db) {
let rows = db.with_transaction(@pgpool.TransactionOptions::new(), async fn(tx) {
tx.query("INSERT INTO notes(body) VALUES ($1) RETURNING id", params=["hello"])
})
let id : Int = rows[0].get("id")
println(id)
})fn database(config : Config, group : TaskGroup[Unit], max_waiters? : Int, checkout_timeout_ms? : Int, max_rows? : Int, max_bytes? : Int) -> Database[&ToSql, Row, QuerySummary, TransactionOptions] raiseasync fn[T] with_database(config : Config, f : async (Database[&ToSql, Row, QuerySummary, TransactionOptions]) -> T, max_waiters? : Int, checkout_timeout_ms? : Int, max_rows? : Int, max_bytes? : Int) -> TInstall
Download zipScoped SQL adapter for moonbit-community/postgres
Dependencies