This repository implements the storage.Conn (from webtyp.com/storage) and ddl.Compiler (from webtyp.com/ddl) interfaces for PostgreSQL.
Instead of a global registry or init-driven registration, the PostgreSQL adapter is constructed explicitly:
package main
import (
"log"
"webtyp.com/postgres"
)
func main() {
dsn := "postgres://user:password@localhost:5432/dbname?sslmode=disable"
// Open returns a storage.Conn
conn, err := postgres.Open(dsn)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
// Use conn...
} snap, err := postgres.Backups(dsn).OpenBackup("migrate/pastdb/1793656810107289500-db.backup")
if err != nil { return err }
defer snap.Close()
rows, err := snap.ReadTable("staff")Needs pg_restore in PATH and a URL DSN with permission to CREATE DATABASE. The PostgreSQL client tools must not be newer than the server (ErrPgRestoreNewer says which to install).
- Full
storage.Connimplementation (unifying DML Compilation and Execution). - Transaction support via
BeginTxreturningstorage.TxBoundExecutor. - Secure SQL generation with parameterized queries using
$1,$2, etc. - Support for
Create,ReadOne,ReadAll,Update,DeleteDML actions. - Full DDL schema creation and compilation using
ddl.Compiler. - High-efficiency row scanning with
sql.ErrNoRowscleanly mapped tostorage.ErrNoRows. - Complies with
storage/conformanceandddl/conformancetest suites.