driver

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 7 Imported by: 9

Documentation

Overview

Package driver holds the driver interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExtension

func FileExtension(d Driver) string

FileExtension returns extension of migration file for given driver. Panics if you provide instance of unregistered driver.

func FileTemplate

func FileTemplate(d Driver) []byte

FileTemplate returns initial content of migration file for given driver. Panics if you provide instance of unregistered driver.

func Lock

func Lock(d Driver) error

Lock calls Lock method if driver implements Lockable

func Register

func Register(driverName, migrationFileExtension string, migrationFileTemplate []byte, f FactoryFunc)

Register a driver so it can be created from its name. Drivers should call this from an init() function so that they registers themselves on import. filenameExtension returns the extension of the migration files. migrationFileTemplate is a content that should be written into newly-created migration file (can be nil).

func Unlock

func Unlock(d Driver) error

Unlock calls Unlock method if driver implements Lockable

Types

type Driver

type Driver interface {
	// Close is the last function to be called.
	// Close any open connection here.
	Close() error

	// Migrate is the heart of the driver.
	// It will receive a file which the driver should apply
	// to its backend or whatever. The migration function should use
	// the pipe channel to return any errors or other useful information.
	Migrate(file file.File) error

	// Version returns the current migration version.
	Version() (file.Version, error)

	// Versions returns the list of applied migrations.
	Versions() (file.Versions, error)

	// Execute a statement
	Execute(statement string) error
}

Driver is the interface type that needs to implemented by all drivers.

func New

func New(url string) (Driver, error)

New returns Driver and calls Initialize on it.

type FactoryFunc

type FactoryFunc func(url string) (Driver, error)

FactoryFunc produces driver instances

type Lockable

type Lockable interface {
	Lock() error
	Unlock() error
}

Lockable represents driver that supports database locking. Implement if possible to make it safe to run migrations concurrently. NOTE: Probably better to move into Driver interface to make sure it's not dismissed when locking is possible to implement.

Jump to

Keyboard shortcuts

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