gom

package module
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 10 Imported by: 1

README

gom

gom - An Easy ORM library for Golang

golang Go Report Card GitHub GoDoc

基本介绍&特性

gom是一个基于golang语言的关系型数据库ORM框架(CRUD工具库,支持事务)

目前最新版本为v2.1.4,于2023年12月30 修复发布。修复问题详见下方的迭代注记

当前支持的数据库类型仅为 mysql及其衍生品 mariadb

数据库类型支持自定义扩展(参考factory/mysql/mysql.go)

gom是goroutine安全的(自认为的安全)

稳定性及性能

和原生查询接近的查询性能(甚至更好),增删改性能略比原生差一些。

单元测试覆盖率90%,测试比较充分,但是仍不排除还有漏网之BUG

但是逻辑覆盖率没法做到百分之百,如使用过程中如出现问题,欢迎邮件我:kmlixh@foxmail.com或者直接给PR

本地测试的结果详见迭代注记

快速入门

使用go mod的情况下:

require github.com/kmlixh/gom/v2 v2.1.4
require github.com/go-sql-driver/mysql v1.6.0 // indirect,

或者

go get github.com/kmlixh/gom/v2@v2.1.4
一个简单的CRUD示例
package main

import (
	"github.com/google/uuid"
	"github.com/kmlixh/gom/v2"
	_ "github.com/kmlixh/gom/v2/factory/mysql"
	"time"
)

var dsn = "remote:remote123@tcp(10.0.1.5)/test?charset=utf8&loc=Asia%2FShanghai&parseTime=true"

type User struct {
	Id       int64     `json:"id" gom:"@,id"`
	Pwd      string    `json:"pwd" gom:"pwd"`
	Email    string    `json:"email" gom:"email"`
	Valid    int       `json:"valid" gom:"valid"`
	NickName string    `json:"nicks" gom:"nick_name"`
	RegDate  time.Time `json:"reg_date" gom:"reg_date"`
}

var db *gom.DB

func init() {
	//Create DB ,Global
	var er error
	db, er = gom.Open("mysql", dsn, true)
	if er != nil {
		panic(er)
	}
}

func main() {
	var users []User
	//Query
	db.Where(gom.Cnd("name", gom.Eq, "kmlixh")).Page(0, 100).Select(&users)
	//Update
	temp := users[0]
	temp.NickName = uuid.New().String()
	temp.RegDate = time.Now()
	db.Update(temp)
	//Delete
	db.Delete(users[1])
	tt := User{
		Pwd:      "123213",
		Email:    "1@test.com",
		Valid:    1,
		NickName: uuid.New().String(),
		RegDate:  time.Now(),
	}
	db.Insert(tt)

}


DB结构体具有的方法(函数)如下:
RawDb() 获取原生的sql.Db对象
Table(tableName string) 设置表名
Raw() *sql.Db 获取go底层的db对象
OrderBy()排序
CleanOrders清除排序
OrderByAsc
OrderByDesc
Where2
Where
Clone
Page
Count
Sum
Select
SelectByModel
First
Insert
Delete
Update
ExecuteRaw
ExecuteStatement
Begin
IsInTransaction
Commit
Rollback
DoTransaction
CleanDb

迭代注记

2023年12月30日 修复查询迭代是sql必须存在于一行的bug
2022年9月3日 修复In只有一个参数是sql异常的mysql报错;版本更新为v2.1.1
2022年9月2日 修复MapToCondition 没有处理简单类型数组的bug;版本更新为2.1.0
2022年9月1日 修复某些情况下,In条件解析数组参数异常的bug;版本更新为2.10
2022年7月21日 修复复杂条件解析逻辑混乱的bug;版本更新为2.0.9(你猜的没错,2.0.8也是修复这个bug,没修好)
2022年7月20日 修复Count和Sum时条件无效的bug,版本更新为v2.0.7(中间两个版本改了什么忘记了,懒得去🍵git)
2022年4月17日 修复bug,更新版本为v2.0.4
修复查询条件关系错误的bug;
修复查询条件初始化为空时附加属性不合理的bug;
新增CndEmpty()方法,用于创建空的Condition对象,此方法与CndRaw("")等价
2022年4月15日 01:56:50 v2.0.0发布
v2.0
代码几乎全部重构,你大概可以认为这是一个全新的东西,API全变了(不过也没事,之前的版本也就我一个人在用^_^自嗨锅)
代码测试覆盖率93.0%(相关的测试覆盖率结果可以看test_cover.html以及cover.out)

