gmorm

package module
v0.0.0-...-ce97080 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-mysql-orm

golang orm framework

Documentation

Index

Constants

View Source
const (
	SELECT optionType // 查询
	UPDATE            // 修改
	DELETE            // 删除
	INSERT            // 新增
)

Variables

This section is empty.

Functions

func ErrorF

func ErrorF(format string, params ...any) error

func KeyTo

func KeyTo(key string) string

KeyTo 字段key优化

func ObjTagMap

func ObjTagMap(obj any, tag string) (map[string]interface{}, error)

ObjTagMap 结构体对象依据tag获取数据转map 当结构体中存在tag字段但无值情况给nil值 当tag字段类型为slice或map时将会进行json处理 当tag字段类型为其他类型时,需要在对应类型上添加Value方法去重构它,该程序将会依据Value方法获取其字段值 此方法将作为sqlx的Named模式将结构体转换为map使用

Types

type Clause

type Clause struct {
	Condition []string      // 语句(条件语句或设置语句) xxx = ? | xxx in (?) ...
	Params    []interface{} // 值
	End       bool          // 是否结束当前子句
}

Clause 子句 单个块的子句为 and 当存在多子句时,使用 or 拼接

func NewClause

func NewClause() Clause

NewClause 创建子句

type ColObj

type ColObj interface {
	Value() any
}

ColObj 字段值接口

type Engine

type Engine[T TbObj] struct {
	*GmOrm // DB组件块
	// contains filtered or unexported fields
}

Engine 引擎

func NewEngine

func NewEngine[T TbObj](g *GmOrm, t T) *Engine[T]

func (*Engine[T]) And

func (e *Engine[T]) And(condition string, vals ...interface{}) *Engine[T]

And

func (*Engine[T]) Clear

func (e *Engine[T]) Clear() *Engine[T]

Clear 重置

func (*Engine[T]) CloseClause

func (e *Engine[T]) CloseClause() *Engine[T]

CloseClause 关闭当前子句 用于进入到下一条 or 子句 或 结束当前or子句操作

func (*Engine[T]) Count

func (se *Engine[T]) Count() *Engine[T]

func (*Engine[T]) Delete

func (e *Engine[T]) Delete() *Engine[T]

Delete delete语句生成器 此方法执行时如果delete语句没有where条件将会抛出错误

func (*Engine[T]) Exec

func (e *Engine[T]) Exec() (sql.Result, error)

func (*Engine[T]) Find

func (e *Engine[T]) Find(obj any, columns ...string) error

func (*Engine[T]) Get

func (e *Engine[T]) Get(obj any, columns ...string) error

func (*Engine[T]) InsertNamed

func (e *Engine[T]) InsertNamed(tag string, objs ...T) *Engine[T]

Insert insert named语句生成器(允许生成批量插入) 此方法依据tag获取字段名称,并将依据此tag的值设定为列名进行插入语句生成

func (*Engine[T]) Or

func (e *Engine[T]) Or(condition string, vals ...interface{}) *Engine[T]

Or

func (*Engine[T]) Select

func (e *Engine[T]) Select(columns ...string) *Engine[T]

Select select语句生成器

func (*Engine[T]) Set

func (e *Engine[T]) Set(condition string, vals ...interface{}) *Engine[T]

Set

func (*Engine[T]) Update

func (e *Engine[T]) Update() *Engine[T]

Update update语句生成器 此方法执行时如果update语句没有where条件将会抛出错误

func (*Engine[T]) Value

func (e *Engine[T]) Value() (string, []interface{}, error)

func (*Engine[T]) Where

func (e *Engine[T]) Where(condition string, vals ...interface{}) *Engine[T]

Where

type GmOrm

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

GmOrm 核心ORM对象

func New

func New(db *sqlx.DB) *GmOrm

New

func (*GmOrm) GetEngine

func (g *GmOrm) GetEngine(t TbObj) *Engine[TbObj]

Register 注册表对象

type StringObj

type StringObj interface {
	String() any
}

type TbObj

type TbObj interface {
	TableName() string // 返回表名
}

TbObj 表对象接口

Jump to

Keyboard shortcuts

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