query

package
v1.25.11 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

* Licensed to the AcmeStack under one or more contributor license * agreements. See the NOTICE file distributed with this work for * additional information regarding copyright ownership. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(columnName any, asName any) string

func Begin

func Begin(opts ...*sql.TxOptions) *gobatis.DB

func Cache

func Cache(models ...any)

Cache 缓存实体对象所有的字段名

func Delete

func Delete[T any](q *QueryCond[T], opts ...OptionFunc) *gobatis.DB

Delete 根据条件删除记录

func DeleteById

func DeleteById[T any](id any, opts ...OptionFunc) *gobatis.DB

DeleteById 根据 ID 删除记录

func DeleteByIds

func DeleteByIds[T any](ids any, opts ...OptionFunc) *gobatis.DB

DeleteByIds 根据 ID 批量删除记录

func Exists

func Exists[T any](q *QueryCond[T], opts ...OptionFunc) (bool, *gobatis.DB)

Exists 根据条件判断记录是否存在

func GetModel

func GetModel[T any]() *T

GetModel 获取

func Init

func Init(db *gobatis.DB)

func Insert

func Insert[T any](entity *T, opts ...OptionFunc) *gobatis.DB

Insert 插入一条记录

func InsertBatch

func InsertBatch[T any](entities []*T, opts ...OptionFunc) *gobatis.DB

InsertBatch 批量插入多条记录

func InsertBatchSize

func InsertBatchSize[T any](entities []*T, batchSize int, opts ...OptionFunc) *gobatis.DB

InsertBatchSize 批量插入多条记录

func LikeLeft

func LikeLeft(query *QueryCond[any], name string, value any)

func LikeRight

func LikeRight(query *QueryCond[any], name string, value any)

func SelectById

func SelectById[T any](id any, opts ...OptionFunc) (*T, *gobatis.DB)

SelectById 根据 ID 查询单条记录

func SelectByIds

func SelectByIds[T any](ids any, opts ...OptionFunc) ([]*T, *gobatis.DB)

SelectByIds 根据 ID 查询多条记录

func SelectCount

func SelectCount[T any](q *QueryCond[T], opts ...OptionFunc) (int64, *gobatis.DB)

SelectCount 根据条件查询记录数量

func SelectGeneric

func SelectGeneric[T any, R any](q *QueryCond[T], opts ...OptionFunc) (R, *gobatis.DB)

SelectGeneric 根据传入的泛型封装记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

func SelectList

func SelectList[T any](q *QueryCond[T], opts ...OptionFunc) ([]*T, *gobatis.DB)

SelectList 根据条件查询多条记录

func SelectOne

func SelectOne[T any](q *QueryCond[T], opts ...OptionFunc) (*T, *gobatis.DB)

SelectOne 根据条件查询单条记录

func Tx

func Tx(txFunc func(tx *gobatis.DB) error, opts ...OptionFunc) error

Tx 事务

func Update

func Update[T any](q *QueryCond[T], opts ...OptionFunc) *gobatis.DB

Update 根据 Map 更新

func UpdateById

func UpdateById[T any](entity *T, opts ...OptionFunc) *gobatis.DB

UpdateById 根据 ID 更新,默认零值不更新

func UpdateZeroById

func UpdateZeroById[T any](entity *T, opts ...OptionFunc) *gobatis.DB

UpdateZeroById 根据 ID 零值更新

Types

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | time.Time
}

type Condition

type Condition struct {
	Group       string
	ColumnName  string
	Op          string
	ColumnValue any
}

type Dao

type Dao[T any] struct{}

func (Dao[T]) NewQuery

func (dao Dao[T]) NewQuery() (*QueryCond[T], *T)

type Function

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

func Avg

func Avg(columnName any) *Function

func Count

func Count(columnName any) *Function

func Max

func Max(columnName any) *Function

func Min

func Min(columnName any) *Function

func Sum

func Sum(columnName any) *Function

func (*Function) As

func (f *Function) As(asName any) string

func (*Function) Between

func (f *Function) Between(start int64, end int64) (string, int64, int64)

func (*Function) Eq

func (f *Function) Eq(value int64) (string, int64)

func (*Function) Ge

func (f *Function) Ge(value int64) (string, int64)

func (*Function) Gt

func (f *Function) Gt(value int64) (string, int64)

func (*Function) In

func (f *Function) In(values ...any) (string, []any)

func (*Function) Le

func (f *Function) Le(value int64) (string, int64)

func (*Function) Lt

func (f *Function) Lt(value int64) (string, int64)

func (*Function) Ne

func (f *Function) Ne(value int64) (string, int64)

func (*Function) NotBetween

func (f *Function) NotBetween(start int64, end int64) (string, int64, int64)

func (*Function) NotIn

func (f *Function) NotIn(values ...any) (string, []any)

type Option

type Option struct {
	Db          *gobatis.DB
	Selects     []any
	Omits       []any
	IgnoreTotal bool
}

type OptionFunc

type OptionFunc func(*Option)

func Db

func Db(db *gobatis.DB) OptionFunc

Db 使用传入的Db对象

func IgnoreTotal

func IgnoreTotal() OptionFunc

IgnoreTotal 分页查询忽略总数 issue: https://gitee.com/gobatis/gobatis/issues/37

func Omit

func Omit(columns ...any) OptionFunc

Omit 指定需要忽略的字段

func Select

func Select(columns ...any) OptionFunc

Select 指定需要查询的字段

func Session

func Session(session *gobatis.Session) OptionFunc

Session 创建回话

type Page

type Page[T any] struct {
	Current    int   `json:"current"`
	Size       int   `json:"size"`
	Total      int64 `json:"total"`
	Records    []*T  `json:"records"`
	RecordsMap []T   `json:"recordsMap"`
}

func NewPage

func NewPage[T any](current, size int) *Page[T]

func SelectPage

func SelectPage[T any](page *Page[T], q *QueryCond[T], opts ...OptionFunc) (*Page[T], *gobatis.DB)

SelectPage 根据条件分页查询记录

func SelectPageGeneric

func SelectPageGeneric[T any, R any](page *Page[R], q *QueryCond[T], opts ...OptionFunc) (*Page[R], *gobatis.DB)

SelectPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

type QueryCond

type QueryCond[T any] struct {
	// contains filtered or unexported fields
}

func BuildQuery

func BuildQuery[T any](queryParams url.Values) *QueryCond[T]

func NewQuery

func NewQuery[T any]() (*QueryCond[T], *T)

NewQuery 构建查询条件

func NewQueryModel

func NewQueryModel[T any, R any]() (*QueryCond[T], *T, *R)

NewQueryModel 构建查询条件

func (*QueryCond[T]) And

func (q *QueryCond[T]) And(fn ...func(q *QueryCond[T])) *QueryCond[T]

And 拼接 AND

func (*QueryCond[T]) AndCond

func (q *QueryCond[T]) AndCond(cond bool, fn ...func(q *QueryCond[T])) *QueryCond[T]

AndCond 拼接 AND

func (*QueryCond[T]) AndEqCond

func (q *QueryCond[T]) AndEqCond(cond bool, column any, val any) *QueryCond[T]

AndEqCond 并且等于 =

func (*QueryCond[T]) AndGeCond

func (q *QueryCond[T]) AndGeCond(cond bool, column any, val any) *QueryCond[T]

AndGeCond 并且大于等于 >=

func (*QueryCond[T]) AndGtCond

func (q *QueryCond[T]) AndGtCond(cond bool, column any, val any) *QueryCond[T]

AndGtCond 并且大于 >

func (*QueryCond[T]) AndInCond

func (q *QueryCond[T]) AndInCond(cond bool, column any, val any) *QueryCond[T]

AndInCond 并且字段 IN (值1, 值2, ...)

func (*QueryCond[T]) AndLeCond

func (q *QueryCond[T]) AndLeCond(cond bool, column any, val any) *QueryCond[T]

AndLeCond 并且小于等于 <=

func (*QueryCond[T]) AndLikeCond

func (q *QueryCond[T]) AndLikeCond(cond bool, column any, val any) *QueryCond[T]

AndLikeCond 并且模糊 LIKE '%值%'

func (*QueryCond[T]) AndLikeLeftCond

func (q *QueryCond[T]) AndLikeLeftCond(cond bool, column any, val any) *QueryCond[T]

AndLikeLeftCond 并且左模糊 LIKE '%值'

func (*QueryCond[T]) AndLikeRightCond

func (q *QueryCond[T]) AndLikeRightCond(cond bool, column any, val any) *QueryCond[T]

AndLikeRightCond 并且右模糊 LIKE '值%'

func (*QueryCond[T]) AndLtCond

func (q *QueryCond[T]) AndLtCond(cond bool, column any, val any) *QueryCond[T]

AndLtCond 并且小于 <

func (*QueryCond[T]) AndNeCond

func (q *QueryCond[T]) AndNeCond(cond bool, column any, val any) *QueryCond[T]

AndNeCond 并且不等于 !=

func (*QueryCond[T]) AndNotLikeCond

func (q *QueryCond[T]) AndNotLikeCond(cond bool, column any, val any) *QueryCond[T]

AndNotLikeCond 并且非模糊 NOT LIKE '%值%'

func (*QueryCond[T]) AndNotLikeLeftCond

func (q *QueryCond[T]) AndNotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]

AndNotLikeLeftCond 并且非左模糊 NOT LIKE '%值'

func (*QueryCond[T]) AndNotLikeRightCond

func (q *QueryCond[T]) AndNotLikeRightCond(cond bool, column any, val any) *QueryCond[T]

AndNotLikeRightCond 并且非右模糊 NOT LIKE '值%'

func (*QueryCond[T]) Between

func (q *QueryCond[T]) Between(column any, start, end any) *QueryCond[T]

Between BETWEEN 值1 AND 值2

func (*QueryCond[T]) Distinct

func (q *QueryCond[T]) Distinct(columns ...any) *QueryCond[T]

Distinct 去除重复字段值

func (*QueryCond[T]) Eq

func (q *QueryCond[T]) Eq(column any, val any) *QueryCond[T]

Eq 等于 =

func (*QueryCond[T]) EqCond

func (q *QueryCond[T]) EqCond(cond bool, column any, val any) *QueryCond[T]

EqCond 等于 =

func (*QueryCond[T]) Ge

func (q *QueryCond[T]) Ge(column any, val any) *QueryCond[T]

Ge 大于等于 >=

func (*QueryCond[T]) GeCond

func (q *QueryCond[T]) GeCond(cond bool, column any, val any) *QueryCond[T]

GeCond 大于等于 >=

func (*QueryCond[T]) Group

func (q *QueryCond[T]) Group(columns ...any) *QueryCond[T]

Group 分组:GROUP BY 字段1,字段2

func (*QueryCond[T]) Gt

func (q *QueryCond[T]) Gt(column any, val any) *QueryCond[T]

Gt 大于 >

func (*QueryCond[T]) GtCond

func (q *QueryCond[T]) GtCond(cond bool, column any, val any) *QueryCond[T]

GtCond 大于 >

func (*QueryCond[T]) Having

func (q *QueryCond[T]) Having(having string, args ...any) *QueryCond[T]

Having HAVING SQl语句

func (*QueryCond[T]) In

func (q *QueryCond[T]) In(column any, val any) *QueryCond[T]

In 字段 IN (值1, 值2, ...)

func (*QueryCond[T]) InCond

func (q *QueryCond[T]) InCond(cond bool, column any, val any) *QueryCond[T]

InCond 字段 IN (值1, 值2, ...)

func (*QueryCond[T]) IsNotNull

func (q *QueryCond[T]) IsNotNull(column any) *QueryCond[T]

IsNotNull 是否非空 字段 IS NOT NULL

func (*QueryCond[T]) IsNull

func (q *QueryCond[T]) IsNull(column any) *QueryCond[T]

IsNull 是否为空 字段 IS NULL

func (*QueryCond[T]) Le

func (q *QueryCond[T]) Le(column any, val any) *QueryCond[T]

Le 小于等于 <=

func (*QueryCond[T]) LeCond

func (q *QueryCond[T]) LeCond(cond bool, column any, val any) *QueryCond[T]

LeCond 小于等于 <=

func (*QueryCond[T]) Like

func (q *QueryCond[T]) Like(column any, val any) *QueryCond[T]

Like 模糊 LIKE '%值%'

func (*QueryCond[T]) LikeCond

func (q *QueryCond[T]) LikeCond(cond bool, column any, val any) *QueryCond[T]