此处略作测试摘录证明一下我真的做过测试了:

go test  -cover -coverprofile=cover.out -coverpkg=./...

init DB.............
PASS
coverage: 93.0% of statements in ./...
ok      github.com/kmlixh/gom   9.112s

然后Benchmark也顺手写了粗糙的两个:

go test -bench="." -benchmem -run="TestNothing" 
   
init DB.............
goos: darwin
goarch: amd64
pkg: github.com/kmlixh/gom
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkBaseSelect-16                       138           8654269 ns/op          662728 B/op      10397 allocs/op
BenchmarkBaseSelectGom-16                    122           8936071 ns/op          679967 B/op      14406 allocs/op
BenchmarkDB_InsertSingle-16                   74          19828957 ns/op            5403 B/op        109 allocs/op
BenchmarkRaw_InsertSingle-16                  66          17606781 ns/op            1175 B/op         22 allocs/op
PASS
ok      github.com/kmlixh/gom   6.176s

查询的性能比原始查询是差了一些的,这个需要承认

2019年6月19日 17:44:18
v1.1.2
修复CreateSingleTable的一些bug
2019年6月15日 08:18:25
v1.1.1
修复一些bug;
增加NotIn模式
2019年5月15日 09:18:06
v1.0.8
截止1.0.8又修复了若干bug,详细请看commit
2019年4月30日 11:15:38
1.修复了大量的bug;(具体可以看提交记录)
2.改造了数据获取的方式,从原来的固定格式转换,变成了接近于数据库底层的Scanner模式的性能
3.优化了自定义类型的查询和存储
2017年6月22日 12:54:36
1.修复若干bug(具体修复哪些bug记不清了 ^_^)
2.修复Update,Insert,Delete方法传入不定参数时的bug(无法解析,或者解析不正确,使用递归解决)
3.修复Condition为空的情况下会莫名注入一个“where”进入sql语句的bug 
4.Db对象增加了一个Count函数,故名思议,用来做count的
2017年6月18日22:47:53
1.修复无法使用事务的bug
2.修改了数据库操作的一些基础逻辑,每次操作前都会进行Prepare操作,以提高一些“性能”
3.为了修复上面的bug,修改了整体的gom.Db结构

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool

Functions

func ArrayIntersect added in v2.0.2

func ArrayIntersect(slice1, slice2 []string) []string

func ArrayOf added in v2.0.2

func ArrayOf(i ...interface{}) []interface{}

func ByteArrayScan added in v2.0.2

func ByteArrayScan(src interface{}) (interface{}, error)

func CamelToSnakeString added in v2.0.2

func CamelToSnakeString(s string) string

func Float32Scan added in v2.0.2

func Float32Scan(src interface{}) (interface{}, error)

func IntScan added in v2.0.2

func IntScan(src interface{}) (interface{}, error)

func Register added in v2.0.2

func Register(name string, inter SqlFactory)

func ScannerResultToStruct added in v2.0.2

func ScannerResultToStruct(t reflect.Type, scanners []interface{}, columnNames []string, columnIdxMap map[string]int) reflect.Value

func SliceToGroupSlice added in v2.0.2

func SliceToGroupSlice(vs interface{}) map[string][]interface{}

func StructToMap added in v2.0.2

func StructToMap(vs interface{}, columns ...string) (map[string]interface{}, []string, error)

func UnZipSlice added in v2.0.2

func UnZipSlice(vs interface{}) []interface{}

Types

type CndImpl added in v2.0.2

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

func (*CndImpl) And added in v2.0.2

func (c *CndImpl) And(field string, operation Operation, value ...interface{}) Condition

