PostgreSQL-specific DALgo driver. Wraps github.com/dal-go/dalgo2sql to provide the dal.DB surface, and adds PostgreSQL-native implementations of:
dbschema.SchemaReader— schema introspection viainformation_schemaandpg_indexesddl.Applier— PostgreSQL-flavoredCREATE TABLE/CREATE INDEX/DROP TABLE/ALTER TABLEdal.ConcurrencyAware— advertisesSupportsConcurrentConnections() = true(PostgreSQL supports concurrent connections from multiple goroutines and processes, unlike SQLite which serializes writers)
import (
"github.com/dal-go/dalgo/dal"
"github.com/dal-go/dalgo2postgres"
"github.com/dal-go/dalgo2sql"
)
// Minimal — no per-collection primary-key configuration.
db, err := dalgo2postgres.NewDatabase("postgres://user:pass@localhost:5432/mydb?sslmode=disable")
// With per-collection recordset options (required for Insert/Get/Delete with map[string]any data):
db, err := dalgo2postgres.NewDatabaseWithOptions(dsn, dal.NewSchema(nil, nil),
dalgo2sql.DbOptions{
Recordsets: map[string]*dalgo2sql.Recordset{
"widgets": dalgo2sql.NewRecordset("widgets", dalgo2sql.Table,
[]dal.FieldRef{dal.Field("id")}),
},
})
if err != nil {
return err
}
defer db.Close()dbschema.Type |
PostgreSQL column type |
|---|---|
String |
TEXT (or VARCHAR(n) when Length is set) |
Int |
BIGINT |
Float |
DOUBLE PRECISION |
Bool |
BOOLEAN |
Time |
TIMESTAMPTZ |
Decimal |
NUMERIC (or NUMERIC(total, scale) when Precision is set) |
Bytes |
BYTEA |
The tests that touch a live database are gated on the DALGO2POSTGRES_TEST_DSN
environment variable. When it is not set, those tests are skipped so plain CI
passes without a database.
Start a local PostgreSQL 17 server (Docker):
docker run -d \
--name postgres17 \
-e POSTGRES_USER=ovdb \
-e POSTGRES_PASSWORD=ovdb \
-e POSTGRES_DB=ovdb \
-p 15432:5432 \
postgres:17Then run the tests:
DALGO2POSTGRES_TEST_DSN='postgres://ovdb:ovdb@127.0.0.1:15432/ovdb?sslmode=disable' \
go test ./... -count=1 -vThis package uses github.com/jackc/pgx/v5/stdlib — a pure-Go PostgreSQL
driver exposed through the standard database/sql interface (driver name "pgx").
No C toolchain is required; the package compiles with CGO_ENABLED=0.
PostgreSQL requires positional parameter markers $1, $2, … rather than the
? style used by SQLite and MySQL. dalgo2postgres automatically sets
dalgo2sql.DbOptions.Placeholder = dalgo2sql.PlaceholderDollar so that all
SQL emitted through dalgo2sql uses the correct form. This field was added to
dalgo2sql as a minimal backward-compatible extension; the zero value
(PlaceholderQuestion) preserves the existing behavior for all other drivers.
PostgreSQL folds unquoted identifiers to lower case. dalgo2postgres quotes
identifiers (so reserved words and otherwise-illegal names stay usable) but
lower-cases them first, so the case-preserving quoted form agrees with the
unquoted references that dalgo2sql's DML and dalgo's structured-query
rendering emit (which PostgreSQL also folds to lower case). DDL and DML thus
always address the same physical identifier.
Consequence: collection (table) and field (column) names are stored
lower-cased. Typed clients round-trip transparently because encoding/json
unmarshalling is case-insensitive; consumers reading raw records observe
lower-cased field names. Fully case-preserving storage would require dalgo's
structured-query String() to quote column identifiers, tracked upstream.