core

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 17 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(name string, d Driver)

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 MergeConfig

func MergeConfig(c ...*Config) *Config

MergeConfig returns merged config.

func MustNewConfig

func MustNewConfig(dir string) *Config

MustNewConfig returns a new config. dir cannot be empty.

func NewConfig

func NewConfig(dir string) (*Config, error)

NewConfig returns a new config. dir cannot be empty.

func (Config) Dir

func (c Config) Dir() string

Dir returns a config file existing path name.

func (Config) Driver

func (c Config) Driver() string

Driver returns a raw driver string.

func (Config) Dsn

func (c Config) Dsn() string

Dsn returns a raw dsn string.

func (*Config) WithEnv

func (c *Config) WithEnv(env string) *Config

WithEnv sets an environment of config.

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.

func GetDriver

func GetDriver(name string) Driver

GetDriver retrieves a registered driver by name.

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) IsValid added in v0.3.0

func (m *Migration) IsValid() bool

IsValid reports whether the migration is valid.

func (*Migration) IsValidTimestamp added in v0.4.3

func (m *Migration) IsValidTimestamp() bool

func (Migration) Name

func (m Migration) Name() string

Name returns a file name.

func (Migration) Read

func (m Migration) Read() ([]byte, error)

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) Version

func (m Migration) Version() uint64

Version returns a migration version value.

func (*Migration) WithVersion

func (m *Migration) WithVersion(v interface{}) *Migration

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

func NewService(c *Config) *Service

NewService returns a new Service pointer that can be chained with builder methods to set multiple configuration values inline without using pointers.

func (*Service) Apply

func (s *Service) Apply(d int, version uint64) error

Apply applies the given migration version.

func (*Service) Down

func (s *Service) Down() error

Down downgrades migration version.

func (*Service) MakeMigrationsDir

func (s *Service) MakeMigrationsDir() error

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) Next

func (s *Service) Next(n int) error

Next upgrades migration version.

func (*Service) NextMigration

func (s *Service) NextMigration(name string) (up *Migration, down *Migration, err error)

NextMigration returns next version migrations.

func (*Service) Prev

func (s *Service) Prev(n int) error

Prev downgrades migration version.

func (*Service) Sync

func (s *Service) Sync() error

Sync applies all migrations.

func (*Service) Up

func (s *Service) Up() error

Up upgrades migration version.

func (*Service) WithDriver

func (s *Service) WithDriver(d Driver) *Service

WithDriver sets a driver returning a Service pointer for chaining.

func (*Service) WithVersion

func (s *Service) WithVersion(v interface{}) *Service

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.

Jump to

Keyboard shortcuts

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