Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultDBName ¶
func SetDefaultDBName(name string)
SetDefaultDBName configures the current process to support connecting to a PostgreSQL database. The name should be the name of the database used for development. This should be called before calling flag.Parse(), since it creates the -db CLI flag for specifying the database DSN in production.
Types ¶
type DB ¶
type DB interface { healthcheck.Checker BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error) ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) *sql.Row }
DB is an interface that includes a subset of the methods on sql.DB. Code that works with DB connections should use this interface type rather than *sql.DB directly so that we can substitute an implementation that supports tracing.
func MustOpenDB ¶
MustOpenDB calls OpenDB, but panics if there is an error opening the database or running migrations. Use this in main functions, when panicking was going to be your solution to an error anyway.
func OpenDB ¶
OpenDB opens the PostgreSQL database for the current application. Panics if SetDefaultDBName has not been called. Pass in a fs.FS of migration file contents that were embedded into the binary at build time. These migrations will be run immediately after opening the database to ensure the schema is up-to-date. Returns a database that is instrumented for tracing.