sqlx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2020 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

sqlx

GoDoc

Package sqlx provides a number of SQL-related utilities.

Documentation

Index

Constants

View Source
const (
	MigrationAttemptDelay    = time.Second
	MigrationMaximumAttempts = 5
)

The delay between migration attempts, and the maximum number of attempts to make.

View Source
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

type Database interface {
	Begin() (*sql.Tx, error)
}

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

type Migrator interface {
	Use(migration Migration)
	Migrate(timestamp uint64) error
}

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.

Jump to

Keyboard shortcuts

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