Documentation ¶
Index ¶
- func Disable(mds ...IModel)
- func Init(confs []*Config) (err error)
- func Register(md IModel)
- func RegisterWithValidator(validate *validator.Validate)
- type Builder
- func (b *Builder) And(cond builder.Cond) *Builder
- func (b *Builder) Asc(colNames ...string)
- func (b *Builder) CrossJoin(joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) Delete(conds ...builder.Cond) *Builder
- func (b *Builder) Desc(colNames ...string)
- func (b *Builder) From(table interface{}) *Builder
- func (b *Builder) FullJoin(joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) GroupBy(groupBy string)
- func (b *Builder) InnerJoin(joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) Insert(eq builder.Eq) *Builder
- func (b *Builder) Into(table interface{}) *Builder
- func (b *Builder) Join(joinType string, joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) LeftJoin(joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) Or(cond builder.Cond) *Builder
- func (b *Builder) OrderBy(orderBy string)
- func (b *Builder) RightJoin(joinTable interface{}, joinCond interface{}) *Builder
- func (b *Builder) Select(cols ...string) *Builder
- func (b *Builder) Update(updates ...builder.Cond) *Builder
- func (b *Builder) Where(cond builder.Cond) *Builder
- type Config
- type DA
- func (da *DA[T]) Asc(colNames ...string) *xorm.Session
- func (da *DA[T]) Desc(colNames ...string) *xorm.Session
- func (da *DA[T]) GetModelList(page, pageSize int, itemsOpt ...[]T) (ml *ModelList[T], err error)
- func (da *DA[T]) GetModelListByBuilder(builder *Builder, page, pageSize int, itemsOpt ...[]T) (ml *ModelList[T], err error)
- func (da *DA[T]) GetModelListByBuilderWithPageOffset(builder *Builder, page, pageSize, pageOffset int, itemsOpt ...[]T) (ml *ModelList[T], err error)
- func (da *DA[T]) GetModelListWithPageOffset(page, pageSize, pageOffset int, itemsOpt ...[]T) (ml *ModelList[T], err error)
- func (da *DA[T]) GroupBy(keys string) *xorm.Session
- func (da *DA[T]) OrderBy(order string) *xorm.Session
- func (da *DA[T]) UpdateByBuilder(builder *Builder) (rows int64, err error)
- func (da *DA[T]) UpdateByModel(imdOpt ...IModel) (int64, error)
- type Engine
- type Field
- func (f *Field[T]) FieldName() string
- func (f *Field[T]) FromDB(body []byte) error
- func (f *Field[T]) IsSetVal() bool
- func (f *Field[T]) JSONName() string
- func (f *Field[T]) MarshalJSON() ([]byte, error)
- func (f *Field[T]) SetVal(valOpt ...T)
- func (f *Field[T]) ToDB() ([]byte, error)
- func (f *Field[T]) UnmarshalJSON(body []byte) error
- func (f *Field[T]) UnsetVal(valOpt ...T)
- func (f *Field[T]) Val() T
- func (f Field[T]) ValidatorValue() (value any, isSetVal bool)
- type FieldType
- type FieldTypeFloat
- type FieldTypeInt
- type FieldTypeUint
- type IModel
- type Model
- type ModelList
- type ValidatorValuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterWithValidator ¶ added in v1.2.0
func RegisterWithValidator(validate *validator.Validate)
RegisterWithValidator 注册到 Validator
Types ¶
type Builder ¶
func NewBuilder ¶
func NewBuilder() *Builder
func NewMySQLBuilder ¶
func NewMySQLBuilder() *Builder
type Config ¶
type Config struct { Alias string `json:"alias"` Type string `json:"type"` Server string `json:"server"` Port int `json:"port"` Database string `json:"database"` User string `json:"user"` Password string `json:"password"` IsShowSQL bool `json:"isShowSQL"` // 是否打印 SQL 语句 LogLevel string `json:"logLevel"` // logger 日志级别,支持:debug、info、warn、error、off,默认:off // contains filtered or unexported fields }
Config 数据库配置
type DA ¶
DA 数据库操作对象
func (*DA[T]) GetModelList ¶
GetModelList 获取列表数据,items可指定接收查询结果的结构对象
func (*DA[T]) GetModelListByBuilder ¶
func (da *DA[T]) GetModelListByBuilder(builder *Builder, page, pageSize int, itemsOpt ...[]T) (ml *ModelList[T], err error)
GetModelListByBuilder 获取列表数据,通过Builder构建查询,items可指定接收查询结果的结构对象
func (*DA[T]) GetModelListByBuilderWithPageOffset ¶
func (da *DA[T]) GetModelListByBuilderWithPageOffset(builder *Builder, page, pageSize, pageOffset int, itemsOpt ...[]T) (ml *ModelList[T], err error)
GetModelListByBuilderWithPageOffset 获取列表数据,通过Builder构建查询,items可指定接收查询结果的结构对象
func (*DA[T]) GetModelListWithPageOffset ¶
func (da *DA[T]) GetModelListWithPageOffset(page, pageSize, pageOffset int, itemsOpt ...[]T) (ml *ModelList[T], err error)
GetModelListWithPageOffset 获取列表数据,items可指定接收查询结果的结构对象
func (*DA[T]) UpdateByBuilder ¶
UpdateByBuilder 使用Builder进行更新
type Field ¶ added in v1.2.0
type Field[T FieldType] struct { // contains filtered or unexported fields }
Field 字段
func NewField ¶ added in v1.2.0
func NewField[T FieldType](model *Model, fieldName, jsonName string, isJSONTagString bool) *Field[T]
NewField 创建新的字段
func (*Field[T]) MarshalJSON ¶ added in v1.2.0
MarshalJSON 实现 json.Marshaler 接口
func (*Field[T]) SetVal ¶ added in v1.2.0
func (f *Field[T]) SetVal(valOpt ...T)
SetVal 设定赋值,不指定 valOpt 时仅为设置赋值状态
func (*Field[T]) UnmarshalJSON ¶ added in v1.2.0
UnmarshalJSON 实现 json.Unmarshaler 接口
func (*Field[T]) UnsetVal ¶ added in v1.2.0
func (f *Field[T]) UnsetVal(valOpt ...T)
UnsetVal 取消赋值,不指定 valOpt 时仅为取消赋值状态
func (Field[T]) ValidatorValue ¶ added in v1.2.0
ValidatorValue 实现 ValidatorValuer 接口
type FieldType ¶ added in v1.2.0
type FieldType interface { ~string | ~bool | FieldTypeInt | FieldTypeUint | FieldTypeFloat }
FieldType 字段类型约束
type FieldTypeFloat ¶ added in v1.2.0
FieldTypeFloat 字段类型约束 - 浮点
type FieldTypeInt ¶ added in v1.2.0
FieldTypeInt 字段类型约束 - 整型
type FieldTypeUint ¶ added in v1.2.0
FieldTypeUint 字段类型约束 - 无符号整型
type IModel ¶
type IModel interface { // 本服务的 db 接口要求 DatabaseAlias() string FieldNames(isSetValOpt ...bool) []string // xorm 的接口要求 TableName() string }
基础数据模型接口
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model 基础数据模型
func (*Model) FieldNames ¶ added in v1.2.0
FieldNames 获取字段列表,可指定是否赋值
type ModelList ¶
type ModelList[T IModel] struct { Page int `json:"page"` PageSize int `json:"pageSize"` PageCount int `json:"pageCount"` Total int64 `json:"total"` Items []T `json:"items"` }
ModelList 通用模型列表
type ValidatorValuer ¶ added in v1.2.0
ValidatorValuer 自定义 validate 字段类型接口