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) 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
- type Dialect
- 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) 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)
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) 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.
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 (*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.
func (*Dialect) DriverName ¶
DriverName returns the driver string for database/sql registration via pgx.
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).