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

postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package postgres provides the PostgreSQL dialect for Orjanda's DAL. Uses github.com/jackc/pgx/v5 as the driver. See TAD §2.3 and PRD §13.3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps *sql.DB and implements dal.Database for PostgreSQL.

func Open

func Open(dsn string) (*DB, error)

Open opens a PostgreSQL database at the given DSN (postgres:// URL).

func (*DB) Close

func (d *DB) Close() error

Close releases the connection pool.

func (*DB) CreateTables

func (d *DB) CreateTables(docs []*schema.CompiledDoc) error

CreateTables executes CREATE TABLE IF NOT EXISTS for all docs (idempotent).

func (*DB) Delete

func (d *DB) Delete(ctx context.Context, docType, id string) error

Delete hard-deletes a record.

func (*DB) Dialect

func (d *DB) Dialect() dal.Dialect

Dialect returns the underlying dal.Dialect.

func (*DB) ExistingColumns

func (d *DB) ExistingColumns(tableName string) (map[string]string, error)

ExistingColumns returns the live column names of a table mapped to the information_schema data_type each reports (unnormalized lowercase base type).

func (*DB) ExistingTables

func (d *DB) ExistingTables() (map[string]bool, error)

ExistingTables returns the set of table names in the current schema.

func (*DB) Insert

func (d *DB) Insert(ctx context.Context, docType string, data map[string]any) (string, error)

Insert writes a new record and returns the generated or provided ULID.

func (*DB) Query

func (d *DB) Query(ctx context.Context, q dal.Select) ([]map[string]any, error)

Query executes a Select and returns rows as maps.

func (*DB) RegisterDoc

func (d *DB) RegisterDoc(docType, tableName string)

RegisterDoc registers a docType→tableName mapping.

func (*DB) RegisterDocs

func (d *DB) RegisterDocs(docs []*schema.CompiledDoc)

RegisterDocs registers mappings from a slice of CompiledDocs.

func (*DB) Transaction

func (d *DB) Transaction(ctx context.Context, fn func(dal.Tx) error) error

Transaction runs fn inside a database transaction.

func (*DB) Underlying

func (d *DB) Underlying() *sql.DB

Underlying returns the raw *sql.DB.

func (*DB) Update

func (d *DB) Update(ctx context.Context, docType, id string, data map[string]any) error

Update mutates an existing record.

type Dialect

type Dialect struct{}

Dialect implements dal.Dialect for PostgreSQL. Uses $N positional placeholders and PostgreSQL DDL conventions. See TAD §2.3 and PRD §13.3.

func New

func New() *Dialect

New returns a new PostgreSQL Dialect.

func (*Dialect) AlterTable

func (d *Dialect) AlterTable(diff schema.TableAlteration) []string

AlterTable generates ALTER TABLE SQL for column additions, drops, and type changes.

func (*Dialect) ColumnType

func (d *Dialect) ColumnType(f schema.Field) string

ColumnType returns the DDL type PostgreSQL uses for the given Field.

func (*Dialect) CreateTable

func (d *Dialect) CreateTable(doc schema.CompiledDoc) string

CreateTable generates CREATE TABLE SQL for the given CompiledDoc.

func (*Dialect) DeleteSQL

func (d *Dialect) DeleteSQL(tableName string, id string) (string, []any)

DeleteSQL renders a hard DELETE statement with $N placeholder.

func (*Dialect) DriverName

func (d *Dialect) DriverName() string

DriverName returns the driver string for database/sql registration via pgx.

func (*Dialect) FullTextSearch

func (d *Dialect) FullTextSearch(tableName string, query string, fields []string) (string, []any)

FullTextSearch renders a PostgreSQL tsvector-based FTS query excluding soft-deleted records.

func (*Dialect) InsertSQL

func (d *Dialect) InsertSQL(tableName string, fields map[string]any) (string, []any)

InsertSQL renders an INSERT statement with $N placeholders.

func (*Dialect) Name

func (d *Dialect) Name() string

Name returns "postgres".

func (*Dialect) NormalizeColumnType

func (d *Dialect) NormalizeColumnType(raw string) string

NormalizeColumnType canonicalizes an information_schema-reported data_type (lowercase base names) and ColumnType output into a comparable token.

func (*Dialect) Placeholder

func (d *Dialect) Placeholder(n int) string

Placeholder returns $N for PostgreSQL positional parameters (1-indexed).

func (*Dialect) SelectSQL

func (d *Dialect) SelectSQL(q dal.Select) (string, []any)

SelectSQL renders a Select into PostgreSQL SQL and a positional args slice.

func (*Dialect) UpdateSQL

func (d *Dialect) UpdateSQL(tableName string, id string, fields map[string]any) (string, []any)

UpdateSQL renders an UPDATE statement with $N placeholders.

Jump to

Keyboard shortcuts

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