postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package postgres opens the composite SQL store on PostgreSQL: the pool of the platform/sql/postgres driver, migrated and wrapped in the composite store of app/adapters/sql.

Role

app, adapter layer (SQL on PostgreSQL): opens the composite on one driver with the options and error texts it had before the composite moved under app. app's store opener calls it for the postgres database type; the tests of the modules reach it only through app/storetest's OpenPostgres. It imports app/adapters/sql and the PostgreSQL driver.

Inputs

  • Open: the DSN of the database, and Options: the composite store's Options and the driver's pool settings, the open connection limit and the connection lifetime.

Outputs

  • Open: the composite store over the database, migrated unless Options.SkipMigrate.

Invariants

  • The driver's errors, ErrDSNRequired among them, are returned as they are, and the composite's open errors behind "postgres: ", so the texts that operators see and the wrapcheck exception for the driver's OpenDB stay as they were.
  • On any failure the pool is closed and no store is returned.

References

Status

Implemented P2 (pull request 3). Moved here in P9d: the pool comes from the platform/sql/postgres driver (issue 995), and the package moved under app (issue 1098).

Testing

Every test but TestAccOpenErrors runs on the PostgreSQL server that the test binary shares (platform/sql/sqltest), and skips with it.

  • postgres_test.go: TestAccContract runs the composite contract of app/storetest, emptying the database between stores with its Reset; TestAccKeyRotation, TestAccLegacyHistoryRefused, TestAccRemoteCachePersistence, TestAccRepositoryHeaderSecrets and TestAccRepositoryHeaderMigration run its composite suites; TestAccStreamsMigrateAlone migrates each module's stream up and down on its own, in a scratch schema; TestAccOpenErrors opens an empty DSN, a malformed one and a closed port, which need no server.
  • schema_test.go: TestAccSchemaGolden compares the migrated schema with testdata/schema.golden.
  • replay_test.go: TestAccReplayProcessCrash and TestAccKeyedReplayProcessCrash, with their children TestAccReplayCrashHelper and TestAccKeyedReplayCrashHelper, as on SQLite, and TestAccReplayPruneDoesNotDeleteRenewal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, dsn string, o Options) (*appsql.Store, error)

Open opens the composite store on the PostgreSQL database that dsn names: the driver's pool with o's pool settings, which appsql.Open pings, migrates unless o.SkipMigrate, wraps in the SQL store and closes on failure. The driver's errors, ErrDSNRequired among them, are returned as they are, and appsql.Open's behind "postgres: ".

Types

type Options

type Options struct {
	appsql.Options
	// MaxOpenConns bounds the pool; 0 keeps the database/sql default.
	MaxOpenConns int
	// ConnMaxLifetime recycles connections; 0 keeps them.
	ConnMaxLifetime time.Duration
}

Options configures Open: the store's options, and the driver's, which Open passes on.

Jump to

Keyboard shortcuts

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