Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 7 Imported by: 0

README

vormia-go-driver-postgresql

Pure-Go PostgreSQL driver for Vormia Go — thin database/sql wrapper over pgx that satisfies the shared Database contract, with ?→$N rebinding.

Version: v1.1.0 — verified ready for upcoming db:wipe / db:seed (no API change). See CHANGELOG.

Install

go get github.com/vormialabs/vormia-go-driver-postgresql@v1.1.0

Usage

import postgres "github.com/vormialabs/vormia-go-driver-postgresql"

db, err := postgres.Open(postgres.Config{
    Host:     "localhost",
    Port:     5432,
    User:     "postgres",
    Password: "postgres",
    Database: "myapp",
    SSLMode:  "disable", // use "require" or "verify-full" in production
})
if err != nil {
    log.Fatal(err)
}
defer db.Close()

// Write portable SQL with ? placeholders; Rebind converts to $1, $2, ...
query := db.Rebind("SELECT * FROM users WHERE id = ?")
rows, err := db.QueryContext(ctx, query, userID)

Config

Field Default Description
Host localhost PostgreSQL host
Port 5432 PostgreSQL port
SSLMode disable disable, require, verify-ca, verify-full
MaxOpenConns 0 (unlimited) Set deliberately in production (e.g. 10–25)
MaxIdleConns 0 Idle connections kept in the pool
ConnMaxLifetime 0 Max lifetime of a connection

Testing

Unit tests (TestRebind, contract check) run without a database:

go test ./...

Integration tests require a running Postgres. Set PG_TEST_HOST to enable them:

docker run --name vormia-pg \
  -e POSTGRES_PASSWORD=postgres \
  -p 5432:5432 -d postgres:16

export PG_TEST_HOST=localhost
export PG_TEST_PASSWORD=postgres

go test -v ./...
Env var Default
PG_TEST_HOST (required to run integration tests)
PG_TEST_PORT 5432
PG_TEST_USER postgres
PG_TEST_PASSWORD postgres
PG_TEST_DB postgres
PG_TEST_SSLMODE disable

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
	// SSLMode: "disable" (local dev), "require", "verify-ca", "verify-full".
	SSLMode string

	// Pool tuning. Zero means "use database/sql defaults".
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

Config describes how to open a PostgreSQL database.

type DB

type DB struct {
	*sql.DB
}

DB wraps *sql.DB. Embedding promotes all standard methods so the framework's Database contract is satisfied directly.

func Open

func Open(cfg Config) (*DB, error)

Open builds the DSN, opens the pool, applies tuning, and verifies connectivity. sql.Open itself is lazy — Ping is the real check.

func (*DB) Rebind

func (d *DB) Rebind(query string) string

Rebind converts ? placeholders to PostgreSQL's positional $1, $2, ... Apps write portable "?" SQL; this makes it Postgres-native.

Note: this is a sequential replacement and does NOT skip ? inside quoted string literals. Parameterized queries never place a literal ? there, so in practice this is safe — the same tradeoff sqlx makes.

Jump to

Keyboard shortcuts

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