Documentation
¶
Index ¶
- Constants
- type Database
- type DefaultMigrator
- type Dialect
- type Dictionary
- type Migration
- type Migrator
- type PostgresDictionary
- func (d *PostgresDictionary) CreateMigrationStateTableIfDoesNotExist() string
- func (d *PostgresDictionary) Dialect() Dialect
- func (d *PostgresDictionary) EnsureCurrentTimestampIsPresentInTable() string
- func (d *PostgresDictionary) GetCurrentTimestamp() string
- func (d *PostgresDictionary) SetCurrentTimestamp() string
- type SQLite3Dictionary
- func (d *SQLite3Dictionary) CreateMigrationStateTableIfDoesNotExist() string
- func (d *SQLite3Dictionary) Dialect() Dialect
- func (d *SQLite3Dictionary) EnsureCurrentTimestampIsPresentInTable() string
- func (d *SQLite3Dictionary) GetCurrentTimestamp() string
- func (d *SQLite3Dictionary) SetCurrentTimestamp() string
- type Tx
Constants ¶
const ( MigrationAttemptDelay = time.Second MigrationMaximumAttempts = 5 )
The delay between migration attempts, and the maximum number of attempts to make.
const ( PostgresDialect = "Postgres" SQLite3Dialect = "SQLite3" )
The sqlx package provides support for two dialects by default: "Postgres" and "SQLite3".
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
Database redefines the methods implemented on *sql.DB that are used by this package.
type DefaultMigrator ¶
type DefaultMigrator struct {
// contains filtered or unexported fields
}
DefaultMigrator is the default migrator in the package. It is not thread safe.
func NewDefaultMigrator ¶
func NewDefaultMigrator(db Database, dictionary Dictionary) *DefaultMigrator
NewDefaultMigrator creates a new DefaultMigrator for the provided database using the provided Dictionary.
func (*DefaultMigrator) Migrate ¶
func (m *DefaultMigrator) Migrate(timestamp uint64) error
Migrate migrates the database to the migration with the provided timestamp.
func (*DefaultMigrator) Use ¶
func (m *DefaultMigrator) Use(migration Migration)
Use adds a migration to the migrator.
type Dialect ¶
type Dialect string
Dialect is a simple string alias type that represents different SQL dialects e.g. "Postgres" or "SQLite3".
type Dictionary ¶
type Dictionary interface {
Dialect() Dialect
CreateMigrationStateTableIfDoesNotExist() string
EnsureCurrentTimestampIsPresentInTable() string
GetCurrentTimestamp() string
SetCurrentTimestamp() string
}
Dictionary defines the methods that a SQL Dialect Dictionary must implement.
type Migration ¶
type Migration interface {
Name() string
Timestamp() uint64
Up(dialect Dialect, tx *sql.Tx) error
Down(dialect Dialect, tx *sql.Tx) error
}
Migration defines the methods that any database migration must implement. Name is a human-friendly name for the migration. Timestamp is used to determine what order migrations should be run in. Enabled determines if the migration is enabled or not. Up and Down apply and tear down the migration respectively.
type Migrator ¶
Migrator defines the methods that any type capable of migrating a database must implement. Use adds a migration to the list of migrations managed by the migrator. Migrate migrates the database to the provided timestamp. Migrate is safe for use across multiple concurrent instances of an application.
func NewMigrator ¶
func NewMigrator(db Database, dictionary Dictionary) Migrator
NewMigrator returns a new migrator for the provided database using the provided dictionary. It is an alias of NewDefaultMigrator.
type PostgresDictionary ¶
type PostgresDictionary struct{}
PostgresDictionary is an implementation of Dictionary for use with Postgres.
func NewPostgresDictionary ¶
func NewPostgresDictionary() *PostgresDictionary
NewPostgresDictionary returns a new PostgresDictionary.
func (*PostgresDictionary) CreateMigrationStateTableIfDoesNotExist ¶
func (d *PostgresDictionary) CreateMigrationStateTableIfDoesNotExist() string
CreateMigrationStateTableIfDoesNotExist returns the Postgres version of this query.
func (*PostgresDictionary) Dialect ¶
func (d *PostgresDictionary) Dialect() Dialect
Dialect returns Postgres.
func (*PostgresDictionary) EnsureCurrentTimestampIsPresentInTable ¶
func (d *PostgresDictionary) EnsureCurrentTimestampIsPresentInTable() string
EnsureCurrentTimestampIsPresentInTable returns the Postgres version of this query.
func (*PostgresDictionary) GetCurrentTimestamp ¶
func (d *PostgresDictionary) GetCurrentTimestamp() string
GetCurrentTimestamp returns the Postgres version of this query.
func (*PostgresDictionary) SetCurrentTimestamp ¶
func (d *PostgresDictionary) SetCurrentTimestamp() string
SetCurrentTimestamp returns the Postgres version of this query.
type SQLite3Dictionary ¶
type SQLite3Dictionary struct{}
SQLite3Dictionary is an implementation of Dictionary for use with SQLite3.
func NewSQLite3Dictionary ¶
func NewSQLite3Dictionary() *SQLite3Dictionary
NewSQLite3Dictionary returns a new SQLite3Dictionary.
func (*SQLite3Dictionary) CreateMigrationStateTableIfDoesNotExist ¶
func (d *SQLite3Dictionary) CreateMigrationStateTableIfDoesNotExist() string
CreateMigrationStateTableIfDoesNotExist returns the SQLite3 version of this query.
func (*SQLite3Dictionary) Dialect ¶
func (d *SQLite3Dictionary) Dialect() Dialect
Dialect returns SQLite3.
func (*SQLite3Dictionary) EnsureCurrentTimestampIsPresentInTable ¶
func (d *SQLite3Dictionary) EnsureCurrentTimestampIsPresentInTable() string
EnsureCurrentTimestampIsPresentInTable returns the SQLite3 version of this query.
func (*SQLite3Dictionary) GetCurrentTimestamp ¶
func (d *SQLite3Dictionary) GetCurrentTimestamp() string
GetCurrentTimestamp returns the SQLite3 version of this query.
func (*SQLite3Dictionary) SetCurrentTimestamp ¶
func (d *SQLite3Dictionary) SetCurrentTimestamp() string
SetCurrentTimestamp returns the SQLite3 version of this query.
type Tx ¶
type Tx interface {
Commit() error
Rollback() error
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}
Tx redefines the methods implemented on *sql.Tx that are used by this package.