sqlc

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	EQ_ = iota
	NOT_EQ_
	LT_
	LTE_
	GT_
	GTE_
	IS_NULL_
	IS_NOT_NULL_
	BETWEEN_
	BETWEEN2_
	NOT_BETWEEN_
	IN_
	NOT_IN_
	LIKE_
	NOT_LIKE_
	OR_
	ORDER_BY_
	LEFT_
	RIGHT_
	INNER_
	SUM_
	AVG_
	MIN_
	MAX_
	CNT_
)

数据库操作类型枚举

View Source
const (
	ID      = "ID"
	Key     = "key"
	Auto    = "auto"
	Ignore  = "ignore"
	Bson    = "bson"
	Json    = "json"
	Mg      = "mg"
	True    = "true"
	Date    = "date"
	Date2   = "date2"
	Blob    = "blob"
	Safe    = "safe"
	DB      = "db"
	Comment = "comment"
	Charset = "charset"
	Collate = "collate"
)
View Source
const ASC_ = 1
View Source
const DESC_ = 2

Variables

This section is empty.

Functions

func LoopPager added in v1.1.0

func LoopPager(fast *FastObject, size int, call func(index int))

Types

type CacheConfig

type CacheConfig struct {
	// 16字节字段组 (2个字段,32字节)
	Prefix string // 16字节 (8+8) - string字段
	Key    string // 16字节 (8+8) - string字段

	// 8字节字段组 (1个字段,8字节)
	Expire int // 8字节 - int字段

	// bool字段组 (1个字段,1字节,会产生7字节填充到8字节对齐)
	Open bool // 1字节 - bool字段
}

CacheConfig 结构体 - 40字节 (4个字段,8字节对齐,无填充) 排列优化:string字段在前,int字段居中,bool字段在后

type Cnd

type Cnd struct {
	// 24字节切片字段组 (9个字段,216字节)
	ConditPart   []string    // 24字节 - 切片字段
	Conditions   []Condition // 24字节 - 切片字段
	AnyFields    []string    // 24字节 - 切片字段
	AnyNotFields []string    // 24字节 - 切片字段
	Distincts    []string    // 24字节 - 切片字段
	Groupbys     []string    // 24字节 - 切片字段
	Orderbys     []Condition // 24字节 - 切片字段
	Aggregates   []Condition // 24字节 - 切片字段
	JoinCond     []*JoinCond // 24字节 - 切片字段

	// 16字节字段组 (3个字段,48字节)
	Model       Object          // 16字节 - interface字段
	Pagination  dialect.Dialect // 16字节 - 结构体字段 (假设)
	CacheConfig CacheConfig     // 16字节 - 结构体字段 (假设)

	// 8字节字段组 (5个字段,40字节)
	CollationConfig *Collation             // 8字节 - 指针字段
	FromCond        *FromCond              // 8字节 - 指针字段
	Upsets          map[string]interface{} // 8字节 - map字段
	SampleSize      int64                  // 8字节 - int64字段
	LimitSize       int64                  // 固定截取结果集数量 - 8字节

	// bool字段组 (1个字段,1字节,会产生7字节填充)
	Escape bool // 1字节 - bool字段
}

Cnd 结构体 - 376字节 (20个字段,8字节对齐,0字节填充) 排列优化:按字段大小从大到小排列,24字节切片在前,16字节结构体居中,8字节字段在后

func M

func M(model ...Object) *Cnd

args[0]=对象类型

func (*Cnd) AddOther

func (self *Cnd) AddOther(part string) *Cnd

add other

func (*Cnd) Agg

func (self *Cnd) Agg(logic int, key string, alias ...string) *Cnd

聚合函数

func (*Cnd) Asc

func (self *Cnd) Asc(keys ...string) *Cnd

按字段排序升序

func (*Cnd) Between

func (self *Cnd) Between(key string, value1 interface{}, value2 interface{}) *Cnd

between, >= a b =<

func (*Cnd) Cache

func (self *Cnd) Cache(config CacheConfig) *Cnd

缓存指定结果集

func (*Cnd) Collation added in v1.0.71

func (self *Cnd) Collation(collation *Collation) *Cnd

func (*Cnd) Desc

