Available

amalgame-postgresql

Dynamic-link binding to system libpq. First of the pattern.

amc package add postgresql GitHub ↗ ← Back to the ecosystem

Overview

First Amalgame package to adopt the dynamic-link pattern: the lib is not vendored — the binary references the system's libpq.so. Lighter, more security-current, and more natural for server deployments where PostgreSQL is already installed.

Features

  • ✓Direct binding to libpq: install libpq-dev to build
  • ✓PostgreSQL.Open, Exec, QueryAll, Changes, ServerVersion
  • ✓$1, $2 parameters with ExecBind / QueryBindAll, Begin / Commit / Rollback transactions
  • ✓TLS handled by libpq, set in the connection string (sslmode=require)

Planned

  • ◐Prepared-statement reuse
  • ◐Typed column accessors: today every cell comes back as text
  • ◐COPY for bulk imports
  • ◐LISTEN / NOTIFY, async queries, cursors

Example

Minimal usage example — copy-paste runnable after install.

import Amalgame.Database.PostgreSQL

public class Program {
    public static void Main() {
        let db = PostgreSQL.Open("host=localhost dbname=app user=app")
        if (!PostgreSQL.IsOpen(db)) {
            Console.WriteLine("connect failed: " + PostgreSQL.LastError(db))
            return
        }
        let params = new List<string>()
        params.Add("true")
        let rows = PostgreSQL.QueryBindAll(db, "SELECT id, name FROM users WHERE active = $1", params)
        for row in rows {
            Console.WriteLine(row.Get(0) + " : " + row.Get(1))
        }
        PostgreSQL.Close(db)
    }
}

At a glance

Related packages