func (*CndImpl) And2 added in v2.0.2

func (c *CndImpl) And2(condition Condition) Condition

func (*CndImpl) And3 added in v2.0.2

func (c *CndImpl) And3(rawExpresssion string, values ...interface{}) Condition

func (*CndImpl) And3Bool added in v2.0.2

func (c *CndImpl) And3Bool(b bool, rawExpresssion string, values ...interface{}) Condition

func (*CndImpl) AndBool added in v2.0.2

func (c *CndImpl) AndBool(b bool, field string, operation Operation, values ...interface{}) Condition

func (*CndImpl) Eq added in v2.0.2

func (c *CndImpl) Eq(field string, values interface{}) Condition

func (*CndImpl) EqBool added in v2.0.2

func (c *CndImpl) EqBool(b bool, field string, values interface{}) Condition

func (*CndImpl) Field added in v2.0.2

func (c *CndImpl) Field() string

func (*CndImpl) Ge added in v2.0.2

func (c *CndImpl) Ge(field string, values interface{}) Condition

func (*CndImpl) GeBool added in v2.0.2

func (c *CndImpl) GeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) Gt added in v2.0.2

func (c *CndImpl) Gt(field string, values interface{}) Condition

func (*CndImpl) GtBool added in v2.0.2

func (c *CndImpl) GtBool(b bool, field string, values interface{}) Condition

func (*CndImpl) HasSubConditions added in v2.0.2

func (c *CndImpl) HasSubConditions() bool

func (*CndImpl) In added in v2.0.2

func (c *CndImpl) In(field string, values ...interface{}) Condition

func (*CndImpl) InBool added in v2.0.2

func (c *CndImpl) InBool(b bool, field string, values ...interface{}) Condition

func (*CndImpl) IsNotNull added in v2.0.2

func (c *CndImpl) IsNotNull(field string) Condition

func (*CndImpl) IsNotNullBool added in v2.0.2

func (c *CndImpl) IsNotNullBool(b bool, filed string) Condition

func (*CndImpl) IsNull added in v2.0.2

func (c *CndImpl) IsNull(filed string) Condition

func (*CndImpl) IsNullBool added in v2.0.2

func (c *CndImpl) IsNullBool(b bool, field string) Condition

func (*CndImpl) Items added in v2.0.2

func (c *CndImpl) Items() []Condition

func (*CndImpl) Le added in v2.0.2

func (c *CndImpl) Le(field string, values interface{}) Condition

func (*CndImpl) LeBool added in v2.0.2

func (c *CndImpl) LeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) Like added in v2.0.2

func (c *CndImpl) Like(field string, values interface{}) Condition

func (*CndImpl) LikeBool added in v2.0.2

func (c *CndImpl) LikeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) LikeIgnoreEnd added in v2.0.2

func (c *CndImpl) LikeIgnoreEnd(field string, values interface{}) Condition

func (*CndImpl) LikeIgnoreEndBool added in v2.0.2

func (c *CndImpl) LikeIgnoreEndBool(b bool, field string, values interface{}) Condition

func (*CndImpl) LikeIgnoreStart added in v2.0.2

func (c *CndImpl) LikeIgnoreStart(field string, values interface{}) Condition

func (*CndImpl) LikeIgnoreStartBool added in v2.0.2

func (c *CndImpl) LikeIgnoreStartBool(b bool, field string, values interface{}) Condition

func (*CndImpl) Linker added in v2.0.2

func (c *CndImpl) Linker() Linker

func (*CndImpl) Lt added in v2.0.2

func (c *CndImpl) Lt(field string, values interface{}) Condition

func (*CndImpl) LtBool added in v2.0.2

func (c *CndImpl) LtBool(b bool, field string, values interface{}) Condition

func (*CndImpl) NotEq added in v2.0.2

func (c *CndImpl) NotEq(field string, values interface{}) Condition

func (*CndImpl) NotEqBool added in v2.0.2

func (c *CndImpl) NotEqBool(b bool, field string, values interface{}) Condition

func (*CndImpl) NotIn added in v2.0.2

