postgres

package
v0.0.0-...-1bdb29e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package postgres provides a convenience constructor for using graph.SQLCheckpointer with a real Postgres database, without callers needing to know which driver to import or how to wire up the DSN.

graph.SQLCheckpointer is already driver-agnostic (bring your own *sql.DB), so this package is intentionally thin: it registers the jackc/pgx stdlib driver, opens/pings the connection, and ensures the checkpoints table exists.

cp, db, err := postgres.New[MyState](ctx, "postgres://user:pass@localhost/mydb")
if err != nil {
	log.Fatal(err)
}
defer db.Close()
compiled, _ := g.Compile(graph.WithCheckpointer[MyState](cp))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[S any](ctx context.Context, dsn string) (*graph.SQLCheckpointer[S], *sql.DB, error)

New opens a Postgres connection at dsn and returns a graph.SQLCheckpointer backed by it, with the checkpoints table (and pending_nodes/pending_sends migration) already ensured.

dsn is a standard Postgres connection string, e.g. "postgres://user:pass@localhost:5432/mydb?sslmode=disable".

The returned *sql.DB is also returned so callers can manage its lifecycle (e.g. call db.Close() on shutdown, or reuse it for other tables).

cp, db, err := postgres.New[MyState](ctx, dsn)
if err != nil { ... }
defer db.Close()
compiled, _ := g.Compile(graph.WithCheckpointer[MyState](cp))

func NewWithDB

func NewWithDB[S any](ctx context.Context, db *sql.DB) (*graph.SQLCheckpointer[S], error)

NewWithDB is like New but takes an already-open *sql.DB (e.g. shared with other tables/pools, or opened with a driver/pooler of the caller's choosing such as pgbouncer). The caller owns the DB's lifecycle.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL