database

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExecuteSqlError added in v1.2.10

func NewExecuteSqlError(sql string, errorOccurred error) error

func NewTemplateFormatError added in v1.2.10

func NewTemplateFormatError(template []rune) error

Types

type BaseDatabaseImplement

type BaseDatabaseImplement struct {
	Db      *gorm.DB
	Logger  logger.Logger
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*BaseDatabaseImplement) Count

func (s *BaseDatabaseImplement) Count(table, query string, args ...any) (count int64, err error)

func (*BaseDatabaseImplement) CountWithCtx

func (s *BaseDatabaseImplement) CountWithCtx(ctx context.Context, table, query string, args ...any) (count int64, err error)

func (*BaseDatabaseImplement) DeleteAll

func (s *BaseDatabaseImplement) DeleteAll(query string, args ...any) error

func (*BaseDatabaseImplement) DeleteAllWithCtx

func (s *BaseDatabaseImplement) DeleteAllWithCtx(ctx context.Context, query string, args ...any) error

func (*BaseDatabaseImplement) DeleteOne

func (s *BaseDatabaseImplement) DeleteOne(query string, args ...any) error

func (*BaseDatabaseImplement) DeleteOneWithCtx

func (s *BaseDatabaseImplement) DeleteOneWithCtx(ctx context.Context, query string, args ...any) error

func (*BaseDatabaseImplement) ExecRaw

func (s *BaseDatabaseImplement) ExecRaw(sql string, args ...any) error

func (*BaseDatabaseImplement) ExecRawWithCtx

func (s *BaseDatabaseImplement) ExecRawWithCtx(ctx context.Context, sql string, args ...any) error

func (*BaseDatabaseImplement) ExtMethods added in v1.2.7

func (s *BaseDatabaseImplement) ExtMethods() ExtMethods

func (*BaseDatabaseImplement) GetAll

func (s *BaseDatabaseImplement) GetAll(receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) GetAllWithCtx

func (s *BaseDatabaseImplement) GetAllWithCtx(ctx context.Context, receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) GetOne

func (s *BaseDatabaseImplement) GetOne(receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) GetOneWithCtx

func (s *BaseDatabaseImplement) GetOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) GetPage

func (s *BaseDatabaseImplement) GetPage(receiver any, offset, limit int, query string, args ...any) error

func (*BaseDatabaseImplement) Has

func (s *BaseDatabaseImplement) Has(table, query string, args ...any) (exist bool, err error)

func (*BaseDatabaseImplement) HasWithCtx

func (s *BaseDatabaseImplement) HasWithCtx(ctx context.Context, table, query string, args ...any) (exist bool, err error)

func (*BaseDatabaseImplement) Init

func (s *BaseDatabaseImplement) Init(_ Options) error

func (*BaseDatabaseImplement) InsertAll

func (s *BaseDatabaseImplement) InsertAll(data any) error

func (*BaseDatabaseImplement) InsertAllWithCtx

func (s *BaseDatabaseImplement) InsertAllWithCtx(ctx context.Context, data any) error

func (*BaseDatabaseImplement) InsertOne

func (s *BaseDatabaseImplement) InsertOne(data any) error

func (*BaseDatabaseImplement) InsertOneWithCtx

func (s *BaseDatabaseImplement) InsertOneWithCtx(ctx context.Context, data any) error

func (*BaseDatabaseImplement) Migrate

func (s *BaseDatabaseImplement) Migrate(models ...any) error

func (*BaseDatabaseImplement) ParseDatabaseOptions

func (s *BaseDatabaseImplement) ParseDatabaseOptions(db *sql.DB, opts Options)

func (*BaseDatabaseImplement) ParseLoggerOptions

func (s *BaseDatabaseImplement) ParseLoggerOptions(opts Options)

func (*BaseDatabaseImplement) PickAll

func (s *BaseDatabaseImplement) PickAll(receiver any, length int, query string, args ...any) error

func (*BaseDatabaseImplement) PickAllWithCtx

func (s *BaseDatabaseImplement) PickAllWithCtx(ctx context.Context, receiver any, length int, query string, args ...any) error

func (*BaseDatabaseImplement) PickOne

func (s *BaseDatabaseImplement) PickOne(receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) PickOneWithCtx

func (s *BaseDatabaseImplement) PickOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error

func (*BaseDatabaseImplement) QueryRaw

func (s *BaseDatabaseImplement) QueryRaw(receiver any, sql string, args ...any) error

func (*BaseDatabaseImplement) QueryRawWithCtx

func (s *BaseDatabaseImplement) QueryRawWithCtx(ctx context.Context, receiver any, sql string, args ...any) error

func (*BaseDatabaseImplement) SetDriverName added in v1.2.7

func (s *BaseDatabaseImplement) SetDriverName(name string)

func (*BaseDatabaseImplement) SetLogger added in v1.2.10

func (s *BaseDatabaseImplement) SetLogger(logger logger.Logger)

func (*BaseDatabaseImplement) SetRandCommand

func (s *BaseDatabaseImplement) SetRandCommand(command string)

func (*BaseDatabaseImplement) UpdateAll

func (s *BaseDatabaseImplement) UpdateAll(data any, query string, args ...any) error