func (c *CndImpl) NotIn(field string, values ...interface{}) Condition

func (*CndImpl) NotInBool added in v2.0.2

func (c *CndImpl) NotInBool(b bool, field string, values ...interface{}) Condition

func (*CndImpl) Operation added in v2.0.2

func (c *CndImpl) Operation() Operation

func (*CndImpl) Or added in v2.0.2

func (c *CndImpl) Or(field string, operation Operation, values ...interface{}) Condition

func (*CndImpl) Or2 added in v2.0.2

func (c *CndImpl) Or2(condition Condition) Condition

func (*CndImpl) Or3 added in v2.0.2

func (c *CndImpl) Or3(rawExpresssion string, values ...interface{}) Condition

func (*CndImpl) Or3Bool added in v2.0.2

func (c *CndImpl) Or3Bool(b bool, rawExpresssion string, values ...interface{}) Condition

func (*CndImpl) OrBool added in v2.0.2

func (c *CndImpl) OrBool(b bool, field string, operation Operation, values ...interface{}) Condition

func (*CndImpl) OrEq added in v2.0.2

func (c *CndImpl) OrEq(field string, values interface{}) Condition

func (*CndImpl) OrEqBool added in v2.0.2

func (c *CndImpl) OrEqBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrGe added in v2.0.2

func (c *CndImpl) OrGe(field string, values interface{}) Condition

func (*CndImpl) OrGeBool added in v2.0.2

func (c *CndImpl) OrGeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrGt added in v2.0.2

func (c *CndImpl) OrGt(field string, values interface{}) Condition

func (*CndImpl) OrGtBool added in v2.0.2

func (c *CndImpl) OrGtBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrIn added in v2.0.2

func (c *CndImpl) OrIn(field string, values ...interface{}) Condition

func (*CndImpl) OrInBool added in v2.0.2

func (c *CndImpl) OrInBool(b bool, field string, values ...interface{}) Condition

func (*CndImpl) OrIsNotNull added in v2.0.2

func (c *CndImpl) OrIsNotNull(field string) Condition

func (*CndImpl) OrIsNotNullBool added in v2.0.2

func (c *CndImpl) OrIsNotNullBool(b bool, field string) Condition

func (*CndImpl) OrIsNull added in v2.0.2

func (c *CndImpl) OrIsNull(field string) Condition

func (*CndImpl) OrIsNullBool added in v2.0.2

func (c *CndImpl) OrIsNullBool(b bool, field string) Condition

func (*CndImpl) OrLe added in v2.0.2

func (c *CndImpl) OrLe(field string, values interface{}) Condition

func (*CndImpl) OrLeBool added in v2.0.2

func (c *CndImpl) OrLeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrLike added in v2.0.2

func (c *CndImpl) OrLike(field string, values interface{}) Condition

func (*CndImpl) OrLikeBool added in v2.0.2

func (c *CndImpl) OrLikeBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrLikeIgnoreEnd added in v2.0.2

func (c *CndImpl) OrLikeIgnoreEnd(field string, values interface{}) Condition

func (*CndImpl) OrLikeIgnoreEndBool added in v2.0.2

func (c *CndImpl) OrLikeIgnoreEndBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrLikeIgnoreStart added in v2.0.2

func (c *CndImpl) OrLikeIgnoreStart(field string, values interface{}) Condition

func (*CndImpl) OrLikeIgnoreStartBool added in v2.0.2

func (c *CndImpl) OrLikeIgnoreStartBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrLt added in v2.0.2

func (c *CndImpl) OrLt(field string, values interface{}) Condition

func (*CndImpl) OrLtBool added in v2.0.2

func (c *CndImpl) OrLtBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrNotEq added in v2.0.2

func (c *CndImpl) OrNotEq(field string, values interface{}) Condition

func (*CndImpl) OrNotEqBool added in v2.0.2

func (c *CndImpl) OrNotEqBool(b bool, field string, values interface{}) Condition

func (*CndImpl) OrNotIn added in v2.0.2

func (c *CndImpl) OrNotIn(field string, values ...interface{}) Condition

func (*CndImpl) OrNotInBool added in v2.0.2

func (c *CndImpl) OrNotInBool(b bool, field string, values ...interface{}) Condition

func (*CndImpl) PayLoads added in v2.0.9

func (c *CndImpl) PayLoads() int64

func (*CndImpl) RawExpression added in v2.0.2

func (c *CndImpl) RawExpression() string

func (*CndImpl) SetValues added in v2.0.2

func (c *CndImpl) SetValues(values []interface{})

func (*CndImpl) Values added in v2.0.2

func (c *CndImpl) Values() []interface{}

type Column added in v2.0.2

type Column struct {
	Data        interface{}
	ColumnName  string
	FieldName   string
	Primary     bool
	PrimaryAuto bool //If Primary Key Auto Generate Or2 Not
}

type Condition added in v2.0.2

type Condition interface {
	PayLoads() int64 //有效荷载,说明当前条件及其链式条件共有多少有多少个条件
	Linker() Linker
	Field() string
	Operation() Operation
	Values() []interface{}
	SetValues([]interface{})
	Items() []Condition
	HasSubConditions() bool
	RawExpression() string
	Eq(field string, values interface{}) Condition
	EqBool(b bool, field string, value interface{}) Condition
	OrEq(field string, value interface{}) Condition
	OrEqBool(b bool, field string, value interface{}) Condition
	Ge(field string, value interface{}) Condition
	GeBool(b bool, field string, value interface{}) Condition
	OrGe(field string, value interface{}) Condition
	OrGeBool(b bool, field string, value interface{}) Condition
	Gt(field string, values interface{}) Condition
	GtBool(b bool, field string, values interface{}) Condition
	OrGt(field string, values interface{}) Condition
	OrGtBool(b bool, field string, values interface{}) Condition
	Le(field string, values interface{}) Condition
	LeBool(b bool, field string, values interface{}) Condition
	OrLe(field string, values interface{}) Condition
	OrLeBool(b bool, field string, values interface{}) Condition
	Lt(field string, values interface{}) Condition
	LtBool(b bool, field string, values interface{}) Condition
	OrLt(field string, values interface{}) Condition
	OrLtBool(b bool, field string, values interface{}) Condition
	NotEq(field string, values interface{}) Condition
	NotEqBool(b bool, field string, values interface{}) Condition
	OrNotEq(field string, values interface{}) Condition
	OrNotEqBool(b bool, field string, values interface{}) Condition
	In(field string, values ...interface{}) Condition
	InBool(b bool, field string, values ...interface{}) Condition
	OrIn(field string, values ...interface{}) Condition
	OrInBool(b bool, field string, values ...interface{}) Condition
	NotIn(field string, values ...interface{}) Condition
	NotInBool(b bool, field string, values ...interface{}) Condition
	OrNotIn(field string, values ...interface{}) Condition
	OrNotInBool(b bool, field string, values ...interface{}) Condition
	Like(field string, values interface{}) Condition
	LikeBool(b bool, field string, values interface{}) Condition
	OrLike(field string, values interface{}) Condition
	OrLikeBool(b bool, field string, values interface{}) Condition
	LikeIgnoreStart(field string, values interface{}) Condition
	LikeIgnoreStartBool(b bool, field string, values interface{}) Condition
	OrLikeIgnoreStart(field string, values interface{}) Condition
	OrLikeIgnoreStartBool(b bool, field string, values interface{}) Condition
	LikeIgnoreEnd(field string, values interface{}) Condition
	LikeIgnoreEndBool(b bool, field string, values interface{}) Condition
	OrLikeIgnoreEnd(field string, values interface{}) Condition
	OrLikeIgnoreEndBool(b bool, field string, values interface{}) Condition
	IsNull(filed string) Condition
	IsNullBool(b bool, field string) Condition
	IsNotNull(field string) Condition
	IsNotNullBool(b bool, field string) Condition
	OrIsNull(filed string) Condition
	OrIsNullBool(b bool, field string) Condition
	OrIsNotNull(field string) Condition
	OrIsNotNullBool(b bool, field string) Condition
	And(field string, operation Operation, value ...interface{}) Condition
	AndBool(b bool, field string, operation Operation, value ...interface{}) Condition
	And2(condition Condition) Condition
	And3(rawExpresssion string, values ...interface{}) Condition
	And3Bool(b bool, rawExpresssion string, values ...interface{}) Condition
	Or(field string, operation Operation, value ...interface{}) Condition
	OrBool(b bool, field string, operation Operation, value ...interface{}) Condition
	Or2(condition Condition) Condition
	Or3(rawExpresssion string, values ...interface{}) Condition
	Or3Bool(b bool, rawExpresssion string, values ...interface{}) Condition
}

