A Postgres client in Bend. Protocol 3.0, SCRAM-SHA-256, prepared queries, and a pool.
import [email protected]/postgres.bend as Pg
import [email protected]/bytes.bend as Bytes
postgres.bend imports that bytes version, [email protected], and [email protected]. scram.bend also imports [email protected]. codec.bend and scram.bend are part of this package. Callers use postgres.bend.
config(host, port, user, pass, db) builds a Config. TLS is on by default. The default step timeout is 10 seconds. Keep tls set when the server must use TLS. If the server refuses SSL, the error is NoTls. The client does not switch to cleartext.
connect returns a Result with a Conn on success. query(conn, sql, params) sends Parse, Bind, Describe, Execute, and Sync messages. Parameters have type Maybe<&1, Bytes.Bytes>. None means SQL NULL. text makes a text parameter from a String. Results contain text columns. A server error carries its SQLSTATE. A successful query returns the connection beside the reply. pool.get borrows a connection. pool.put returns it to the pool.
smoke.bend expects a live server with TLS and SCRAM, and the POSTGRES_* variables. The laws cover the codec and SCRAM fixtures, not the socket.