sql

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMigrationDirection = errors.New("invalid migration direction")
)

Functions

func SourceFromDirectory

func SourceFromDirectory(dbGetter func() DBExecer, folder string) (migrations.Source, error)

SourceFromDirectory creates a new source based on the provided folder in the disk.

func SourceFromFS

func SourceFromFS(dbGetter func() DBExecer, fs fs.ReadDirFS, folder string) (migrations.Source, error)

SourceFromFS creates a new source based on the provided fs.ReadDirFS and folder. This is useful for creating a source based on a virtual filesystem (for example `go:embed`). Example:

//go:embed migrations
var migrationsFS embed.FS

source, err := sql.SourceFromFS(dbGetter, migrationsFS, "migrations")

Types

type DB

type DB interface {
	DBExecer
	Driver() driver.Driver
	BeginTx(ctx context.Context, tx *sql.TxOptions) (*sql.Tx, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

type DBExecer

type DBExecer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

type Target

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

func NewTarget

func NewTarget(db DB, options ...TargetOption) (*Target, error)

func (*Target) Add

func (target *Target) Add(ctx context.Context, id string) error

func (*Target) Create

func (target *Target) Create(ctx context.Context) error

func (*Target) Current

func (target *Target) Current(ctx context.Context) (string, error)

func (*Target) Destroy

func (target *Target) Destroy(ctx context.Context) error

func (*Target) Done

func (target *Target) Done(ctx context.Context) ([]string, error)

func (*Target) FinishMigration

func (target *Target) FinishMigration(ctx context.Context, id string) error

func (*Target) Lock

func (target *Target) Lock(ctx context.Context) (migrations.Unlocker, error)

func (*Target) Remove

func (target *Target) Remove(ctx context.Context, id string) error

func (*Target) StartMigration

func (target *Target) StartMigration(ctx context.Context, id string) error

type TargetOption

type TargetOption func(target *targetOpts) error

func WithDriver

func WithDriver(driver drivers.Driver) TargetOption

func WithDriverOptions

func WithDriverOptions(options ...drivers.Option) TargetOption

func WithTableName

func WithTableName(tableName string) TargetOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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