func Cnd added in v2.0.3

func Cnd(field string, operation Operation, values ...interface{}) Condition

func CndEmpty added in v2.0.3

func CndEmpty() Condition

func CndEq added in v2.0.3

func CndEq(field string, value interface{}) Condition

func CndFull added in v2.0.3

func CndFull(linker Linker, field string, operation Operation, rawExpression string, values ...interface{}) Condition

func CndGe added in v2.0.3

func CndGe(field string, value interface{}) Condition

func CndGt added in v2.0.3

func CndGt(field string, value interface{}) Condition

func CndIn added in v2.0.3

func CndIn(field string, values ...interface{}) Condition

func CndIsNotNull added in v2.0.3

func CndIsNotNull(field string) Condition

func CndIsNull added in v2.0.3

func CndIsNull(field string) Condition

func CndLe added in v2.0.3

func CndLe(field string, value interface{}) Condition

func CndLike added in v2.0.3

func CndLike(field string, value interface{}) Condition

func CndLikeIgnoreEnd added in v2.0.3

func CndLikeIgnoreEnd(field string, value interface{}) Condition

func CndLikeIgnoreStart added in v2.0.3

func CndLikeIgnoreStart(field string, value interface{}) Condition

func CndLt added in v2.0.3

func CndLt(field string, value interface{}) Condition

func CndNotEq added in v2.0.3

func CndNotEq(field string, value interface{}) Condition

func CndNotIn added in v2.0.3

func CndNotIn(field string, values ...interface{}) Condition

func CndRaw added in v2.0.3

func CndRaw(rawExpresssion string, values ...interface{}) Condition

func MapToCondition added in v2.0.2

func MapToCondition(maps map[string]interface{}) Condition

func StructToCondition added in v2.0.2

func StructToCondition(vs interface{}, columns ...string) Condition

type CountResult added in v2.0.2

type CountResult struct {
	Count int64
	Error error
}

type DB

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

func Open

func Open(driverName string, dsn string, debugs bool) (*DB, error)

func OpenWithConfig

func OpenWithConfig(driverName string, dsn string, maxOpen int, maxIdle int, debugs bool) (*DB, error)

func (*DB) Begin

func (db *DB) Begin() error

func (*DB) CleanDb

func (db *DB) CleanDb() *DB

func (*DB) CleanOrders

func (db *DB) CleanOrders() *DB

func (DB) Clone

func (db DB) Clone() DB

func (*DB) Commit

func (db *DB) Commit()

func (DB) Count

func (db DB) Count(columnName string) (int64, error)

func (DB) Delete

func (db DB) Delete(vs ...interface{}) (int64, int64, error)

func (DB) DoTransaction

func (db DB) DoTransaction(work TransactionWork) (interface{}, error)

func (DB) ExecuteRaw

func (db DB) ExecuteRaw() (int64, int64, error)

func (DB) ExecuteStatement

func (db DB) ExecuteStatement(statement string, data ...interface{}) (sql.Result, error)

func (DB) Factory added in v2.0.2

func (db DB) Factory() SqlFactory

func (DB) First

func (db DB) First(vs interface{}) (interface{}, error)

func (DB) GetCnd added in v2.0.2

func (db DB) GetCnd() Condition

func (DB) GetOrderBys added in v2.0.2

func (db DB) GetOrderBys() []OrderBy

func (DB) GetPage added in v2.0.2

func (db DB) GetPage() (int64, int64)

