db

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateUp

func MigrateUp(db *sql.DB) error

Types

type DbApi

type DbApi struct {
	DbConfig *config.DbConfig
	DbPool   *pgxpool.Pool

	ConnCtx context.Context
	Cancel  context.CancelFunc

	DbStatusNotifier server.Producer
}

func NewDbApi

func NewDbApi(config *config.DbConfig) (*DbApi, error)

func (*DbApi) Acquire

func (api *DbApi) Acquire() (*pgxpool.Conn, error)

func (*DbApi) CreateDb

func (api *DbApi) CreateDb(params *CreateDbParams, q *Queries) (*Db, error)

func (*DbApi) CreateDbTask

func (api *DbApi) CreateDbTask(params *CreateDbTaskParams, q *Queries) (*DbTask, error)

func (*DbApi) GetDb

func (api *DbApi) GetDb(dbId int64, q *Queries) (*Db, error)

func (*DbApi) GetDbByName

func (api *DbApi) GetDbByName(name string, q *Queries) (*Db, error)

func (*DbApi) ListDbs

func (api *DbApi) ListDbs(q *Queries) ([]Db, error)

func (*DbApi) MigrateDB

func (api *DbApi) MigrateDB(quitCtx context.Context) error

func (*DbApi) NotifyDbStatusChanged

func (api *DbApi) NotifyDbStatusChanged(db *Db)

func (*DbApi) Query

func (api *DbApi) Query(queryFunc QueryFunc) error

func (*DbApi) QueryWithRollback

func (api *DbApi) QueryWithRollback(queryFunc QueryWithRollbackFunc) error

func (*DbApi) ToProtoDatabases

func (api *DbApi) ToProtoDatabases(dbs []Db) []*proto.Database

func (*DbApi) UpdateDbStatus

func (api *DbApi) UpdateDbStatus(db *Db, q *Queries) error

func (*DbApi) UpdateTaskStatus

func (api *DbApi) UpdateTaskStatus(task *DbTask, q *Queries) error

type DbTaskData

type DbTaskData struct {
	// This task depends on other tasks
	// Valid in all tasks
	DependsOn []uuid.UUID `json:"depends_on"`

	// When the task is failed or canceled,
	// this field contains the reason of the failure
	// Valid in all tasks
	ErrReason string `json:"err_reason"`

	// The pg instance to run backup task
	BackupFrom string `json:"backup_from"`
	// The backup path of the database, in format of `pg-<major>/<database name>/<timestamp>.sql`
	// e.g. `pg-12/mydb/2021-01-01T01:01:01.sql`
	//
	// This path is relative to DbConfig.BackupRootPath
	//
	// Valid in following tasks:
	// - backup
	// - remote-backup
	// - restore
	BackupPath string `json:"backup_path"`

	Owner string `json:"owner"`

	// Do not save password to database
	Password string `json:"-"`
}

type QueryFunc

type QueryFunc func(*Queries) error

type QueryWithRollbackFunc

type QueryWithRollbackFunc func(pgx.Tx) error

Jump to

Keyboard shortcuts

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