common_sql_postgresql
PostgreSQL driver for common_sql, implemented with pog.
For usage documentation, examples, and the full API reference, see the common_sql README.
This package exposes a single driver() function. Add it alongside common_sql:
gleam add common_sql common_sql_postgresql
import common_sql as sql
import common_sql_postgresql
pub fn main() {
let driver = common_sql_postgresql.driver()
use conn <- sql.with_connection(driver, "postgres://user:pass@localhost/mydb")
// see common_sql README for full examples
}
SQL placeholders
Both sql.Sql("… WHERE id = $1") and sql.Portable("… WHERE id = $1") work with this driver — PostgreSQL natively uses $1, $2, … so no conversion is applied either way.
PostgreSQL connection URL
postgres://[user[:password]@][host[:port]][/database][?options]
"postgres://localhost/mydb" // local, no auth
"postgres://alice:secret@db.example.com:5432/mydb" // with credentials
"postgres://localhost/mydb?sslmode=verify-full" // with SSL
Notes
pogmanages connections as an OTP pool. Calldriver()once at startup — not in a loop.common_sql.close/2is a no-op for this driver. Usepog.supervised/1to manage the pool lifecycle via a supervision tree.
Development
Integration tests require a live PostgreSQL instance on localhost:5432 (user postgres, password postgres, database testdb). A Docker one-liner:
docker run --rm --name test_pg -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres \
-e POSTGRES_DB=testdb -p 5432:5432 -d postgres:16-alpine
gleam test # run the integration tests
gleam build # compile the package
Licence
MIT