orm

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable(mds ...IModel)

Disable 关闭数据库(不创建连接)

func Init

func Init(confs []*Config) (err error)

Init 初始化

func Register

func Register(md IModel)

Register 注册数据库

func RegisterWithValidator added in v1.2.0

func RegisterWithValidator(validate *validator.Validate)

RegisterWithValidator 注册到 Validator

Types

type Builder

type Builder struct {
	*builder.Builder
	OrderByStr string
	GroupByStr string
}

func NewBuilder

func NewBuilder() *Builder

func NewMySQLBuilder

func NewMySQLBuilder() *Builder

func (*Builder) And

func (b *Builder) And(cond builder.Cond) *Builder

func (*Builder) Asc

func (b *Builder) Asc(colNames ...string)

func (*Builder) CrossJoin

func (b *Builder) CrossJoin(joinTable interface{}, joinCond interface{}) *Builder

CrossJoin 重写Builder.CrossJoin方法,支持model传入

func (*Builder) Delete

func (b *Builder) Delete(conds ...builder.Cond) *Builder

Delete 重写Builder.Delete方法,总是创建新对象

func (*Builder) Desc

func (b *Builder) Desc(colNames ...string)

func (*Builder) From

func (b *Builder) From(table interface{}) *Builder

From 重写Builder.From方法,支持model传入

func (*Builder) FullJoin

func (b *Builder) FullJoin(joinTable interface{}, joinCond interface{}) *Builder

FullJoin 重写Builder.FullJoin方法,支持model传入

func (*Builder) GroupBy

func (b *Builder) GroupBy(groupBy string)

func (*Builder) InnerJoin

func (b *Builder) InnerJoin(joinTable interface{}, joinCond interface{}) *Builder

InnerJoin 重写Builder.InnerJoin方法,支持model传入

func (*Builder) Insert

func (b *Builder) Insert(eq builder.Eq) *Builder

Insert 重写Builder.Insert方法,总是创建新对象

func (*Builder) Into

func (b *Builder) Into(table interface{}) *Builder

Into 重写Builder.Into方法,支持model传入

func (*Builder) Join

func (b *Builder) Join(joinType string, joinTable interface{}, joinCond interface{}) *Builder

Join 重写Builder.Join方法,支持model传入

func (*Builder) LeftJoin

func (b *Builder) LeftJoin(joinTable interface{}, joinCond interface{}) *Builder

LeftJoin 重写Builder.LeftJoin方法,支持model传入

func (*Builder) Or

func (b *Builder) Or(cond builder.Cond) *Builder

func (*Builder) OrderBy

func (b *Builder) OrderBy(orderBy string)

func (*Builder) RightJoin

func (b *Builder) RightJoin(joinTable interface{}, joinCond interface{}) *Builder

RightJoin 重写Builder.RightJoin方法,支持model传入

func (*Builder) Select

func (b *Builder) Select(cols ...string) *Builder

Select 重写Builder.Select方法,总是创建新对象

func (*Builder) Update

func (b *Builder) Update(updates ...builder.Cond) *Builder

Update 重写Builder.Update方法,总是创建新对象

func (*Builder) Where

func (b *Builder) Where(cond builder.Cond) *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 数据库配置

func (*Config) Init

func (conf *Config) Init() (err error)

Init 初始化

type DA

type DA[T IModel] struct {
	*xorm.Session
	// contains filtered or unexported fields
}

DA 数据库操作对象

func NewDA

func NewDA[T IModel](md T) (da *DA[T], err error)

NewDA 创建数据库操作对象

func (*DA[T]) Asc

func (da *DA[T]) Asc(colNames ...string) *xorm.Session

Asc 升序

func (*DA[T]) Desc

func (da *DA[T]) Desc(colNames ...string) *xorm.Session

Desc 降序

func (*DA[T]) GetModelList

func (da *DA[T]) GetModelList(page, pageSize int, itemsOpt ...[]T) (ml *ModelList[T], err error)

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]) GroupBy

func (da *DA[T]) GroupBy(keys string) *xorm.Session

GroupBy 分组

func (*DA[T]) OrderBy

func (da *DA[T]) OrderBy(order string) *xorm.Session

OrderBy 排序

func (*DA[T]) UpdateByBuilder

func (da *DA[T]) UpdateByBuilder(builder *Builder) (rows int64, err error)

UpdateByBuilder 使用Builder进行更新

func (*DA[T]) UpdateByModel

func (da *DA[T]) UpdateByModel(imdOpt ...IModel) (int64, error)

UpdateByModel 通过模型更新数据,没传参数时使用内置模型对象

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 数据库引擎管理对象

type Field added in v1.2.0

type Field[T FieldType] struct {
	// contains filtered or unexported fields
}

Field 字段

func (*Field[T]) FieldName added in v1.2.0

func (f *Field[T]) FieldName() string

FieldName 字段名

func (*Field[T]) FromDB added in v1.2.0

func (f *Field[T]) FromDB(body []byte) error

FromDB 实现

func (*Field[T]) IsSetVal added in v1.2.0

func (f *Field[T]) IsSetVal() bool

IsSetVal 是否赋值

func (*Field[T]) JSONName added in v1.2.0

func (f *Field[T]) JSONName() string

JSONName 成员名

func (*Field[T]) MarshalJSON added in v1.2.0

func (f *Field[T]) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*Field[T]) Reset added in v1.2.5

func (f *Field[T]) Reset(model *Model, fieldName, jsonName string, isJSONTagString bool)

Reset 重设配置

func (*Field[T]) SetVal added in v1.2.0

func (f *Field[T]) SetVal(valOpt ...T)

SetVal 设定赋值,不指定 valOpt 时仅为设置赋值状态

func (*Field[T]) ToDB added in v1.2.0

func (f *Field[T]) ToDB() ([]byte, error)

ToDB 实现

func (*Field[T]) UnmarshalJSON added in v1.2.0

func (f *Field[T]) UnmarshalJSON(body []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

func (*Field[T]) UnsetVal added in v1.2.0

func (f *Field[T]) UnsetVal(valOpt ...T)

UnsetVal 取消赋值,不指定 valOpt 时仅为取消赋值状态

func (*Field[T]) Val added in v1.2.0

func (f *Field[T]) Val() T

Val 值

func (Field[T]) ValidatorValue added in v1.2.0

func (f Field[T]) ValidatorValue() (value any, isSetVal bool)

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

type FieldTypeFloat interface {
	~float32 | ~float64
}

FieldTypeFloat 字段类型约束 - 浮点

type FieldTypeInt added in v1.2.0

type FieldTypeInt interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

FieldTypeInt 字段类型约束 - 整型

type FieldTypeUint added in v1.2.0

type FieldTypeUint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

FieldTypeUint 字段类型约束 - 无符号整型

type IField added in v1.2.5

type IField interface {
	IsSetVal() bool
	FieldName() string
}

基础字段接口

type IModel

type IModel interface {
	// 本服务的 db 接口要求
	DatabaseAlias() string
	FieldNames(isSetValOpt ...bool) []string
	FieldReset()

	// xorm 的接口要求
	TableName() string
}

基础数据模型接口

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model 基础数据模型

func (*Model) FieldNames added in v1.2.0

func (m *Model) FieldNames(isSetValOpt ...bool) (names []string)

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

type ValidatorValuer interface {
	ValidatorValue() (value any, isSetVal bool)
}

ValidatorValuer 自定义 validate 字段类型接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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