PostgreSQL client for Turmeric via libpq: connect, exec, parameterized
queries, prepared statements, transactions, and LISTEN/NOTIFY.
tur-postgres is a cmake-dep spice that wraps libpq. It exposes the
familiar PostgreSQL workflow: open a connection with db-connect, run
queries with db-query / db-query-params, prepare statements via
stmt-prepare, and walk rows with row-get / col-name.
It also surfaces LISTEN / NOTIFY so you can build event-driven services
that react to row changes without polling.
:spices {
"postgres" {:url "https://github.com/rjungemann/turmeric-spices"
:ref "postgres-v0.1.0"
:subdir "spices/postgres"}
}
(import postgres/db :refer [db-connect db-close db-query])
(import postgres/row :refer [row-get rows-free])
(let [r (db-connect "postgresql://localhost/app")]
(when (ok? r)
(let [db (ok-val r)
rows (ok-val (db-query db "SELECT id, name FROM users"))]
(for [row rows]
(println (row-get row "id") (row-get row "name")))
(rows-free rows)
(db-close db))))