dialect

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect string

Dialect is the type of database dialect.

const (
	Postgres    Dialect = "postgres"
	Mysql       Dialect = "mysql"
	Sqlite3     Dialect = "sqlite3"
	Sqlserver   Dialect = "sqlserver"
	Redshift    Dialect = "redshift"
	Tidb        Dialect = "tidb"
	Clickhouse  Dialect = "clickhouse"
	Vertica     Dialect = "vertica"
	Ydb         Dialect = "ydb"
	Sqlanywhere Dialect = "sqlanywhere"
)

type GetMigrationResult

type GetMigrationResult struct {
	IsApplied bool
	Timestamp time.Time
}

type ListMigrationsResult

type ListMigrationsResult struct {
	VersionID int64
	IsApplied bool
}

type Store

type Store interface {
	// CreateVersionTable creates the version table within a transaction.
	// This table is used to store goose migrations.
	CreateVersionTable(ctx context.Context, tx *sql.Tx, tableName string) error

	// InsertVersion inserts a version id into the version table within a transaction.
	InsertVersion(ctx context.Context, tx *sql.Tx, tableName string, version int64) error
	// InsertVersionNoTx inserts a version id into the version table without a transaction.
	InsertVersionNoTx(ctx context.Context, db *sql.DB, tableName string, version int64) error

	// DeleteVersion deletes a version id from the version table within a transaction.
	DeleteVersion(ctx context.Context, tx *sql.Tx, tableName string, version int64) error
	// DeleteVersionNoTx deletes a version id from the version table without a transaction.
	DeleteVersionNoTx(ctx context.Context, db *sql.DB, tableName string, version int64) error

	// GetMigrationRow retrieves a single migration by version id.
	//
	// Returns the raw sql error if the query fails. It is the callers responsibility
	// to assert for the correct error, such as sql.ErrNoRows.
	GetMigration(ctx context.Context, db *sql.DB, tableName string, version int64) (*GetMigrationResult, error)

	// ListMigrations retrieves all migrations sorted in descending order by id.
	//
	// If there are no migrations, an empty slice is returned with no error.
	ListMigrations(ctx context.Context, db *sql.DB, tableName string) ([]*ListMigrationsResult, error)
}

Store is the interface that wraps the basic methods for a database dialect.

A dialect is a set of SQL statements that are specific to a database.

By defining a store interface, we can support multiple databases with a single codebase.

The underlying implementation does not modify the error. It is the callers responsibility to assert for the correct error, such as sql.ErrNoRows.

func NewStore

func NewStore(d Dialect) (Store, error)

NewStore returns a new Store for the given dialect.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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