func (self *Cnd) Desc(keys ...string) *Cnd

按字段排序倒序

func (*Cnd) Distinct

func (self *Cnd) Distinct(keys ...string) *Cnd

筛选字段去重

func (*Cnd) Eq

func (self *Cnd) Eq(key string, value interface{}) *Cnd

=

func (*Cnd) FastPage added in v1.0.49

func (self *Cnd) FastPage(fast *FastObject) *Cnd

func (*Cnd) Fields

func (self *Cnd) Fields(keys ...string) *Cnd

筛选指定字段查询

func (*Cnd) From

func (self *Cnd) From(fromTable string) *Cnd

复杂查询设定首个from table as

func (*Cnd) GetPageResult added in v1.0.54

func (self *Cnd) GetPageResult() dialect.PageResult

func (*Cnd) Groupby

func (self *Cnd) Groupby(keys ...string) *Cnd

按字段分组

func (*Cnd) Gt

func (self *Cnd) Gt(key string, value interface{}) *Cnd

>

func (*Cnd) Gte

func (self *Cnd) Gte(key string, value interface{}) *Cnd

>=

func (*Cnd) In

func (self *Cnd) In(key string, values ...interface{}) *Cnd

in

func (*Cnd) InDate

func (self *Cnd) InDate(key string, value1 interface{}, value2 interface{}) *Cnd

时间范围专用, >= a b <

func (*Cnd) IsNotNull

func (self *Cnd) IsNotNull(key string) *Cnd

is not null

func (*Cnd) IsNull

func (self *Cnd) IsNull(key string) *Cnd

is null

func (*Cnd) Join

func (self *Cnd) Join(join int, table string, on string) *Cnd

left join

func (*Cnd) Like

func (self *Cnd) Like(key string, value interface{}) *Cnd

like

func (*Cnd) Limit

func (self *Cnd) Limit(pageNo int64, pageSize int64) *Cnd

limit,以页数跨度查询

func (*Cnd) Lt

func (self *Cnd) Lt(key string, value interface{}) *Cnd

<

func (*Cnd) Lte

func (self *Cnd) Lte(key string, value interface{}) *Cnd

<=

func (*Cnd) NotBetween

func (self *Cnd) NotBetween(key string, value1 interface{}, value2 interface{}) *Cnd

not between

func (*Cnd) NotEq

func (self *Cnd) NotEq(key string, value interface{}) *Cnd

<>

func (*Cnd) NotFields

func (self *Cnd) NotFields(keys ...string) *Cnd

筛选过滤指定字段查询

func (*Cnd) NotIn

func (self *Cnd) NotIn(key string, values ...interface{}) *Cnd

not in

func (*Cnd) NotLike

func (self *Cnd) NotLike(key string, value interface{}) *Cnd

not like

func (*Cnd) Offset

func (self *Cnd) Offset(offset int64, limit int64) *Cnd

offset,以下标跨度查询

func (*Cnd) Or

func (self *Cnd) Or(cnds ...interface{}) *Cnd

or

func (*Cnd) Orderby

func (self *Cnd) Orderby(key string, sortby int) *Cnd

按字段排序

func (*Cnd) ResultSize

func (self *Cnd) ResultSize(size int64) *Cnd

固定截取结果集数量

func (*Cnd) Sample

func (self *Cnd) Sample(size int64) *Cnd

随机选取数据条数

func (*Cnd) UnEscape added in v1.0.118

func (self *Cnd) UnEscape() *Cnd

func (*Cnd) Upset

func (self *Cnd) Upset(keys []string, values ...interface{}) *Cnd

指定更新字段

func (*Cnd) UseEscape added in v1.1.0

func (self *Cnd) UseEscape() *Cnd

type Collation added in v1.0.71

type Collation struct {
	// 16字节字段组 (4个字段,64字节)
	Locale      string `bson:",omitempty"` // The locale - 16字节 (8+8)
	CaseFirst   string `bson:",omitempty"` // The case ordering - 16字节 (8+8)
	Alternate   string `bson:",omitempty"` // Whether spaces and punctuation are considered base characters - 16字节 (8+8)
	MaxVariable string `bson:",omitempty"` // Which characters are affected by alternate: "shifted" - 16字节 (8+8)

	// 8字节字段组 (1个字段,8字节)
	Strength int `bson:",omitempty"` // The number of comparison levels to use - 8字节

	// bool字段组 (3个字段,3字节,会产生5字节填充到8字节对齐)
	CaseLevel       bool `bson:",omitempty"` // The case level - 1字节
	NumericOrdering bool `bson:",omitempty"` // Whether to order numbers based on numerical order and not collation order - 1字节
	Normalization   bool `bson:",omitempty"` // Causes text to be normalized into Unicode NFD - 1字节
	Backwards       bool `bson:",omitempty"` // Causes secondary differences to be considered in reverse order, as it is done in the French language - 1字节
}

Collation 结构体 - 80字节 (8个字段,8字节对齐,无填充) 排列优化:string字段在前,int字段居中,bool字段在后连续排列

type Condition

type Condition struct {
	// 16字节字段组 (2个字段,32字节)
	Key   string // 16字节 (8+8) - string字段
	Alias string // 16字节 (8+8) - string字段

	// 16字节字段组 (2个字段,32字节)
	Value  interface{}   // 16字节 (8+8) - interface字段
	Values []interface{} // 24字节 (8+8+8) - slice字段

	// 8字节字段组 (1个字段,8字节)
	Logic int // 8字节 - int字段
}

Condition 结构体 - 80字节 (5个字段,8字节对齐,无填充) 排列优化:按字段大小分组,string字段在前,interface字段居中,int字段在后

type FastObject added in v1.1.0

type FastObject struct {
	PrevID int64
	LastID int64
	Size   int64
	CountQ bool
	IsPrev bool
	IsNext bool
	// contains filtered or unexported fields
}

func GetFast added in v1.1.0

func GetFast(req common.BaseReq) *FastObject

func (*FastObject) Asc added in v1.1.0

func (s *FastObject) Asc() *FastObject

func (*FastObject) Desc added in v1.1.0

func (s *FastObject) Desc() *FastObject

func (*FastObject) Key added in v1.1.0

func (s *FastObject) Key(k string) *FastObject

func (*FastObject) Sort added in v1.1.0

func (s *FastObject) Sort(v int) *FastObject

type FromCond

type FromCond struct {
	Table string // 16字节 (8+8) - string字段
	Alias string // 16字节 (8+8) - string字段
}

FromCond 结构体 - 32字节 (2个字段,8字节对齐,无填充) 排列优化:string字段连续排列

type Index added in v1.0.33

type Index struct {
	Name   string
	Key    []string
	Keys   []KV
	Unique bool
}

type JoinCond

type JoinCond struct {
	// 16字节字段组 (3个字段,48字节)
	Table string // 16字节 (8+8) - string字段
	Alias string // 16字节 (8+8) - string字段
	On    string // 16字节 (8+8) - string字段

	// 8字节字段组 (1个字段,8字节)
	Type int // 8字节 - int字段
}

JoinCond 结构体 - 56字节 (4个字段,8字节对齐,无填充) 排列优化:string字段在前,int字段在后

type KV added in v1.1.6

type KV struct {
	K string
	V int
}

type Limit added in v1.1.0

type Limit struct {
	// 分页条数
	Limit int64 `json:"limit"`
	// 总数据条数,查询条件prevID=0和lastID=0的时候触发查询count数量,一般在首页查询触发
	Total int64 `json:"total"`
	// 上一页的划分ID
	LastID int64 `json:"lastID"`
	// 下一页的划分ID
	PrevID int64 `json:"prevID"`
}

func LimitPager added in v1.1.0

func LimitPager(sql *Cnd, prevID, lastID int64) Limit

func (Limit) MarshalEasyJSON added in v1.1.0

func (v Limit) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Limit) MarshalJSON added in v1.1.0

func (v Limit) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Limit) UnmarshalEasyJSON added in v1.1.0

func (v *Limit) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Limit) UnmarshalJSON added in v1.1.0

func (v *Limit) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Object added in v1.0.5

type Object interface {
	GetTable() string
	NewObject() Object
	AppendObject(data interface{}, target Object)
	NewIndex() []Index
}

Jump to

Keyboard shortcuts

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