db_utils

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OnNewInstance  = errors.New("creating new instance")
	OnVersionCheck = errors.New("checking DB version")
	OnDrop         = errors.New("dropping DB")
)

Functions

func DoMigrate

func DoMigrate[InstanceCfgT any](cfg MigrationConfig[InstanceCfgT],
	newInstance func(db *sql.DB, sourceURL string, cfg InstanceCfgT) (*migrate.Migrate, error)) (uint, bool, error)

DoMigrate applies migration to a database

func NewMigratePgxInstance

func NewMigratePgxInstance(db *sql.DB, sourceURL string, cfg *pgx.Config) (*migrate.Migrate, error)

NewMigratePgxInstance is a newInstance function for pgx/v5 database driver

func NewMigrateSQLiteInstance

func NewMigrateSQLiteInstance(db *sql.DB, sourceURL string, cfg *sqlite3.Config) (*migrate.Migrate, error)

NewMigrateSQLiteInstance is a newInstance function for sqlite3 database driver

Types

type MigrationConfig

type MigrationConfig[InstanceCfgT any] struct {
	// File path
	// format: path or /absolutepath
	MigrationsPath string
	// format: sqlite3://path/to/db
	// postgresql://user:password@ip:port/dbname?conn_opts
	DB *sql.DB
	// Put -1 for no limit, 0 to down database
	// and any number > 0 to limit version
	VersionLimit int
	// Drop DB before applying migrations
	Drop bool
	// Config used for migration connects
	DriverCfg InstanceCfgT
}

Jump to

Keyboard shortcuts

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