LikeCond 模糊 LIKE '%值%'

func (*QueryCond[T]) LikeLeft

func (q *QueryCond[T]) LikeLeft(column any, val any) *QueryCond[T]

LikeLeft 左模糊 LIKE '%值'

func (*QueryCond[T]) LikeLeftCond

func (q *QueryCond[T]) LikeLeftCond(cond bool, column any, val any) *QueryCond[T]

LikeLeftCond 左模糊 LIKE '%值'

func (*QueryCond[T]) LikeRight

func (q *QueryCond[T]) LikeRight(column any, val any) *QueryCond[T]

LikeRight 右模糊 LIKE '值%'

func (*QueryCond[T]) LikeRightCond

func (q *QueryCond[T]) LikeRightCond(cond bool, column any, val any) *QueryCond[T]

LikeRightCond 右模糊 LIKE '值%'

func (*QueryCond[T]) Lt

func (q *QueryCond[T]) Lt(column any, val any) *QueryCond[T]

Lt 小于 <

func (*QueryCond[T]) LtCond

func (q *QueryCond[T]) LtCond(cond bool, column any, val any) *QueryCond[T]

LtCond 小于 <

func (*QueryCond[T]) Ne

func (q *QueryCond[T]) Ne(column any, val any) *QueryCond[T]

Ne 不等于 !=

func (*QueryCond[T]) NeCond

func (q *QueryCond[T]) NeCond(cond bool, column any, val any) *QueryCond[T]

NeCond 不等于 !=

func (*QueryCond[T]) NotBetween

func (q *QueryCond[T]) NotBetween(column any, start, end any) *QueryCond[T]

NotBetween NOT BETWEEN 值1 AND 值2

func (*QueryCond[T]) NotIn

func (q *QueryCond[T]) NotIn(column any, val any) *QueryCond[T]

NotIn 字段 NOT IN (值1, 值2, ...)

func (*QueryCond[T]) NotLike

func (q *QueryCond[T]) NotLike(column any, val any) *QueryCond[T]

NotLike 非模糊 NOT LIKE '%值%'

func (*QueryCond[T]) NotLikeCond

func (q *QueryCond[T]) NotLikeCond(cond bool, column any, val any) *QueryCond[T]

NotLikeCond 非模糊 NOT LIKE '%值%'

func (*QueryCond[T]) NotLikeLeft

func (q *QueryCond[T]) NotLikeLeft(column any, val any) *QueryCond[T]

NotLikeLeft 非左模糊 NOT LIKE '%值'

func (*QueryCond[T]) NotLikeLeftCond

func (q *QueryCond[T]) NotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]

NotLikeLeftCond 非左模糊 NOT LIKE '%值'

func (*QueryCond[T]) NotLikeRight

func (q *QueryCond[T]) NotLikeRight(column any, val any) *QueryCond[T]

NotLikeRight 非右模糊 NOT LIKE '值%'

func (*QueryCond[T]) NotLikeRightCond

func (q *QueryCond[T]) NotLikeRightCond(cond bool, column any, val any) *QueryCond[T]

NotLikeRightCond 非右模糊 NOT LIKE '值%'

func (*QueryCond[T]) Omit

func (q *QueryCond[T]) Omit(columns ...any) *QueryCond[T]

Omit 忽略字段

func (*QueryCond[T]) Or

func (q *QueryCond[T]) Or(fn ...func(q *QueryCond[T])) *QueryCond[T]

Or 拼接 OR

func (*QueryCond[T]) OrCond

func (q *QueryCond[T]) OrCond(cond bool, fn ...func(q *QueryCond[T])) *QueryCond[T]

OrCond 拼接 OR

func (*QueryCond[T]) OrEqCond

func (q *QueryCond[T]) OrEqCond(cond bool, column any, val any) *QueryCond[T]

OrEqCond 或者等于 =

func (*QueryCond[T]) OrGeCond

func (q *QueryCond[T]) OrGeCond(cond bool, column any, val any) *QueryCond[T]

OrGeCond 或者大于等于 >=

func (*QueryCond[T]) OrGtCond

func (q *QueryCond[T]) OrGtCond(cond bool, column any, val any) *QueryCond[T]

OrGtCond 或者大于 >

