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 ¶
- type DB
- func (d *DB) Close() error
- func (d *DB) CreateTables(docs []*schema.CompiledDoc) error
- func (d *DB) Delete(ctx context.Context, docType, id string) error
- func (d *DB) Dialect() dal.Dialect
- func (d *DB) ExistingColumns(tableName string) (map[string]string, error)
- func (d *DB) ExistingForeignKeys(tableName string) ([]dal.ForeignKeyInfo, error)
- func (d *DB) ExistingTables() (map[string]bool, error)
- func (d *DB) Insert(ctx context.Context, docType string, data map[string]any) (string, error)
- func (d *DB) Query(ctx context.Context, q dal.Select) ([]map[string]any, error)
- func (d *DB) RegisterDoc(docType, tableName string)
- func (d *DB) RegisterDocs(docs []*schema.CompiledDoc)
- func (d *DB) Transaction(ctx context.Context, fn func(dal.Tx) error) error
- func (d *DB) Underlying() *sql.DB
- func (d *DB) Update(ctx context.Context, docType, id string, data map[string]any) error
- func (d *DB) WithForeignKeys(on bool)
- type Dialect
- func (d *Dialect) AddForeignKey(fkc schema.ForeignKeyConstraint) string
- func (d *Dialect) AlterTable(diff schema.TableAlteration) []string
- func (d *Dialect) ColumnType(f schema.Field) string
- func (d *Dialect) CreateTable(doc schema.CompiledDoc) string
- func (d *Dialect) DeleteSQL(tableName string, id string) (string, []any)
- func (d *Dialect) DriverName() string
- func (d *Dialect) DropForeignKey(fkc schema.ForeignKeyConstraint) string
- func (d *Dialect) EnforceForeignKeys() bool
- func (d *Dialect) FullTextSearch(tableName string, query string, fields []string) (string, []any)
- func (d *Dialect) InsertSQL(tableName string, fields map[string]any) (string, []any)
- func (d *Dialect) Name() string
- func (d *Dialect) NormalizeColumnType(raw string) string
- func (d *Dialect) Placeholder(n int) string
- func (d *Dialect) SelectSQL(q dal.Select) (string, []any)
- func (d *Dialect) UpdateSQL(tableName string, id string, fields map[string]any) (string, []any)
- func (d *Dialect) WithForeignKeys(on bool)
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 (*DB) CreateTables ¶
func (d *DB) CreateTables(docs []*schema.CompiledDoc) error
CreateTables executes CREATE TABLE IF NOT EXISTS for all docs (idempotent).
func (*DB) ExistingColumns ¶
ExistingColumns returns the live column names of a table mapped to the information_schema data_type each reports (unnormalized lowercase base type).
func (*DB) ExistingForeignKeys ¶ added in v0.1.6
func (d *DB) ExistingForeignKeys(tableName string) ([]dal.ForeignKeyInfo, error)
ExistingForeignKeys returns the live FK constraints on a table by parsing pg_get_constraintdef() (Phase 3).
func (*DB) ExistingTables ¶
ExistingTables returns the set of table names in the current schema.
func (*DB) RegisterDoc ¶
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 ¶
Transaction runs fn inside a database transaction.
func (*DB) WithForeignKeys ¶ added in v0.1.6
WithForeignKeys sets whether CreateTable emits DB-level FOREIGN KEY constraints for Link fields (proposal §3.5). Off by default (opt-in, §5.4 step 3). Forwarded to the dialect.
type Dialect ¶
type Dialect struct {
// contains filtered or unexported fields
}
Dialect implements dal.Dialect for PostgreSQL. Uses $N positional placeholders and PostgreSQL DDL conventions. See TAD §2.3 and PRD §13.3.
func (*Dialect) AddForeignKey ¶ added in v0.1.6
func (d *Dialect) AddForeignKey(fkc schema.ForeignKeyConstraint) string
AddForeignKey renders an ALTER TABLE ... ADD CONSTRAINT ... for an FK delta. Uses a deterministic constraint name derived from the column so a later DROP can target it. See proposal §5.1.
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 ¶
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. Link fields emit a DB-level FOREIGN KEY ... REFERENCES ... ON DELETE ... constraint (defense-in-depth against non-framework writes, §3.5), unless the field carries oj:"no_fk". ON DELETE uses restrict|cascade|set_null as declared; on_delete defaults to restrict at compile time (registry.go).
func (*Dialect) DriverName ¶
DriverName returns the driver string for database/sql registration via pgx.
func (*Dialect) DropForeignKey ¶ added in v0.1.6
func (d *Dialect) DropForeignKey(fkc schema.ForeignKeyConstraint) string
DropForeignKey renders an ALTER TABLE ... DROP CONSTRAINT ... for an FK delta.
func (*Dialect) EnforceForeignKeys ¶ added in v0.1.6
EnforceForeignKeys reports whether FK emission is enabled.
func (*Dialect) FullTextSearch ¶
FullTextSearch renders a PostgreSQL tsvector-based FTS query excluding soft-deleted records.
func (*Dialect) NormalizeColumnType ¶
NormalizeColumnType canonicalizes an information_schema-reported data_type (lowercase base names) and ColumnType output into a comparable token.
func (*Dialect) Placeholder ¶
Placeholder returns $N for PostgreSQL positional parameters (1-indexed).
func (*Dialect) SelectSQL ¶
SelectSQL renders a Select into PostgreSQL SQL and a positional args slice.
func (*Dialect) WithForeignKeys ¶ added in v0.1.6
WithForeignKeys sets whether CreateTable emits FOREIGN KEY constraints for Link fields. Off by default (opt-in, proposal §5.4 step 3).