orm

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 12 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 注册数据库

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

func (da *DA[T]) GetModel() (md T)

GetModel 获取内置模型

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

func (da *DA[T]) SetModel(md T)

SetModel 设置内置模型

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 IModel

type IModel interface {
	// xorm 的接口要求
	TableName() string

	// 本服务的接口要求
	DatabaseAlias() string

	// 以下接口要求为 github.com/amoeba-inc/easyjson 生成
	FieldMarks() []string
}

type Model

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

Model orm基础模型 与定制的 easyjson 搭配使用

func (*Model) FieldMarks

func (m *Model) FieldMarks() []string

FieldMarks 列出所有已赋值的字段名称列表

func (*Model) HasFieldMark

func (m *Model) HasFieldMark(fieldName string) bool

HasFieldMark 指定的字段名称是否已赋值

func (*Model) HasPropertyMark

func (m *Model) HasPropertyMark(markKey string) bool

HasPropertyMark 指定的字段名称是否已赋值

func (*Model) PropertyMarks

func (m *Model) PropertyMarks() []string

PropertyMarks 列出所有已赋值的属性名称列表

func (*Model) ResetFieldMark

func (m *Model) ResetFieldMark()

ResetFieldMark 重置所有字段的赋值标识为:false,字段内容并不会清空

func (*Model) ResetMark

func (m *Model) ResetMark()

ResetMark 重置所有字段、属于的赋值标识为:false,字段内容并不会清空

func (*Model) ResetPropertyMark

func (m *Model) ResetPropertyMark()

ResetPropertyMark 重置所有字段的赋值标识为:false,字段内容并不会清空

func (*Model) SetFieldMark

func (m *Model) SetFieldMark(fieldName string, isMark ...bool)

SetFieldMark 设置字段的赋值标识,isMark不传时,默认:true

func (*Model) SetPropertyMark

func (m *Model) SetPropertyMark(markKey string, isMark ...bool)

SetPropertyMark 设置字段的赋值标识,isMark不传时,默认:true

type ModelList

type ModelList[T any] struct {
	Page      int   `json:"page"`
	PageSize  int   `json:"pageSize"`
	PageCount int   `json:"pageCount"`
	Total     int64 `json:"total"`
	Items     []T   `json:"items"`
}

ModelList 通用模型列表

Jump to

Keyboard shortcuts

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