Documentation
¶
Index ¶
- func RegisterDriver(name string, d Driver)
- type Config
- type Driver
- type Migration
- type Migrations
- type Service
- func (s *Service) Apply(d int, version uint64) error
- func (s *Service) Down() error
- func (s *Service) MakeMigrationsDir() error
- func (s *Service) Next(n int) error
- func (s *Service) NextMigration(name string) (up *Migration, down *Migration, err error)
- func (s *Service) Prev(n int) error
- func (s *Service) Sync() error
- func (s *Service) Up() error
- func (s *Service) WithDriver(d Driver) *Service
- func (s *Service) WithVersion(v interface{}) *Service
- type Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
RegisterDriver a driver so it can be created from its name. Drivers should call this from an init() function so that they registers themselvse on import
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config object.
func MustNewConfig ¶
MustNewConfig returns a new config. dir cannot be empty.
type Driver ¶
type Driver interface {
// Open is the first function to be called.
// Check the dsn string and open and verify any connection
// that has to be made.
Open(string) error
// Close is the last function to be called.
// Close any open connection here.
Close() error
// Ext returns the sql file extension used by path. The extension is the
// suffix beginning at the final dot in the final element of path; it is
// empty if there is no dot.
Ext() string
// Transaction starts a db transaction. The isolation level is dependent on the
// driver.
Transaction(func(*sql.Tx) error) 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(*Migration) error
// Version returns a version interface.
Version() Version
}
Driver interface.
type Migration ¶
type Migration struct {
// contains filtered or unexported fields
}
A Migration manages migration files.
func NewMigration ¶
func NewMigration() *Migration
NewMigration returns a new Migration pointer that can be chained with builder methods to set multiple configuration values inline without using pointers.
func (Migration) Read ¶
Read reads from file until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.
func (*Migration) WithVersion ¶
WithVersion sets a config version value returning a Config pointer for chaining.
type Migrations ¶
type Migrations []*Migration
A Migrations collects Migration for sorting.
func (Migrations) Len ¶
func (m Migrations) Len() int
Len is the number of elements in the collection. Required by Sort Interface{}
func (Migrations) Less ¶
func (m Migrations) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j. Required by Sort Interface{}
func (Migrations) Swap ¶
func (m Migrations) Swap(i, j int)
Swap swaps the elements with indexes i and j. Required by Sort Interface{}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
A Service manages for kamimai.
func NewService ¶
NewService returns a new Service pointer that can be chained with builder methods to set multiple configuration values inline without using pointers.
func (*Service) MakeMigrationsDir ¶
MakeMigrationsDir creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. If path is already a directory, MkdirAll does nothing and returns nil.
func (*Service) NextMigration ¶
NextMigration returns next version migrations.
func (*Service) WithDriver ¶
WithDriver sets a driver returning a Service pointer for chaining.
func (*Service) WithVersion ¶
WithVersion sets a config version value returning a Service pointer for chaining.
type Version ¶
type Version interface {
// Insert inserts the given migration version.
Insert(uint64) error
// Delete deletes the given migration version.
Delete(uint64) error
// Count counts number of row the given migration version.
Count(uint64) int
// Current returns the current migration version.
Current() (uint64, error)
// Create creates
Create() error
// Drop drops
Drop() error
}
Version interface.