adapter

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Open() error
	Close() error
	CreateDatabase() error
	DropDatabase() error
	CreateMigrationsTable(ctx context.Context) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryVersion(ctx context.Context, version string) (*sql.Rows, error)
}

func NewAdapter

func NewAdapter(cfg *schema.Config) (Adapter, error)

type Config added in v0.1.11

type Config struct {
	Adapter string
	// full connection url
	URL string
	// connection url without database
	URL2 string
	// database, for sqlite it is sqlite file path
	Database string
	Host     string
	Port     string
	Username string
	Password string
	Options  url.Values
}

func NewConfig added in v0.1.11

func NewConfig(cfg *schema.Config) *Config

func NewConfigFromURL added in v0.2.0

func NewConfigFromURL(rawURL string) *Config

func (*Config) GoFormat added in v0.2.0

func (c *Config) GoFormat() string

func (*Config) TSFormat added in v0.2.0

func (c *Config) TSFormat() string

type DownMigrations

type DownMigrations Migrations

func (DownMigrations) Len

func (ms DownMigrations) Len() int

func (DownMigrations) Less

func (ms DownMigrations) Less(i, j int) bool

func (DownMigrations) Swap

func (ms DownMigrations) Swap(i, j int)

type Migration

type Migration struct {
	Path      string
	Version   string
	Name      string
	Direction string
}

func ParseMigrationFilename

func ParseMigrationFilename(filename string) (*Migration, error)

type Migrations

type Migrations []*Migration

type Migrator

type Migrator struct {
	Adapter         Adapter
	MigrationsPath  string
	MigrationsTable string
	UpMigrations    UpMigrations
	DownMigrations  DownMigrations
}

func NewMigrator

func NewMigrator(adapter Adapter) (*Migrator, error)

func (*Migrator) CreateTable

func (m *Migrator) CreateTable() error

func (*Migrator) Down

func (m *Migrator) Down() error

func (*Migrator) DownWithStep

func (m *Migrator) DownWithStep(step int) error

func (*Migrator) FindMigrations

func (m *Migrator) FindMigrations() error

func (*Migrator) Reset

func (m *Migrator) Reset() error

func (*Migrator) RunMigration

func (m *Migrator) RunMigration(mg *Migration) error

func (*Migrator) Status

func (m *Migrator) Status(out io.Writer) error

func (*Migrator) Up

func (m *Migrator) Up() error

func (*Migrator) UpWithVersion

func (m *Migrator) UpWithVersion(version string) error

type MySQLAdapter added in v0.1.7

type MySQLAdapter struct {
	*sql.DB
	Config *Config
}

func NewMySQLAdapter added in v0.1.7

func NewMySQLAdapter(config *Config) *MySQLAdapter

func (*MySQLAdapter) CreateDatabase added in v0.1.7

func (a *MySQLAdapter) CreateDatabase() error

func (*MySQLAdapter) CreateMigrationsTable added in v0.1.7

func (a *MySQLAdapter) CreateMigrationsTable(ctx context.Context) error

create migrations table with atlas

func (*MySQLAdapter) DropDatabase added in v0.1.7

func (a *MySQLAdapter) DropDatabase() error

func (*MySQLAdapter) Open added in v0.1.7

func (a *MySQLAdapter) Open() error

func (*MySQLAdapter) QueryVersion added in v0.1.11

func (a *MySQLAdapter) QueryVersion(ctx context.Context, version string) (*sql.Rows, error)

type PostgreSQLAdapter

type PostgreSQLAdapter struct {
	*sql.DB
	Config *Config
}

func NewPostgreSQLAdapter

func NewPostgreSQLAdapter(config *Config) *PostgreSQLAdapter

func (*PostgreSQLAdapter) CreateDatabase

func (a *PostgreSQLAdapter) CreateDatabase() error

func (*PostgreSQLAdapter) CreateMigrationsTable

func (a *PostgreSQLAdapter) CreateMigrationsTable(ctx context.Context) error

create migrations table with atlas

func (*PostgreSQLAdapter) DropDatabase

func (a *PostgreSQLAdapter) DropDatabase() error

func (*PostgreSQLAdapter) Open

func (a *PostgreSQLAdapter) Open() error

func (*PostgreSQLAdapter) QueryVersion added in v0.1.11

func (a *PostgreSQLAdapter) QueryVersion(ctx context.Context, version string) (*sql.Rows, error)

type SQLiteAdapter

type SQLiteAdapter struct {
	*sql.DB
	Config *Config
}

func NewSQLiteAdapter

func NewSQLiteAdapter(config *Config) *SQLiteAdapter

func (*SQLiteAdapter) CreateDatabase

func (a *SQLiteAdapter) CreateDatabase() error

func (*SQLiteAdapter) CreateMigrationsTable

func (a *SQLiteAdapter) CreateMigrationsTable(ctx context.Context) error

create migrations table with atlas

func (*SQLiteAdapter) DropDatabase

func (a *SQLiteAdapter) DropDatabase() error

func (*SQLiteAdapter) Open

func (a *SQLiteAdapter) Open() error

func (*SQLiteAdapter) QueryVersion added in v0.1.11

func (a *SQLiteAdapter) QueryVersion(ctx context.Context, version string) (*sql.Rows, error)

type UpMigrations

type UpMigrations Migrations

func (UpMigrations) Len

func (ms UpMigrations) Len() int

func (UpMigrations) Less

func (ms UpMigrations) Less(i, j int) bool

func (UpMigrations) Swap

func (ms UpMigrations) Swap(i, j int)

Jump to

Keyboard shortcuts

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