Documentation ¶
Index ¶
- Constants
- func AppName(name string) utils.OptionFunc[useOption]
- func CheckGormErrorFn(tx *gorm.DB) func() error
- func Clauses(clauses ...clause.Expression) utils.OptionFunc[mysqlDALOption]
- func Construct(ctx context.Context, confs map[string]*Conf, opts ...utils.OptionExtender) func()
- func JsonMarshalFn(tx *gorm.DB, obj, field any) func() error
- func JsonUnmarshalFn(tx *gorm.DB, obj, field any) func() error
- func Scan[T any, TS ~[]*T](ctx context.Context, cb func(TS) bool, opts ...utils.OptionExtender) (err error)
- func ScanBatch(batch int) utils.OptionFunc[scanOption]
- func ScanCursor(cursorWhere any, cursorColumns []string, cursors ...any) utils.OptionFunc[scanOption]
- func ScanDAL[T any, TS ~[]*T](dal DalInterface[T, TS]) utils.OptionFunc[scanOptionGeneric[T, TS]]
- func ScanLimit(limit int) utils.OptionFunc[scanOption]
- func ScanLog(log log.Loggable) utils.OptionFunc[scanOption]
- func ScanOrder(order any) utils.OptionFunc[scanOption]
- func ScanUse(dbName string) utils.OptionFunc[scanOption]
- func ScanWhere(where any, sqlAndArguments ...any) utils.OptionFunc[scanOption]
- func SetCtxGormDB(ctx context.Context, db *DB) context.Context
- func TxUse(name string) utils.OptionFunc[txOption]
- func Unscoped() utils.OptionFunc[mysqlDALOption]
- func WithinTx(ctx context.Context, cb func(ctx context.Context) (err error), ...) error
- func WriteDB() utils.OptionFunc[mysqlDALOption]
- type Business
- type BusinessSoftDeleted
- func (b *BusinessSoftDeleted) BeforeCreate(tx *gorm.DB) (err error)
- func (b *BusinessSoftDeleted) BeforeCreateFn(tx *gorm.DB) func() error
- func (b *BusinessSoftDeleted) BizCreateTime() time.Time
- func (b *BusinessSoftDeleted) BizModifyTime() time.Time
- func (b *BusinessSoftDeleted) Clone() *BusinessSoftDeleted
- func (b *BusinessSoftDeleted) Equals(o *BusinessSoftDeleted) bool
- type Conf
- type DB
- type DalInterface
- type Data
- type DataSoftDeleted
- type Instance
Constants ¶
View Source
const ( ErrDuplicatedName utils.Error = "duplicated database name" ErrDatabaseNotFound utils.Error = "not found database to use" )
Variables ¶
This section is empty.
Functions ¶
func AppName ¶
func AppName(name string) utils.OptionFunc[useOption]
func CheckGormErrorFn ¶
func Clauses ¶
func Clauses(clauses ...clause.Expression) utils.OptionFunc[mysqlDALOption]
func ScanBatch ¶
func ScanBatch(batch int) utils.OptionFunc[scanOption]
func ScanCursor ¶
func ScanCursor(cursorWhere any, cursorColumns []string, cursors ...any) utils.OptionFunc[scanOption]
func ScanDAL ¶
func ScanDAL[T any, TS ~[]*T](dal DalInterface[T, TS]) utils.OptionFunc[scanOptionGeneric[T, TS]]
func ScanLimit ¶
func ScanLimit(limit int) utils.OptionFunc[scanOption]
func ScanOrder ¶
func ScanOrder(order any) utils.OptionFunc[scanOption]
func ScanUse ¶
func ScanUse(dbName string) utils.OptionFunc[scanOption]
func TxUse ¶
func TxUse(name string) utils.OptionFunc[txOption]
func Unscoped ¶
func Unscoped() utils.OptionFunc[mysqlDALOption]
func WithinTx ¶
func WithinTx(ctx context.Context, cb func(ctx context.Context) (err error), opts ...utils.OptionExtender) error
WithinTx 事务内执行 DAL 操作
func WriteDB ¶
func WriteDB() utils.OptionFunc[mysqlDALOption]
Types ¶
type Business ¶
type Business struct { Data UUID uuid.UUID `gorm:"column:uuid;type:varchar(36);uniqueIndex" json:"uuid"` BizCreateTimeMs int64 `gorm:"column:biz_create_time;type:bigint" json:"bizCreateTime"` BizModifyTimeMs int64 `gorm:"column:biz_modify_time;type:bigint" json:"bizModifyTime"` }
func (*Business) BizCreateTime ¶
func (*Business) BizModifyTime ¶
type BusinessSoftDeleted ¶
type BusinessSoftDeleted struct { DataSoftDeleted UUID uuid.UUID `gorm:"column:uuid;type:varchar(36);uniqueIndex:uniq_uuid" json:"uuid"` BizCreateTimeMs int64 `gorm:"column:biz_create_time;type:bigint" json:"bizCreateTime"` BizModifyTimeMs int64 `gorm:"column:biz_modify_time;type:bigint" json:"bizModifyTime"` }
func (*BusinessSoftDeleted) BeforeCreate ¶
func (b *BusinessSoftDeleted) BeforeCreate(tx *gorm.DB) (err error)
func (*BusinessSoftDeleted) BeforeCreateFn ¶
func (b *BusinessSoftDeleted) BeforeCreateFn(tx *gorm.DB) func() error
func (*BusinessSoftDeleted) BizCreateTime ¶
func (b *BusinessSoftDeleted) BizCreateTime() time.Time
func (*BusinessSoftDeleted) BizModifyTime ¶
func (b *BusinessSoftDeleted) BizModifyTime() time.Time
func (*BusinessSoftDeleted) Clone ¶
func (b *BusinessSoftDeleted) Clone() *BusinessSoftDeleted
func (*BusinessSoftDeleted) Equals ¶
func (b *BusinessSoftDeleted) Equals(o *BusinessSoftDeleted) bool
type Conf ¶
type Conf struct { orm.Option `yaml:",inline" json:",inline" toml:",inline"` AutoIncrementIncrement int64 `yaml:"auto_increment_increment" json:"auto_increment_increment" toml:"auto_increment_increment"` Sharding []shardingConf `yaml:"sharding" json:"sharding" toml:"sharding"` EnableLogger bool `yaml:"enable_logger" json:"enable_logger" toml:"enable_logger" default:"false"` LoggerConfig struct { Logger string `yaml:"logger" json:"logger" toml:"logger" default:"github.com/wfusion/gofusion/log/customlogger.gormLogger"` LogInstance string `yaml:"log_instance" json:"log_instance" toml:"log_instance" default:"default"` LogLevel string `yaml:"log_level" json:"log_level" toml:"log_level"` SlowThreshold string `yaml:"slow_threshold" json:"slow_threshold" toml:"slow_threshold"` } `yaml:"logger_config" json:"logger_config" toml:"logger_config"` }
Conf nolint: revive // struct tag too long issue
type DalInterface ¶
type DalInterface[T any, TS ~[]*T] interface { Query(ctx context.Context, query any, args ...any) (TS, error) QueryFirst(ctx context.Context, query any, args ...any) (*T, error) QueryLast(ctx context.Context, query any, args ...any) (*T, error) QueryInBatches(ctx context.Context, batchSize int, fc func(tx *DB, batch int, found TS) error, query any, args ...any) error Count(ctx context.Context, query any, args ...any) (int64, error) Pluck(ctx context.Context, column string, dest any, query any, args ...any) error Take(ctx context.Context, dest any, conds ...any) error InsertOne(ctx context.Context, mod *T, opts ...utils.OptionExtender) error InsertInBatches(ctx context.Context, modList TS, batchSize int, opts ...utils.OptionExtender) error Save(ctx context.Context, mod any, opts ...utils.OptionExtender) error Update(ctx context.Context, column string, value any, query any, args ...any) (int64, error) Updates(ctx context.Context, columns map[string]any, query any, args ...any) (int64, error) Delete(ctx context.Context, query any, args ...any) (int64, error) FirstOrCreate(ctx context.Context, mod *T, conds ...any) (int64, error) Transaction(ctx context.Context, fc func(tx context.Context) error, opts ...utils.OptionExtender) error ReadDB(ctx context.Context) *gorm.DB WriteDB(ctx context.Context) *gorm.DB SetCtxReadDB(src context.Context) (dst context.Context) SetCtxWriteDB(src context.Context) (dst context.Context) Model() *T ModelSlice() TS IgnoreErr(err error) error CanIgnore(err error) bool ShardingByValues(ctx context.Context, src []map[string]any) (dst map[string][]map[string]any, err error) ShardingIDGen(ctx context.Context) (id uint64, err error) ShardingIDListGen(ctx context.Context, amount int) (idList []uint64, err error) ShardingByModelList(ctx context.Context, src TS) (dst map[string]TS, err error) }
DalInterface nolint: revive // interface issue
func NewDAL ¶
func NewDAL[T any, TS ~[]*T](readDBName, writeDBName string, opts ...utils.OptionExtender) DalInterface[T, TS]
type Data ¶
type Data struct { ID uint64 `gorm:"column:id;primary_key;autoIncrement" json:"id"` CreateTimeMs int64 `gorm:"column:create_time;type:bigint;autoCreateTime:milli" json:"createTime"` ModifyTimeMs int64 `gorm:"column:modify_time;type:bigint;autoUpdateTime:milli" json:"modifyTime"` }
func (*Data) CreateTime ¶
func (*Data) ModifyTime ¶
type DataSoftDeleted ¶
type DataSoftDeleted struct { ID uint64 `gorm:"column:id;primary_key;autoIncrement" json:"id"` CreateTimeMs int64 `gorm:"column:create_time;type:bigint;autoCreateTime:milli" json:"createTime"` ModifyTimeMs int64 `gorm:"column:modify_time;type:bigint;autoUpdateTime:milli" json:"modifyTime"` DeleteTimeMs softdelete.Timestamp `gorm:"column:delete_time;type:bigint;index:,composite:soft_delete" json:"deleteTime"` Deleted softdelete.Deleted `gorm:"column:deleted;index:,composite:soft_delete;default:false" json:"deleted"` }
DataSoftDeleted nolint: revive // struct tag too long issue
func (*DataSoftDeleted) Clone ¶
func (d *DataSoftDeleted) Clone() *DataSoftDeleted
func (*DataSoftDeleted) CreateTime ¶
func (d *DataSoftDeleted) CreateTime() time.Time
func (*DataSoftDeleted) DeleteTime ¶
func (d *DataSoftDeleted) DeleteTime() *time.Time
func (*DataSoftDeleted) Equals ¶
func (d *DataSoftDeleted) Equals(o *DataSoftDeleted) bool
func (*DataSoftDeleted) ModifyTime ¶
func (d *DataSoftDeleted) ModifyTime() time.Time
Source Files ¶
Click to show internal directories.
Click to hide internal directories.