dbutil

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)

Functions

func Create

func Create[T any](log zerolog.Logger, con sq.BaseRunner, table string, req T, returning []string, partitionFunc PartitionFunc) (id int, err error)

func CreateMany

func CreateMany[T any](log zerolog.Logger, con sq.BaseRunner, table string, reqs []T, returning []string, partitionFunc PartitionFunc) (ids []int, err error)

func Delete

func Delete(log zerolog.Logger, con sq.BaseRunner, table string, where []string) (err error)

func ExistM

func ExistM(log zerolog.Logger, con *sqlx.DB, table string, where map[string]any) (ret bool, err error)

func ExistS

func ExistS(log zerolog.Logger, con *sqlx.DB, table string, where []string) (bool, error)

func GetM

func GetM[T any](log zerolog.Logger, con *sqlx.DB, table string, where map[string]any) (ret T, err error)

func GetManyM

func GetManyM[T any](log zerolog.Logger, con *sqlx.DB, table string, where map[string]any, orderby []string) (ret []T, err error)

func GetManyS

func GetManyS[T any](log zerolog.Logger, con *sqlx.DB, table string, where []string, orderby []string) (ret []T, err error)

func GetS

func GetS[T any](log zerolog.Logger, con *sqlx.DB, table string, where []string) (ret T, err error)

func ListFlex

func ListFlex[T any](log zerolog.Logger, con *sqlx.DB, page util.Page, table string, selects, where, orderby []string) (ret []T, total int, err error)

func ListM

func ListM[T any](log zerolog.Logger, con *sqlx.DB, page util.Page, table string, where map[string]any, orderBy []string) (ret []T, total int, err error)

func ListS

func ListS[T any](log zerolog.Logger, con *sqlx.DB, page util.Page, table string, wheres, order []string) (ret []T, total int, err error)

func NewDB

func NewDB(dbName, url string, dcfg DBConfig) *sqlx.DB

func SetActive

func SetActive(log zerolog.Logger, con *sqlx.DB, table string, id int, active bool) (err error)

func SetDelete

func SetDelete(log zerolog.Logger, con *sqlx.DB, table string, id int, del bool) (err error)

func UpdateM

func UpdateM(log zerolog.Logger, con sq.BaseRunner, table string, where map[string]any, sets map[string]any) (err error)

func UpdateMore

func UpdateMore(log zerolog.Logger, con sq.BaseRunner, table string, ids []int, sets map[string]any) (err error)

func UpdateS

func UpdateS(log zerolog.Logger, con sq.BaseRunner, table string, where []string, sets map[string]any) (err error)

func UpdateWithID

func UpdateWithID(log zerolog.Logger, con sq.BaseRunner, table string, id int, sets map[string]any) (err error)

func UpsertManyNoPartition

func UpsertManyNoPartition[T any](log zerolog.Logger, con sq.BaseRunner, table string, pks []string, tag string, toInsert []T, mergeStrategy map[string]string) (err error)

Types

type DBConfig

type DBConfig struct {
	MaxOpenConn     int
	MaxIdelConn     int
	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration
}

func (*DBConfig) SetDefault

func (d *DBConfig) SetDefault()

type PartitionFunc

type PartitionFunc func(runner sq.BaseRunner, table string) error

Jump to

Keyboard shortcuts

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