Documentation ¶
Index ¶
- Constants
- func MaybeCommit(conn Connection) error
- func MaybeRollback(conn Connection) error
- func MigrateSchema(logger logger.Logger, conn Connection, providers ...MigrationsProvider) error
- func MigrationVersion(conn Connection, name string) (int, error)
- func SaveMigrationVersion(conn Connection, name string, version int) error
- type Check
- type Checks
- type ConfigurableConnection
- type Connection
- type Constraint
- type ConstraintType
- type Migration
- type MigrationCheckProvider
- type Migrations
- type MigrationsProvider
- type Transaction
- type TransactionFactory
Constants ¶
View Source
const BootstrapSchema = `` /* 241-byte string literal not displayed */
BootstrapSchema is the schema of the migrations table.
Changing this is a major change, since "normal" updates won't work after it, so special upgrade steps will be needed.
Variables ¶
This section is empty.
Functions ¶
func MaybeCommit ¶
func MaybeCommit(conn Connection) error
func MaybeRollback ¶
func MaybeRollback(conn Connection) error
func MigrateSchema ¶
func MigrateSchema(logger logger.Logger, conn Connection, providers ...MigrationsProvider) error
func MigrationVersion ¶
func MigrationVersion(conn Connection, name string) (int, error)
func SaveMigrationVersion ¶
func SaveMigrationVersion(conn Connection, name string, version int) error
Types ¶
type ConfigurableConnection ¶
type ConfigurableConnection interface { Connection SetConnMaxLifetime(d time.Duration) SetMaxIdleConns(n int) SetMaxOpenConns(n int) }
func Connect ¶
func Connect(dbUrl string) (ConfigurableConnection, error)
Connect creates a database connection to a PostgreSQL database.
type Connection ¶
type Connection interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
Connection represents a database connection.
func MaybeBegin ¶
func MaybeBegin(conn Connection) (Connection, error)
func NewLoggerDB ¶
func NewLoggerDB(logger logger.Logger, db Connection) Connection
NewLoggerDB wraps a database connection with a logger.
func TestConnect ¶
func TestConnect(dbUrl string) (Connection, func())
TestConnect creates a connection to a PostgreSQL database for testing.
This will set up a temporary schema, and delete it after the test is run.
The correct usage of this function:
conn, cleanup := database.TestConnect(os.Getenv("DATABASE_URL")) t.Cleanup(cleanup)
type Constraint ¶
type Constraint struct { Name string Type ConstraintType }
func LoadConstraints ¶
func LoadConstraints(conn Connection, relname, prefix string) ([]Constraint, error)
type ConstraintType ¶
type ConstraintType string
const ( ConstraintTypePrimary ConstraintType = "p" ConstraintTypeUnique ConstraintType = "u" ConstraintTypeCheck ConstraintType = "c" ConstraintTypeForeign ConstraintType = "f" ConstraintTypeExclusion ConstraintType = "x" ConstraintTypeUniqueIndex ConstraintType = "iu" )
func (ConstraintType) DropDefinition ¶
func (c ConstraintType) DropDefinition(name string) string
type MigrationCheckProvider ¶
type MigrationCheckProvider interface { MigrationsProvider Checks() Checks }
func DecorateMigrationsWithChecks ¶
func DecorateMigrationsWithChecks(mp MigrationsProvider, checks ...Check) MigrationCheckProvider
type Migrations ¶
type Migrations []Migration
func (Migrations) UpgradeFrom ¶
func (g Migrations) UpgradeFrom(last int, logger logger.Logger, conn Connection) (int, error)
type MigrationsProvider ¶
type MigrationsProvider interface { Name() string Migrations() Migrations }
func DefineMigrations ¶
func DefineMigrations(name string, gens ...Migration) MigrationsProvider
type Transaction ¶
type Transaction interface { Connection Commit() error Rollback() error }
Transaction represents a database connection with an active transaction.
type TransactionFactory ¶
type TransactionFactory interface {
Begin() (Transaction, error)
}
TransactionFactory can initiate a transaction.
Click to show internal directories.
Click to hide internal directories.