func (DB) Insert

func (db DB) Insert(v interface{}, columns ...string) (int64, int64, error)

func (DB) IsInTransaction

func (db DB) IsInTransaction() bool

func (*DB) OrderBy

func (db *DB) OrderBy(field string, t OrderType) *DB

func (*DB) OrderByAsc

func (db *DB) OrderByAsc(field string) *DB

func (*DB) OrderByDesc

func (db *DB) OrderByDesc(field string) *DB

func (*DB) OrderBys added in v2.1.3

func (db *DB) OrderBys(orderbys []OrderBy) *DB

func (*DB) Page

func (db *DB) Page(page int64, pageSize int64) *DB

func (*DB) Raw

func (db *DB) Raw(sql string, datas ...interface{}) *DB

func (DB) RawDb

func (db DB) RawDb() *sql.DB

func (*DB) Rollback

func (db *DB) Rollback()

func (DB) Select

func (db DB) Select(vs interface{}, columns ...string) (interface{}, error)

func (DB) SelectByModel

func (db DB) SelectByModel(model TableModel) (interface{}, error)

func (DB) Sum

func (db DB) Sum(columnName string) (int64, error)

func (DB) Table

func (db DB) Table(table string) DB

func (DB) Update

func (db DB) Update(v interface{}, columns ...string) (int64, int64, error)

func (*DB) Where

func (db *DB) Where(cnd Condition) *DB

func (*DB) Where2

func (db *DB) Where2(sql string, patches ...interface{}) *DB

type DefaultModel added in v2.0.2

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

func (DefaultModel) Clone added in v2.0.2

func (d DefaultModel) Clone() TableModel

func (DefaultModel) ColumnDataMap added in v2.0.2

func (d DefaultModel) ColumnDataMap() map[string]interface{}

func (DefaultModel) Columns added in v2.0.2

func (d DefaultModel) Columns() []string

func (DefaultModel) Condition added in v2.0.2

func (d DefaultModel) Condition() Condition

func (DefaultModel) GetScanners added in v2.0.2

func (d DefaultModel) GetScanners(columns []string) ([]interface{}, int, error)

func (DefaultModel) OrderBys added in v2.0.2

func (d DefaultModel) OrderBys() []OrderBy

func (DefaultModel) Page added in v2.0.2

func (d DefaultModel) Page() PageInfo

func (DefaultModel) PrimaryAuto added in v2.0.2

func (d DefaultModel) PrimaryAuto() bool

func (DefaultModel) Scan added in v2.0.2

func (d DefaultModel) Scan(rows *sql.Rows) (interface{}, error)

func (*DefaultModel) SetColumns added in v2.0.2

func (d *DefaultModel) SetColumns(columns []string) error

func (*DefaultModel) SetCondition added in v2.0.2

func (d *DefaultModel) SetCondition(c Condition) error

func (*DefaultModel) SetData added in v2.0.2

func (d *DefaultModel) SetData(_ interface{}, valueOfData reflect.Value, isStruct bool, isPtr bool, isSlice bool)

func (*DefaultModel) SetOrderBys added in v2.0.2

func (d *DefaultModel) SetOrderBys(orders []OrderBy) error

func (*DefaultModel) SetPage added in v2.0.2

func (d *DefaultModel) SetPage(p PageInfo) error

func (*DefaultModel) SetTable added in v2.0.2

func (d *DefaultModel) SetTable(tableName string)

func (DefaultModel) Table added in v2.0.2

func (d DefaultModel) Table() string

type DefaultStruct added in v2.0.2

type DefaultStruct struct {
}

type EmptyScanner added in v2.0.2

type EmptyScanner struct {
	ColName string
}
var EMPTY_SCANNER *EmptyScanner = &EmptyScanner{}

func (EmptyScanner) Scan added in v2.0.2

func (e EmptyScanner) Scan(_ interface{}) error

func (EmptyScanner) Value added in v2.0.2

func (e EmptyScanner) Value() (driver.Value, error)

type GenerateSQLFunc added in v2.0.2

