# smarm-pg A small Postgres client for the [smarm](https://git.kalsbeek.dev/Markk116/smarm) actor runtime. Calls are plain blocking functions: the socket is read and written optimistically and the calling actor parks on smarm's fd readiness only on `EAGAIN`. No async, no runtime of its own. Extracted from the urus + smarm Conduit server, where it replaced tokio-based drivers that don't fit smarm. ```rust use smarm_pg::{oid, Config, PgConn, Stmt}; static ADD: Stmt = Stmt::read("SELECT $1::int8 + 1", &[oid::INT8]); smarm::run(|| { let cfg = Config::parse("postgres://app:secret@127.0.0.1/app") .unwrap() .option("plan_cache_mode", "force_generic_plan"); let mut conn = PgConn::connect(&cfg).unwrap(); let rows = conn.query(&ADD, &[&41i64]).unwrap(); assert_eq!(rows.first::().unwrap(), Some(42)); }); ``` ## What it does - **Extended protocol only.** Statements are `static` `Stmt`s. A connection prepares each one the first time it runs it, under a name of its own, and reuses it afterwards. The Parse goes out in the same write as the Bind/Execute, so a cold statement still costs one round trip. - **Binary parameters and results.** - **Pipelines.** `PgConn::pipeline` sends several statements behind one Sync: one round trip, one implicit transaction. If one fails, the rest are skipped and none of them took effect. - **Startup options.** `Config::option` puts session settings in the startup message. - **Auth:** trust, cleartext, MD5, SCRAM-SHA-256 (no channel binding). - **Failure:** a server error (`PgError::Db`) leaves the connection usable; anything else (`PgError::fatal`) marks it broken for good (`is_healthy`), and the owner should drop it. ## What it doesn't do (yet) - **Pooling.** One `PgConn` is one connection, used by one actor at a time. In smarm the natural pool is an actor per connection under a supervisor, sending batches by message; the application owns that, along with routing (`Stmt::writes` is there for read/write splitting). - **Types:** `bool`, `int8` (int4 reads too), `text`, `text[]`, `timestamptz` (as `time::OffsetDateTime`, feature `time`, on by default). Everything else is `Rows::raw`. - No TLS, no COPY, no LISTEN/NOTIFY, no explicit transactions beyond a pipeline, no percent-decoding in URLs, no Unix sockets. ## Tests `TEST_DATABASE_URL=postgres://user:pw@127.0.0.1/db cargo test`. Without it, the tests that need a server print a note and pass. They only create session-local temp tables. `cargo clippy --lib` must be clean: as in smarm, the library denies `unwrap`/`expect`. ## License MIT