func (*BaseDatabaseImplement) UpdateAllWithCtx

func (s *BaseDatabaseImplement) UpdateAllWithCtx(ctx context.Context, data any, query string, args ...any) error

func (*BaseDatabaseImplement) UpdateOne

func (s *BaseDatabaseImplement) UpdateOne(data any, query string, args ...any) error

func (*BaseDatabaseImplement) UpdateOneWithCtx

func (s *BaseDatabaseImplement) UpdateOneWithCtx(ctx context.Context, data any, query string, args ...any) error

type BaseExtMethodGroup added in v1.2.7

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

func (*BaseExtMethodGroup) DriverName added in v1.2.7

func (b *BaseExtMethodGroup) DriverName() string

func (*BaseExtMethodGroup) Exec added in v1.2.7

func (b *BaseExtMethodGroup) Exec(cmd func(db *gorm.DB) *gorm.DB) error

func (*BaseExtMethodGroup) ExecCtx added in v1.2.7

func (b *BaseExtMethodGroup) ExecCtx(ctx context.Context, cmd func(db *gorm.DB) *gorm.DB) error

func (*BaseExtMethodGroup) GetGorm added in v1.2.7

func (b *BaseExtMethodGroup) GetGorm() *gorm.DB

func (*BaseExtMethodGroup) Transaction added in v1.2.10

func (b *BaseExtMethodGroup) Transaction(cmd func(tx *gorm.DB) error) error

func (*BaseExtMethodGroup) TransactionCtx added in v1.2.10

func (b *BaseExtMethodGroup) TransactionCtx(ctx context.Context, cmd func(tx *gorm.DB) error) error

type Database

type Database interface {
	Init(options Options) error
	Migrate(models ...any) error
	Has(table string, query string, args ...any) (exist bool, err error)
	Count(table string, query string, args ...any) (count int64, err error)
	GetOne(receiver any, query string, args ...any) error
	GetAll(receiver any, query string, args ...any) error
	GetPage(receiver any, offset, limit int, query string, args ...any) error
	PickOne(receiver any, query string, args ...any) error
	PickAll(receiver any, length int, query string, args ...any) error
	InsertOne(data any) error
	InsertAll(data any) error
	UpdateOne(data any, query string, args ...any) error
	UpdateAll(data any, query string, args ...any) error
	DeleteOne(query string, args ...any) error
	DeleteAll(query string, args ...any) error
	ExecRaw(sql string, args ...any) error
	QueryRaw(receiver any, sql string, args ...any) error
	HasWithCtx(ctx context.Context, table string, query string, args ...any) (exist bool, err error)
	CountWithCtx(ctx context.Context, table string, query string, args ...any) (count int64, err error)
	GetOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error
	GetAllWithCtx(ctx context.Context, receiver any, query string, args ...any) error
	PickOneWithCtx(ctx context.Context, receiver any, query string, args ...any) error
	PickAllWithCtx(ctx context.Context, receiver any, length int, query string, args ...any) error
	InsertOneWithCtx(ctx context.Context, data any) error
	InsertAllWithCtx(ctx context.Context, data any) error
	UpdateOneWithCtx(ctx context.Context, data any, query string, args ...any) error
	UpdateAllWithCtx(ctx context.Context, data any, query string, args ...any) error
	DeleteOneWithCtx(ctx context.Context, query string, args ...any) error
	DeleteAllWithCtx(ctx context.Context, query string, args ...any) error
	ExecRawWithCtx(ctx context.Context, sql string, args ...any) error
	QueryRawWithCtx(ctx context.Context, receiver any, sql string, args ...any) error
	ExtMethods() ExtMethods
	SetLogger(logger logger.Logger)
}

type ExecuteSqlError added in v1.2.10

type ExecuteSqlError struct {
	Sql           string `json:"sql"`
	ErrorOccurred error  `json:"error"`
}

func (*ExecuteSqlError) Error added in v1.2.10

func (err *ExecuteSqlError) Error() string

type ExtMethods added in v1.2.7

type ExtMethods interface {
	DriverName() string
	GetGorm() *gorm.DB
	Exec(cmd func(db *gorm.DB) *gorm.DB) error
	ExecCtx(ctx context.Context, cmd func(db *gorm.DB) *gorm.DB) error
	Transaction(cmd func(tx *gorm.DB) error) error
	TransactionCtx(ctx context.Context, cmd func(tx *gorm.DB) error) error
}

type Extended added in v1.2.7

type Extended interface {
	Database
	ExtensionName() string
}

type Extension added in v1.2.7

type Extension[extended Extended] interface {
	InitializeExtension(base Database) extended
}

type Options

type Options struct {
	DataSource string
	MaxIdle    int
	MaxOpen    int
	MaxLife    time.Duration
	Timeout    time.Duration
	Stdout     string
	Stderr     string
	DebugLog   bool
}

type TemplateFormatError added in v1.2.10

type TemplateFormatError struct {
	Template string `json:"template"`
}

func (*TemplateFormatError) Error added in v1.2.10

func (err *TemplateFormatError) Error() string

Directories

Path Synopsis
extension
orm

Jump to

Keyboard shortcuts

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