Documentation
¶
Index ¶
- Variables
- func Count[T any](ctx context.Context, condition QueryCondition) (int64, error)
- func CountTx[T any](ctx context.Context, db *DBContext, condition QueryCondition) (int64, error)
- func Get[T any](ctx context.Context, id any) (value T, err error)
- func GetTrans(ctx context.Context, fn func(ctx context.Context, tx *DBContext) error) error
- func GetTransResult[T any](ctx context.Context, fn func(ctx context.Context, tx *DBContext) (T, error)) (T, error)
- func GetTx[T any](ctx context.Context, db *DBContext, id any) (T, error)
- func Insert[T any](ctx context.Context, value T) (int64, error)
- func InsertInBatches[T any](ctx context.Context, value []T, batchSize int) (int64, error)
- func InsertInBatchesTx[T any](ctx context.Context, db *DBContext, value []T, batchSize int) (int64, error)
- func InsertTx[T any](ctx context.Context, db *DBContext, value T) (int64, error)
- func Page[T any](ctx context.Context, condition QueryCondition) (int64, []T, error)
- func PageTx[T any](ctx context.Context, db *DBContext, condition QueryCondition) (int64, []T, error)
- func Query[T any](ctx context.Context, condition QueryCondition) ([]T, error)
- func QueryMap[T Entity](ctx context.Context, condition QueryCondition) (map[string]T, error)
- func QueryTx[T any](ctx context.Context, db *DBContext, condition QueryCondition) ([]T, error)
- func ReplaceGlobal(dbo *DBO)
- func Save[T any](ctx context.Context, value T) error
- func SaveTx[T any](ctx context.Context, db *DBContext, value T) error
- func Update[T any](ctx context.Context, value T) (int64, error)
- func UpdateTx[T any](ctx context.Context, db *DBContext, value T) (int64, error)
- func Var[T any](v T) *T
- type Config
- type DBContext
- type DBO
- type DBType
- type Entity
- type LogLevel
- type NullBool
- type NullBools
- type NullInt
- type NullInt64
- type NullInt64s
- type NullInts
- type NullString
- type NullStrings
- type NullTime
- type NullTimes
- type Option
- type OrderByCondition
- type Pager
- type PagerCondition
- type QueryCondition
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrRecordNotFound record not found ErrRecordNotFound = errors.New("record not found") // ErrDuplicateRecord duplicate record ErrDuplicateRecord = errors.New("duplicate record") // ErrExceededLimit exceeded limit ErrExceededLimit = errors.New("exceeded limit") )
View Source
var NoPager = Pager{Page: 0, PageSize: 0}
NoPager do not paging
Functions ¶
func GetTransResult ¶
func GetTransResult[T any](ctx context.Context, fn func(ctx context.Context, tx *DBContext) (T, error)) (T, error)
GetTransResult begin a transaction, get result of callback
func InsertInBatches ¶
InsertInBatches Insert records in batch. visit https://gorm.io/docs/create.html for detail
func InsertInBatchesTx ¶
func InsertInBatchesTx[T any](ctx context.Context, db *DBContext, value []T, batchSize int) (int64, error)
InsertInBatchesTx Insert records in batch with context. visit https://gorm.io/docs/create.html for detail
Types ¶
type Config ¶
type Config struct { ConnectionString string MaxOpenConns int MaxIdleConns int ConnMaxLifetime time.Duration ConnMaxIdleTime time.Duration DBType DBType TransactionTimeout time.Duration LogLevel LogLevel SlowThreshold time.Duration }
Config dbo config
type DBContext ¶
DBContext db with context
func (*DBContext) GetTableName ¶
GetTableName get database table name of value
func (*DBContext) ResetCondition ¶
ResetCondition reset session query conditions
type DBO ¶
type DBO struct {
// contains filtered or unexported fields
}
DBO database operator
func NewWithConfig ¶
NewWithConfig create new database operator
type NullInt64s ¶
type NullString ¶
type NullStrings ¶
type Option ¶
type Option func(*Config)
Option dbo option
func WithConnectionString ¶
func WithDBType ¶
func WithLogLevel ¶
func WithMaxIdleConns ¶
func WithMaxOpenConns ¶
func WithTransactionTimeout ¶
type OrderByCondition ¶
type OrderByCondition interface {
GetOrderBy() string
}
type Pager ¶
Pager paging setting
type PagerCondition ¶
type PagerCondition interface {
GetPager() *Pager
}
type QueryCondition ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.