database

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	ApplyMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error
	RecordMigration(ctx context.Context, tx *sql.Tx, migrationName string, batchNum int) error
	RevertMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error
	DeleteMigration(ctx context.Context, tx *sql.Tx, batchNum int) error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	GetNextBatchNumber() (int, error)
	GetLastBatchNumber() (int, error)
	GetAppliedMigrations() (*sql.Rows, error)
	GetUnappliedMigrations(cwd string) ([]string, error)
	GetMigrationsToRevert(batch int) ([]string, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	Close() error
}

func NewDatabase

func NewDatabase(databaseURL string) (Database, error)

type PostgresDB

type PostgresDB struct {
	*sql.DB
}

func (*PostgresDB) ApplyMigration

func (db *PostgresDB) ApplyMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error

func (*PostgresDB) BeginTx

func (db *PostgresDB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

func (*PostgresDB) Close

func (db *PostgresDB) Close() error

func (*PostgresDB) DeleteMigration

func (db *PostgresDB) DeleteMigration(ctx context.Context, tx *sql.Tx, batchNum int) error

func (*PostgresDB) GetAppliedMigrations

func (db *PostgresDB) GetAppliedMigrations() (*sql.Rows, error)

func (*PostgresDB) GetAppliedMigrationsByBatch

func (db *PostgresDB) GetAppliedMigrationsByBatch(batch int) (*sql.Rows, error)

func (*PostgresDB) GetLastBatchNumber

func (db *PostgresDB) GetLastBatchNumber() (int, error)

func (*PostgresDB) GetMigrationsToRevert

func (db *PostgresDB) GetMigrationsToRevert(batch int) ([]string, error)

func (*PostgresDB) GetNextBatchNumber

func (db *PostgresDB) GetNextBatchNumber() (int, error)

func (*PostgresDB) GetUnappliedMigrations

func (db *PostgresDB) GetUnappliedMigrations(cwd string) ([]string, error)

func (*PostgresDB) RecordMigration

func (db *PostgresDB) RecordMigration(ctx context.Context, tx *sql.Tx, migrationName string, batchNum int) error

func (*PostgresDB) RevertMigration

func (db *PostgresDB) RevertMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error

type SQLiteDB

type SQLiteDB struct {
	*sql.DB
}

func (*SQLiteDB) ApplyMigration

func (db *SQLiteDB) ApplyMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error

func (*SQLiteDB) BeginTx

func (db *SQLiteDB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

func (*SQLiteDB) Close

func (db *SQLiteDB) Close() error

func (*SQLiteDB) DeleteMigration

func (db *SQLiteDB) DeleteMigration(ctx context.Context, tx *sql.Tx, batchNum int) error

func (*SQLiteDB) GetAppliedMigrations

func (db *SQLiteDB) GetAppliedMigrations() (*sql.Rows, error)

func (*SQLiteDB) GetAppliedMigrationsByBatch

func (db *SQLiteDB) GetAppliedMigrationsByBatch(batch int) (*sql.Rows, error)

func (*SQLiteDB) GetLastBatchNumber

func (db *SQLiteDB) GetLastBatchNumber() (int, error)

func (*SQLiteDB) GetMigrationsToRevert

func (db *SQLiteDB) GetMigrationsToRevert(batch int) ([]string, error)

func (*SQLiteDB) GetNextBatchNumber

func (db *SQLiteDB) GetNextBatchNumber() (int, error)

func (*SQLiteDB) GetUnappliedMigrations

func (db *SQLiteDB) GetUnappliedMigrations(cwd string) ([]string, error)

func (*SQLiteDB) RecordMigration

func (db *SQLiteDB) RecordMigration(ctx context.Context, tx *sql.Tx, migrationName string, batchNum int) error

func (*SQLiteDB) RevertMigration

func (db *SQLiteDB) RevertMigration(ctx context.Context, tx *sql.Tx, migrationName string, cwd string) error

Jump to

Keyboard shortcuts

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