func (*QueryCond[T]) OrInCond

func (q *QueryCond[T]) OrInCond(cond bool, column any, val any) *QueryCond[T]

OrInCond 或者字段 IN (值1, 值2, ...)

func (*QueryCond[T]) OrLeCond

func (q *QueryCond[T]) OrLeCond(cond bool, column any, val any) *QueryCond[T]

OrLeCond 或者小于等于 <=

func (*QueryCond[T]) OrLikeCond

func (q *QueryCond[T]) OrLikeCond(cond bool, column any, val any) *QueryCond[T]

OrLikeCond 或者模糊 LIKE '%值%'

func (*QueryCond[T]) OrLikeLeftCond

func (q *QueryCond[T]) OrLikeLeftCond(cond bool, column any, val any) *QueryCond[T]

OrLikeLeftCond 或者左模糊 LIKE '%值'

func (*QueryCond[T]) OrLikeRightCond

func (q *QueryCond[T]) OrLikeRightCond(cond bool, column any, val any) *QueryCond[T]

OrLikeRightCond 或者右模糊 LIKE '值%'

func (*QueryCond[T]) OrLtCond

func (q *QueryCond[T]) OrLtCond(cond bool, column any, val any) *QueryCond[T]

OrLtCond 或者小于 <

func (*QueryCond[T]) OrNeCond

func (q *QueryCond[T]) OrNeCond(cond bool, column any, val any) *QueryCond[T]

OrNeCond 或者不等于 !=

func (*QueryCond[T]) OrNotLikeCond

func (q *QueryCond[T]) OrNotLikeCond(cond bool, column any, val any) *QueryCond[T]

OrNotLikeCond 或者非模糊 NOT LIKE '%值%'

func (*QueryCond[T]) OrNotLikeLeftCond

func (q *QueryCond[T]) OrNotLikeLeftCond(cond bool, column any, val any) *QueryCond[T]

OrNotLikeLeftCond 或者非左模糊 NOT LIKE '%值'

func (*QueryCond[T]) OrNotLikeRightCond

func (q *QueryCond[T]) OrNotLikeRightCond(cond bool, column any, val any) *QueryCond[T]

OrNotLikeRightCond 或者非右模糊 NOT LIKE '值%'

func (*QueryCond[T]) OrderByAsc

func (q *QueryCond[T]) OrderByAsc(columns ...any) *QueryCond[T]

OrderByAsc 排序:ORDER BY 字段1,字段2 ASC

func (*QueryCond[T]) OrderByDesc

func (q *QueryCond[T]) OrderByDesc(columns ...any) *QueryCond[T]

OrderByDesc 排序:ORDER BY 字段1,字段2 Desc

func (*QueryCond[T]) Select

func (q *QueryCond[T]) Select(columns ...any) *QueryCond[T]

Select 查询字段

func (*QueryCond[T]) Set

func (q *QueryCond[T]) Set(column any, val any) *QueryCond[T]

Set 设置更新的字段

type SqlSegment

type SqlSegment interface {
	// contains filtered or unexported methods
}

type StreamingPage

type StreamingPage[T any, V Comparable] struct {
	ColumnName any   `json:"columnName"` // 进行分页的列字段名称
	StartValue V     `json:"startValue"` // 分页起始值
	Limit      int   `json:"limit"`      // 页大小
	Forward    bool  `json:"forward"`    // 上下页翻页标识
	Total      int64 `json:"total"`      // 总记录数
	Records    []*T  `json:"records"`    // 查询记录
	RecordsMap []T   `json:"recordsMap"` // 查询记录Map
}

func NewStreamingPage

func NewStreamingPage[T any, V Comparable](columnName any, startValue V, limit int) *StreamingPage[T, V]

func SelectStreamingPage

func SelectStreamingPage[T any, V Comparable](page *StreamingPage[T, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[T, V], *gobatis.DB)

SelectStreamingPage 根据条件分页查询记录

func SelectStreamingPageGeneric

func SelectStreamingPageGeneric[T any, R any, V Comparable](page *StreamingPage[R, V], q *QueryCond[T], opts ...OptionFunc) (*StreamingPage[R, V], *gobatis.DB)

SelectStreamingPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

Jump to

Keyboard shortcuts

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