Documentation
¶
Index ¶
- Variables
- func GetTrans(ctx context.Context, fn func(ctx context.Context, tx *DBContext) error) error
- func GetTransResult(ctx context.Context, ...) (interface{}, error)
- func ReplaceGlobal(dbo *DBO)
- type BaseDA
- func (s BaseDA) Count(ctx context.Context, condition Conditions, values interface{}) (int, error)
- func (s BaseDA) CountTx(ctx context.Context, db *DBContext, condition Conditions, value interface{}) (int, error)
- func (s BaseDA) Get(ctx context.Context, id interface{}, value interface{}) error
- func (s BaseDA) GetTx(ctx context.Context, db *DBContext, id interface{}, value interface{}) error
- func (s BaseDA) Insert(ctx context.Context, value interface{}) (interface{}, error)
- func (s BaseDA) InsertInBatches(ctx context.Context, value interface{}, batchSize int) (interface{}, error)
- func (s BaseDA) InsertInBatchesTx(ctx context.Context, db *DBContext, value interface{}, batchSize int) (interface{}, error)
- func (s BaseDA) InsertTx(ctx context.Context, db *DBContext, value interface{}) (interface{}, error)
- func (s BaseDA) Page(ctx context.Context, condition Conditions, values interface{}) (int, error)
- func (s BaseDA) PageTx(ctx context.Context, db *DBContext, condition Conditions, values interface{}) (int, error)
- func (s BaseDA) Query(ctx context.Context, condition Conditions, values interface{}) error
- func (s BaseDA) QueryRawSQL(ctx context.Context, values interface{}, sql string, parameters ...interface{}) error
- func (s BaseDA) QueryRawSQLTx(ctx context.Context, db *DBContext, values interface{}, sql string, ...) error
- func (s BaseDA) QueryTx(ctx context.Context, db *DBContext, condition Conditions, values interface{}) error
- func (s BaseDA) Save(ctx context.Context, value interface{}) error
- func (s BaseDA) SaveTx(ctx context.Context, db *DBContext, value interface{}) error
- func (s BaseDA) Update(ctx context.Context, value interface{}) (int64, error)
- func (s BaseDA) UpdateTx(ctx context.Context, db *DBContext, value interface{}) (int64, error)
- type Conditions
- type Config
- type DBContext
- type DBO
- type DBType
- type DataAccesser
- type Geter
- type Inserter
- type LogLevel
- type NullInts
- type NullStrings
- type Option
- type Pager
- type Querier
- type Saver
- type Updater
Constants ¶
This section is empty.
Variables ¶
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") )
var NoPager = Pager{Page: 0, PageSize: 0}
NoPager do not paging
Functions ¶
Types ¶
type BaseDA ¶
type BaseDA struct{}
func (BaseDA) InsertInBatches ¶
func (s BaseDA) InsertInBatches(ctx context.Context, value interface{}, batchSize int) (interface{}, error)
InsertInBatches Insert records in batch. visit https://gorm.io/docs/create.html for detail
func (BaseDA) InsertInBatchesTx ¶
func (s BaseDA) InsertInBatchesTx(ctx context.Context, db *DBContext, value interface{}, batchSize int) (interface{}, error)
InsertInBatchesTx Insert records in batch with context. visit https://gorm.io/docs/create.html for detail
func (BaseDA) Query ¶
func (s BaseDA) Query(ctx context.Context, condition Conditions, values interface{}) error
func (BaseDA) QueryRawSQL ¶
func (BaseDA) QueryRawSQLTx ¶
type Conditions ¶
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 DataAccesser ¶
DataAccesser data access contract
type Inserter ¶
type Inserter interface {
Insert(context.Context, interface{}) (interface{}, error)
InsertTx(context.Context, *DBContext, interface{}) (interface{}, error)
InsertInBatches(context.Context, interface{}, int) (interface{}, error)
InsertInBatchesTx(context.Context, *DBContext, interface{}, int) (interface{}, error)
}
type NullInts ¶
NullInts nullable ints
func (NullInts) SQLPlaceHolder ¶
SQLPlaceHolder generate sql place holder
func (NullInts) ToInterfaceSlice ¶
func (s NullInts) ToInterfaceSlice() []interface{}
ToInterfaceSlice values to interface() slice
type NullStrings ¶
NullStrings nullable strings
func (NullStrings) SQLPlaceHolder ¶
func (s NullStrings) SQLPlaceHolder() string
SQLPlaceHolder generate sql place holder
func (NullStrings) ToInterfaceSlice ¶
func (s NullStrings) ToInterfaceSlice() []interface{}
ToInterfaceSlice values to interface() slice
type Option ¶
type Option func(*Config)
Option dbo option
func WithConnectionString ¶
func WithDBType ¶
func WithLogLevel ¶
func WithMaxIdleConns ¶
func WithMaxOpenConns ¶
func WithTransactionTimeout ¶
type Pager ¶
Pager paging setting
type Querier ¶
type Querier interface {
Query(context.Context, Conditions, interface{}) error
QueryTx(context.Context, *DBContext, Conditions, interface{}) error
Count(context.Context, Conditions, interface{}) (int, error)
CountTx(context.Context, *DBContext, Conditions, interface{}) (int, error)
Page(context.Context, Conditions, interface{}) (int, error)
PageTx(context.Context, *DBContext, Conditions, interface{}) (int, error)
QueryRawSQL(context.Context, interface{}, string, ...interface{}) error
QueryRawSQLTx(context.Context, *DBContext, interface{}, string, ...interface{}) error
}