type GenerateSQLFunc func(model ...TableModel) []SqlProto

type IScanner added in v2.0.2

type IScanner interface {
	Value() (driver.Value, error)
	Scan(src interface{}) error
}

func GetIScannerOfColumn added in v2.0.2

func GetIScannerOfColumn(col interface{}) IScanner

type ITableName added in v2.0.4

type ITableName interface {
	TableName() string
}

type Linker added in v2.0.2

type Linker int
const (
	And Linker
	Or
)

type Operation added in v2.0.2

type Operation int
const (
	Eq Operation
	NotEq
	Ge
	Gt
	Le
	Lt
	Like
	LikeIgnoreStart
	LikeIgnoreEnd
	In
	NotIn
	IsNull
	IsNotNull
	RawOperation
)

type OrderBy added in v2.0.2

type OrderBy interface {
	Name() string
	Type() OrderType
}

func MakeOrderBy added in v2.0.2

func MakeOrderBy(name string, orderType OrderType) OrderBy

type OrderByImpl added in v2.0.2

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

func (OrderByImpl) Name added in v2.0.2

func (o OrderByImpl) Name() string

func (OrderByImpl) Type added in v2.0.2

func (o OrderByImpl) Type() OrderType

type OrderType added in v2.0.2

type OrderType int
const (
	Asc OrderType
	Desc
)

type PageImpl added in v2.0.2

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

func (PageImpl) Page added in v2.0.2

func (p PageImpl) Page() (int64, int64)

type PageInfo added in v2.0.2

type PageInfo interface {
	Page() (int64, int64)
}

func MakePage added in v2.0.2

func MakePage(page int64, size int64) PageInfo

type RawTableInfo added in v2.0.2

type RawTableInfo struct {
	reflect.Type
	RawTableName string
	IsSlice      bool
	IsPtr        bool
	IsStruct     bool
}

func GetRawTableInfo added in v2.0.2

func GetRawTableInfo(v interface{}) RawTableInfo

type ScanFunc added in v2.0.2

type ScanFunc func(src interface{}) (interface{}, error)

type ScannerGenerateFunc added in v2.0.2

type ScannerGenerateFunc func(colName string, col interface{}) IScanner

type ScannerImpl added in v2.0.2

type ScannerImpl struct {
	Object driver.Value
	ScanFunc
}

func (*ScannerImpl) Scan added in v2.0.2

func (scanner *ScannerImpl) Scan(src interface{}) error

func (ScannerImpl) Value added in v2.0.2

func (scanner ScannerImpl) Value() (driver.Value, error)

type SqlFactory added in v2.0.2

type SqlFactory interface {
	GetSqlFunc(sqlType SqlType) GenerateSQLFunc
	ConditionToSql(preTag bool, condition Condition) (string, []interface{})
}

func Get added in v2.0.2

func Get(name string) (SqlFactory, bool)

type SqlProto added in v2.0.2

type SqlProto struct {
	PreparedSql string
	Data        []interface{}
}

type SqlType added in v2.0.2

type SqlType int
const (
	Query SqlType
	Insert
	Update
	Delete
)

type TableModel added in v2.0.2

type TableModel interface {
	Table() string
	SetTable(tableName string)
	Columns() []string
	SetColumns([]string) error
	SetData(data interface{}, valueOfData reflect.Value, isStruct bool, isPtr bool, isSlice bool)
	GetScanners(columns []string) ([]interface{}, int, error)
	PrimaryAuto() bool
	ColumnDataMap() map[string]interface{}
	Condition() Condition
	SetCondition(c Condition) error
	OrderBys() []OrderBy
	SetOrderBys(orders []OrderBy) error
	Page() PageInfo
	SetPage(p PageInfo) error
	Scan(rows *sql.Rows) (interface{}, error)
	Clone() TableModel
}

func GetTableModel added in v2.0.2

func GetTableModel(v interface{}, choosedColumns ...string) (TableModel, error)

type TransactionWork

type TransactionWork func(databaseTx *DB) (interface{}, error)

Directories

Path Synopsis
factory

Jump to

Keyboard shortcuts

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