Documentation
¶
Index ¶
Constants ¶
const ( // CreateSchema is the format string for the statement that creates a schema. // Schema names cannot be bound as query parameters, so the name is // interpolated into the statement. CreateSchema = "CREATE SCHEMA IF NOT EXISTS %s;" // MaxIdleConnsDefault is the number of idle connections a pool keeps when the // caller expresses no preference. // // database/sql keeps two, so past the second concurrent query every call opens // a fresh connection — a TCP round trip, a TLS handshake and a PostgreSQL // authentication exchange — and discards it on release, putting a silent // latency floor under every query. Idle connections cost a file descriptor // here and a backend on the server; ten stays well under a stock // max_connections of 100 once multiplied by a service's replica count. MaxIdleConnsDefault = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Default ¶
type Default struct {
// MaxIdleConns overrides how many idle connections the pools keep. Zero means
// MaxIdleConnsDefault; a negative value keeps none, matching database/sql.
MaxIdleConns int
// MaxOpenConns bounds how many connections the pools may open. Zero means
// unlimited, matching database/sql.
//
// No default: the right number depends on how many replicas share the database,
// which a library cannot know.
//
// The limit applies as a pool opens. Setting it on the handle afterwards stops
// working once anything has taken a connection, because the handle is cached;
// past that point it applies to nothing and reports nothing.
MaxOpenConns int
// contains filtered or unexported fields
}
Default is the standard postgres.Config implementation, backed by pgdriver. It opens connections lazily and caches them: one for the primary database and one per requested schema, all guarded by a single mutex.
func NewDefault ¶
NewDefault returns a Default that connects using the given pgdriver options.
func (*Default) DBSchema ¶
DBSchema returns a database connection scoped to the named schema, caching one connection per schema name. When create is true and the schema has no cached connection yet, the schema is created before the connection is returned.
func (*Default) DropSchema ¶ added in v0.27.0
DropSchema removes a schema created through DBSchema and releases the pool cached for it. It is a test-support operation — production schemas are not dropped — and pairs with the throwaway schema RunIsolatedTransactionalTest stands up.
Without it, a randomly named schema and its pool are both kept forever: the schema accumulates in the database, and the pool holds idle connections against a schema nothing will query again.