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

postgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package postgres builds models on PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect is the PostgreSQL half of building a model.

func (Dialect) Build

func (d Dialect) Build(m model.Model, current dialect.Kind) ([]string, error)

Build is every statement that turns the model into what its header says.

A VIEW IS REPLACED IN PLACE, never dropped, and that is conservative on purpose. `DROP VIEW ... CASCADE` would also take anything depending on it -- including a view somebody wrote by hand outside this project -- and a build deciding that on its own is the kind of silent loss this repository refuses elsewhere.

WHAT IT COSTS, said where somebody hitting it will look: `CREATE OR REPLACE VIEW` cannot change the view's column names or drop a column, so a model whose SELECT list changed shape fails with Postgres's own message ("cannot change name of view column ..."). Dropping it by hand is the way through today; `--full-refresh` is the way through when it exists.

A TABLE IS REBUILT, because `CREATE TABLE AS` is the only way to get the new rows and Postgres has no `CREATE OR REPLACE TABLE`. The drop carries no CASCADE either, so a view reading this table blocks the rebuild and Postgres says which view -- rather than the build removing it.

func (Dialect) EnsureSchema

func (Dialect) EnsureSchema(schema string) []string

EnsureSchema makes the schema, and is safe to run again.

func (Dialect) KindOf

func (Dialect) KindOf(ref string) string

KindOf asks pg_catalog what the relation is.

`relkind` and not information_schema: a materialised view is `m` there and invisible here, and "the build thinks nothing is there and CREATE fails" is a worse answer than "something else is there".

func (Dialect) Literal

func (Dialect) Literal(s string) string

Literal doubles the quote and leaves everything else alone.

Postgres has treated a backslash as an ordinary character since 9.1, when standard_conforming_strings became the default -- verified against the server this project tests on, not taken from the documentation. So escaping one would produce TWO, and a value with a backslash in it would stop matching the data it was written for.

A server with standard_conforming_strings OFF is out of scope and says so rather than being guessed at: that setting is twelve years deprecated, and a dialect quietly producing different SQL per session variable is worse than one that is wrong in a documented way.

func (Dialect) Name

func (Dialect) Name() string

Name is also what the reference extractor is given for this project.

func (Dialect) Open

func (Dialect) Open(ctx context.Context, dsn string) (dialect.Conn, error)

Open connects.

THE SECOND REQUIRE THIS MODULE HAS, and it is the one go.mod's own comment said would have to argue for itself. It does: S4 of #62 is "against a real Postgres", a dialect that cannot connect cannot be conformance-tested, and a test suite that proves only the strings is the thing this package exists to avoid. pgx is what the SDK already uses, so the repository has one Postgres driver rather than two opinions about escaping.

Jump to

Keyboard shortcuts

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