databox

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFirstFieldMustBeAutoIncrInteger = errors.New("Expected first field in structure to be an int64")
View Source
var FlagDatabasePath string = "app.sqlite"
View Source
var FlagMigrationPath string = "migration"
View Source
var MigrateCmd = &cobra.Command{
	Use:   "migrate",
	Short: "Migrates the database of the service",
	Long:  `Migrates the database of the service`,
	Run: func(cmd *cobra.Command, args []string) {
		d := OpenDb(FlagDatabasePath)
		defer d.Close()
		mig := NewMigration(d, FlagDatabasePath, FlagMigrationPath)
		GetMigrationVersion(mig)
	},
}

MigrateCmd represents the migrate command

Functions

func AutoMigration

func AutoMigration(db *sql.DB, databaseName string, migrationUrl string)

func GetMigrationVersion

func GetMigrationVersion(mig *migrate.Migrate) (uint, bool)

func MigrateDown

func MigrateDown(mig *migrate.Migrate)

func MigrateTo

func MigrateTo(mig *migrate.Migrate, version uint)

func MigrateUp

func MigrateUp(mig *migrate.Migrate)

func NewMigratedMemoryDB

func NewMigratedMemoryDB(pathToMigrations string) *sql.DB

func NewMigration

func NewMigration(db *sql.DB, databaseName string, migrationUrl string) *migrate.Migrate

func OpenDb

func OpenDb(name string) *sql.DB

func OpenMemoryDb

func OpenMemoryDb() (*sql.DB, string)

Types

type Dialect added in v1.0.2

type Dialect interface {
	Qt(exp string) string
	QtAll(exp ...string) []string
	QtPtr(exp *string) *string
}

func NewDialect added in v1.0.2

func NewDialect() Dialect

type DialectConfig added in v1.0.2

type DialectConfig struct {
	// contains filtered or unexported fields
}

func (*DialectConfig) Qt added in v1.0.2

func (d *DialectConfig) Qt(exp string) string

func (*DialectConfig) QtAll added in v1.0.2

func (d *DialectConfig) QtAll(exp ...string) []string

func (*DialectConfig) QtPtr added in v1.0.2

func (d *DialectConfig) QtPtr(exp *string) *string

type FactoryFunc added in v1.0.2

type FactoryFunc func() any

type IdSetter added in v1.0.2

type IdSetter func(id int64, row any)

type RevisionStore added in v1.0.2

type RevisionStore interface {
	GetRev(key string) (int64, error)
	IncrRev(key string) (int64, error)
	Close()
}

func NewRevisionStore added in v1.0.2

func NewRevisionStore(db *sql.DB) RevisionStore

type ScanFunc added in v1.0.2

type ScanFunc func(row any) []any

type Store added in v1.0.2

type Store interface {
	Insert(row any) error
	InsertAll(rows ...any) error
	Update(row any) error
	UpdateAll(row ...any) error
	SelectFirst(where string, args ...any) (any, error)
	SelectById(id int64) (any, error)
	SelectAll(where string, args ...any) ([]any, error)
	SelectAllBy(column string, key any) ([]any, error)
	SelectAllByPage(offset *int64, limit *int64, orderBy *string, sortDir *string, search *string) ([]any, int64, error)
	DeleteById(id int64) (bool, error)
	Delete(where string, args ...any) (int64, error)
	DeleteAllBy(column string, key any) (int64, error)
	DeleteFromBy(table string, column string, key any) (int64, error)
	CountAll() (int64, error)
	Count(where string, args ...any) (int64, error)
	CountBy(column string, key any) (int64, error)
	Exists(where string, args ...any) (bool, error)
	ExistsById(id int64) (bool, error)
	ExistsBy(column string, key any) (bool, error)
	IncrRev() (int64, error)
	GetRev() (int64, error)
	Close() error
}

func NewStore added in v1.0.2

func NewStore(config StoreAdapter) Store

type StoreAdapter added in v1.0.2

type StoreAdapter struct {
	Db          *sql.DB
	Dialect     Dialect
	Table       string
	Scan        ScanFunc
	Factory     FactoryFunc
	RevisionKey string
}

Jump to

Keyboard shortcuts

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