sql

package
v0.0.0-...-f3e7390 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package sql implements a generic adapter for SQL databases. It uses only the database/sql standard package.

Index

Constants

View Source
const DefaultPlaceholder = "?"

DefaultPlaceholder holds the default value for the sql placeholder If you're on postgres, you should use ${i} where {i} will be replaced by the arg position. See PostgrePlaceholder.

View Source
const DefaultTableName = "__migrations"

DefaultTableName represents the default name of the migrations table

View Source
const PostgrePlaceholder = "${i}"

PostgrePlaceholder holds the default placeholder for pg databases.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements the interface defined by migrataur for common SQL databases

func WithDB

func WithDB(db *sql.DB) *Adapter

WithDB constructs a sql adapter with the given DB handle. It will use the default tableName "__migrations" and "?" placeholder.

func WithDBAndOptions

func WithDBAndOptions(db *sql.DB, table, placeholder string) *Adapter

WithDBAndOptions constructs a sql adapter with the given DB handle and options. table is the the name of the migrations table and placeholder is DB dependent. If you're on postgres, you should use ${i} where {i} will be replaced by the arg position.

func (*Adapter) Exec

func (a *Adapter) Exec(command string) error

Exec the given commands. This is call by Migrataur to apply or rollback a migration with the corresponding code.

func (*Adapter) GetAll

func (a *Adapter) GetAll() ([]*migrataur.Migration, error)

GetAll retrieves all migrations for this adapter

func (*Adapter) GetInitialMigration

func (a *Adapter) GetInitialMigration() (up, down string)

GetInitialMigration retrieves the migration up and down code and is used to populate the migrations history table.

func (*Adapter) MigrationApplied

func (a *Adapter) MigrationApplied(migration *migrataur.Migration) error

MigrationApplied is called when the migration has been successfully applied by the adapter. This is where you should insert the migration in the history.

func (*Adapter) MigrationRollbacked

func (a *Adapter) MigrationRollbacked(migration *migrataur.Migration) error

MigrationRollbacked is called when the migration has been successfully rolled back. This is where you should remove the migration from the history.

Jump to

Keyboard shortcuts

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