Documentation
¶
Overview ¶
Package horm mysql 查询语句封装包
Index ¶
- Constants
- func GetDBConfig(name string) (*dbConfig, error)
- func IsAllSuccess(results []*proto.ModResult) bool
- func LoadConfig(confPath ...string)
- func SetGlobalClient(name string, opts ...Option)
- type AND
- type Client
- type Error
- type IN
- type Map
- type OR
- type On
- type Option
- func WithAppID(appid uint64) Option
- func WithCaller(caller string) Option
- func WithEncryption(token string) Option
- func WithLocalIP(ip string) Option
- func WithLocation(region, zone, compus string) Option
- func WithSecret(secret string) Option
- func WithTarget(target string) Option
- func WithTimeout(timeout uint32) Option
- func WithToken(token string) Option
- func WithWorkspaceID(workspaceID int) Option
- type Options
- type Query
- func (s *Query) AddNext(nexts ...*Query) *Query
- func (s *Query) AddSub(sub *Query) *Query
- func (s *Query) Between(key string, start, end interface{}) *Query
- func (s *Query) BitCount(key string, start, end int) *Query
- func (s *Query) Bytes(bs []byte) *Query
- func (s *Query) Collapse(field string) *Query
- func (s *Query) Column(columns ...string) *Query
- func (s *Query) CompExec(ctx context.Context, retReceiver interface{}) error
- func (s *Query) Create(name, shard string, ifNotExists ...bool) *Query
- func (s *Query) Decr(key string) *Query
- func (s *Query) Del(key string) *Query
- func (s *Query) Delete(where ...Where) *Query
- func (s *Query) DeleteBy(key string, value interface{}, kvs ...interface{}) *Query
- func (s *Query) Eq(key string, value interface{}, kvs ...interface{}) *Query
- func (s *Query) Exec(ctx context.Context, retReceiver ...interface{}) (isNil bool, err error)
- func (s *Query) Exists(key string) *Query
- func (s *Query) Expire(key string, ttl int) *Query
- func (s *Query) Extend(key string, value interface{}) *Query
- func (s *Query) Find(where ...Where) *Query
- func (s *Query) FindAll(where ...Where) *Query
- func (s *Query) FindAllBy(key string, value interface{}, kvs ...interface{}) *Query
- func (s *Query) FindBy(key string, value interface{}, kvs ...interface{}) *Query
- func (s *Query) Get(key string) *Query
- func (s *Query) GetBit(key string, offset uint32) *Query
- func (s *Query) GetCoder() codec.Codec
- func (s *Query) GetHead() *Query
- func (s *Query) GetSet(key string, v interface{}) *Query
- func (s *Query) Group(group ...string) *Query
- func (s *Query) Gt(key string, value interface{}) *Query
- func (s *Query) Gte(key string, value interface{}) *Query
- func (s *Query) HDel(key string, field ...interface{}) *Query
- func (s *Query) HExists(key string, field interface{}) *Query
- func (s *Query) HGet(key string, field interface{}) *Query
- func (s *Query) HGetAll(key string) *Query
- func (s *Query) HIncrBy(key string, field string, v int) *Query
- func (s *Query) HIncrByFloat(key string, field string, v float64) *Query
- func (s *Query) HLen(key string) *Query
- func (s *Query) HSet(key string, field, v interface{}, args ...interface{}) *Query
- func (s *Query) HSetNx(key string, filed interface{}, value interface{}) *Query
- func (s *Query) HStrLen(key string, field interface{}) *Query
- func (s *Query) HVals(key string) *Query
- func (s *Query) Having(having Where) *Query
- func (s *Query) HighLight(fields []string, preTag, postTag string) *Query
- func (s *Query) Hkeys(key string) *Query
- func (s *Query) HmGet(key string, fields ...string) *Query
- func (s *Query) HmSet(key string, v interface{}) *Query
- func (s *Query) ID(value interface{}) *Query
- func (s *Query) Incr(key string) *Query
- func (s *Query) IncrBy(key string, n int) *Query
- func (s *Query) Insert(data interface{}) *Query
- func (s *Query) LLen(key string) *Query
- func (s *Query) LPop(key string) *Query
- func (s *Query) LPush(key string, v ...interface{}) *Query
- func (s *Query) Like(key string, value interface{}) *Query
- func (s *Query) Limit(limit int, offset ...uint64) *Query
- func (s *Query) Lt(key string, value interface{}) *Query
- func (s *Query) Lte(key string, value interface{}) *Query
- func (s *Query) MGet(keys ...string) *Query
- func (s *Query) MSet(values map[string]interface{}) *Query
- func (s *Query) Match(key string, value interface{}) *Query
- func (s *Query) MatchPhrase(key string, value interface{}) *Query
- func (s *Query) Name(name string) *Query
- func (s *Query) Next(name string) *Query
- func (s *Query) Not(key string, value interface{}) *Query
- func (s *Query) NotBetween(key string, start, end interface{}) *Query
- func (s *Query) NotLike(key string, value interface{}) *Query
- func (s *Query) NotMatch(key string, value interface{}) *Query
- func (s *Query) NotMatchPhrase(key string, value interface{}) *Query
- func (s *Query) Op(op string) *Query
- func (s *Query) Order(orders ...string) *Query
- func (s *Query) PExec(ctx context.Context) error
- func (s *Query) Page(page, pageSize int) *Query
- func (s *Query) Prefix(prefix string) *Query
- func (s *Query) RPop(key string) *Query
- func (s *Query) RPush(key string, v ...interface{}) *Query
- func (s *Query) Refresh() *Query
- func (s *Query) Replace(data interface{}) *Query
- func (s *Query) Reset() *Query
- func (s *Query) Routing(routing string) *Query
- func (s *Query) SAdd(key string, v ...interface{}) *Query
- func (s *Query) SCard(key string) *Query
- func (s *Query) SIsMember(key string, member interface{}) *Query
- func (s *Query) SMembers(key string) *Query
- func (s *Query) SMove(source, destination string, member interface{}) *Query
- func (s *Query) SPop(key string, count int) *Query
- func (s *Query) SRandMember(key string, count int) *Query
- func (s *Query) SRem(key string, members ...interface{}) *Query
- func (s *Query) Scroll(scroll string, size int, where ...Where) *Query
- func (s *Query) ScrollByID(id string) *Query
- func (s *Query) Set(key string, value interface{}, args ...interface{}) *Query
- func (s *Query) SetBit(key string, offset uint32, value bool) *Query
- func (s *Query) SetCompress() *Query
- func (s *Query) SetEX(key string, v interface{}, ttl int) *Query
- func (s *Query) SetNX(key string, v interface{}) *Query
- func (s *Query) SetParam(key string, value interface{}) *Query
- func (s *Query) Shard(shard ...string) *Query
- func (s *Query) Source(q string, args ...interface{}) *Query
- func (s *Query) TTL(key string) *Query
- func (s *Query) Type(typ string) *Query
- func (s *Query) Update(data interface{}, where ...Where) *Query
- func (s *Query) UpdateKV(key string, value interface{}, kvs ...interface{}) *Query
- func (s *Query) Where(where Where) *Query
- func (s *Query) WithClient(c Client) *Query
- func (s *Query) WithCoder(coder codec.Codec) *Query
- func (s *Query) WithReceiver(nilReceiver *bool, errReceiver *error, receiver ...interface{}) *Query
- func (s *Query) WithRequestID(id uint64) *Query
- func (s *Query) WithTraceID(id string) *Query
- func (s *Query) ZAdd(key string, args ...interface{}) *Query
- func (s *Query) ZCard(key string) *Query
- func (s *Query) ZCount(key string, min, max interface{}) *Query
- func (s *Query) ZIncrBy(key string, member, incr interface{}) *Query
- func (s *Query) ZPopMax(key string, count ...int64) *Query
- func (s *Query) ZPopMin(key string, count ...int64) *Query
- func (s *Query) ZRange(key string, start, stop int, withScore ...bool) *Query
- func (s *Query) ZRangeByScore(key string, min, max interface{}, withScores bool, limit ...int64) *Query
- func (s *Query) ZRank(key string, member interface{}) *Query
- func (s *Query) ZRem(key string, members ...interface{}) *Query
- func (s *Query) ZRemRangeByRank(key string, start, stop int) *Query
- func (s *Query) ZRemRangeByScore(key string, min, max interface{}) *Query
- func (s *Query) ZRevRange(key string, start, stop int, withScore ...bool) *Query
- func (s *Query) ZRevRangeByScore(key string, max, min interface{}, withScore bool, limit ...int64) *Query
- func (s *Query) ZRevRank(key string, member interface{}) *Query
- func (s *Query) ZScore(key string, member interface{}) *Query
- type RspErrs
- type Using
- type Where
Constants ¶
const Version = 1 // orm client version v1,影响查询语句
Variables ¶
This section is empty.
Functions ¶
func IsAllSuccess ¶
IsAllSuccess 判断 es 批量插入是否全部成功
func SetGlobalClient ¶
SetGlobalClient 设置全局查询语句执行客户端。 param: name 配置名 param: opts 参数配置
Types ¶
type Client ¶
type Client interface {
Exec(ctx context.Context, q *Query, retReceiver ...interface{}) (isNil bool, err error)
PExec(ctx context.Context, q *Query) error
CompExec(ctx context.Context, q *Query, retReceiver interface{}) error
}
Client 查询语句执行客户端
var GlobalClient Client // 全局查询语句执行客户端
type Option ¶
type Option func(*Options)
Option sets client options.
func WithCaller ¶
WithCaller returns an Option that sets caller service name of client.
func WithEncryption ¶
WithEncryption returns an Option that sets encryption of frame.
func WithLocalIP ¶
WithLocalIP returns an Option that sets ip of client.
func WithLocation ¶
WithLocation returns an Option that sets location of client.
func WithSecret ¶
WithSecret returns an Option that sets appid`s secret.
func WithTarget ¶
WithTarget returns an Option that sets target of server.
func WithTimeout ¶
WithTimeout returns an Option that sets timeout of server.
func WithWorkspaceID ¶
WithWorkspaceID returns an Option that sets workspace of server.
type Options ¶
type Options struct {
WorkspaceID int // workspace id
Encryption int8 // frame encryption
Token string // workspace token
Timeout uint32 // timeout Millisecond
Caller string // caller name
Appid uint64 // appid
Secret string // secret
Target string // server target address
LocalIP string // 本地 ip
Location struct {
Region string // 区域
Zone string // 城市
Compus string // 园区
}
}
Options are client options.
type Query ¶
type Query struct {
Unit *proto.Unit // 请求单元
Client Client // 客户端
Error error // Query 语句错误
Key string // 语句 key
Receiver []interface{} // 结果接收
IsNil *bool // 是否包含空值
RespError *error // 返回错误
Compress bool // 是否压缩 false - 不压缩 true - 压缩
ResultType int8 // 返回数据类型
Coder codec.Codec // 数据编解码器
RequestID uint64 // 请求 id
TraceID string // 请求 trace_id
RequestBody []byte // 请求体
// contains filtered or unexported fields
}
Query 请求语句
func NewTransaction ¶
NewTransaction 创建一个事务语句 param: trans 为该事务所有执行语句,所有语句必须全部成功或失败。注意:仅支持带事务功能的数据库回滚。
func (*Query) BitCount ¶
BitCount 计算给定字符串中,被设置为 1 的比特位的数量 param: key string param: start int 可以使用负数值: 比如 -1 表示最后一个字节, -2 表示倒数第二个字节,以此类推 param: end int 可以使用负数值: 比如 -1 表示最后一个字节, -2 表示倒数第二个字节,以此类推
func (*Query) Decr ¶
Decr 将 key 中储存的数字值减一。如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作。如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 param: key string
func (*Query) DeleteBy ¶
DeleteBy delete where key1=value1 AND key2=value2 ... input must be key, value, key, value, key, value ...
func (*Query) Eq ¶
Eq equal mean where key1=value1 AND key2=value2 ... input must be key, value, key, value, key, value ...
func (*Query) Expire ¶
Expire 设置 key 的过期时间,key 过期后将不再可用。单位以秒计。 param: key string param: int ttl 到期时间,ttl秒
func (*Query) FindAllBy ¶
FindAllBy find_all where key1=value1 AND key2=value2 ... input must be key, value, key, value, key, value ...
func (*Query) FindBy ¶
FindBy find where key1=value1 AND key2=value2 ... input must be key, value, key, value, key, value ...
func (*Query) Get ¶
Get 获取指定 key 的值。如果 key 不存在,返回 nil 。可用 IsNil(err) 判断是否key不存在,如果key储存的值不是字符串类型,返回一个错误。 param: key string
func (*Query) GetBit ¶
GetBit 获取指定偏移量上的位 param: key string param: offset uint32 参数必须大于或等于 0 ,小于 2^32 (bit 映射被限制在 512 MB 之内)
func (*Query) GetSet ¶
GetSet 设置给定 key 的值。如果 key 已经存储其他值, GetSet 就覆写旧值,并返回原来的值,如果原来未设置值,则返回报错 nil returned param: key string param: v interface{} 任意类型数据
func (*Query) HDel ¶
HDel 删除哈希表 key 中的一个或多个指定字段,不存在的字段将被忽略。 param: keyfield interface{},删除指定key的field数据,这里输入的第一参数为key,其他为多个field,至少得有一个field
func (*Query) HIncrBy ¶
HIncrBy 为哈希表中的字段值加上指定增量值。 param: key string param: field string param: n string 自增数量
func (*Query) HIncrByFloat ¶
HIncrByFloat 为哈希表中的字段值加上指定增量浮点数。 param: key string param: field string param: v float64 自增数量
func (*Query) HSet ¶
HSet 为哈希表中的字段赋值 。 param: key string param: field interface{} 其中field建议为字符串,可以为整数,浮点数 param: v interface{} 任意类型数据 param: args ...interface{} 多条数据,按照filed,value 的格式,其中field建议为字符串,可以为整数,浮点数
func (*Query) HSetNx ¶
HSetNx 为哈希表中不存在的的字段赋值 。 param: key string param: field string param: value interface{}
func (*Query) HmSet ¶
HmSet 把 map/struct 数据设置到哈希表中。此命令会覆盖哈希表中已存在的字段。如果哈希表不存在,会创建一个空哈希表,并执行 HMSET 操作。 param: key string param: v 必须是 map[string]interface{} 、或者 struct
func (*Query) Incr ¶
Incr 将 key 中储存的数字值增一。 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作。 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 param: key string
func (*Query) IncrBy ¶
IncrBy 将 key 中储存的数字加上指定的增量值。如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCRBY 命令。如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 param: key string param: n string 自增数量
func (*Query) LLen ¶
LLen 返回列表的长度。 如果列表 key 不存在,则 key 被解释为一个空列表,返回 0 。 如果 key 不是列表类型,返回一个错误。 param: key string
func (*Query) LPush ¶
LPush 将一个或多个值插入到列表头部。 如果 key 不存在,一个空列表会被创建并执行 LPUSH 操作。 当 key 存在但不是列表类型时,返回一个错误。 param: key string param: v interface{} 任意类型数据
func (*Query) MSet ¶
MSet 批量设置一个或多个 key-value 对 param: values map[string]interface{} // value will marshal 注意,本接口 Prefix 一定要在 MSet 之前设置,这里所有的 key 都会被加上 Prefix
func (*Query) MatchPhrase ¶
func (*Query) NotBetween ¶
func (*Query) NotMatchPhrase ¶
func (*Query) RPush ¶
RPush 将一个或多个值插入到列表的尾部(最右边)。如果列表不存在,一个空列表会被创建并执行 RPUSH 操作。 当列表存在但不是列表类型时,返回一个错误。 param: key string param: v interface{} 任意类型数据
func (*Query) SAdd ¶
SAdd 将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略。 param: key string param: v ...interface{} 任意类型的多条数据,但是务必确保各条数据的类型保持一致
func (*Query) SIsMember ¶
SIsMember 判断成员元素是否是集合的成员。 param: key string param: member interface{} 要检索的任意类型数据
func (*Query) SMove ¶
SMove 将指定成员 member 元素从 source 集合移动到 destination 集合。 param: source string param: destination string param: member interface{} 要移动的成员,任意类型
func (*Query) SRandMember ¶
SRandMember 返回集合中的count个随机元素。 param: key string param: count int 随机返回元素个数。 如果 count 为正数,且小于集合基数,那么命令返回一个包含 count 个元素的数组,数组中的元素各不相同。 如果 count 大于等于集合基数,那么返回整个集合。 如果 count 为负数,那么命令返回一个数组,数组中的元素可能会重复出现多次,而数组的长度为 count 的绝对值。
func (*Query) SRem ¶
SRem 移除集合中的一个或多个成员元素,不存在的成员元素会被忽略 param: key string param: v ...interface{} 任意类型的多条数据
func (*Query) ScrollByID ¶
ScrollByID 根据 scrollID 滚动查询。
func (*Query) Set ¶
Set 设置给定 key 的值。如果 key 已经存储其他值, Set 就覆写旧值。 param: key string param: value interface{} 任意类型数据 param: args ...interface{} set的其他参数
func (*Query) SetBit ¶
SetBit 设置或清除指定偏移量上的位 param: key string param: offset uint32 参数必须大于或等于 0 ,小于 2^32 (bit 映射被限制在 512 MB 之内) param: value bool true:设置为1,false:设置为0
func (*Query) SetCompress ¶
SetCompress 压缩,调用该方法表示数据将通过Gzip压缩传递
func (*Query) SetEX ¶
SetEX 指定的 key 设置值及其过期时间。如果 key 已经存在, SETEX 命令将会替换旧的值。 param: key string param: v interface{} 任意类型数据 param: ttl int 到期时间
func (*Query) SetNX ¶
SetNX redis.SetNX 指定的 key 不存在时,为 key 设置指定的值。 param: key string param: v interface{} 任意类型数据
func (*Query) SetParam ¶
SetParam 与数据库相关的请求参数,例如 redis 的 WITHSCORES, elastic 的 collapse、runtime_mappings、track_total_hits 等等。
func (*Query) WithReceiver ¶
WithReceiver 接收返回,主要用于并发查询
func (*Query) WithRequestID ¶
WithRequestID 设置 request_id
func (*Query) ZAdd ¶
ZAdd redis.ZAdd 将成员元素及其分数值加入到有序集当中。如果某个成员已经是有序集的成员,那么更新这个成员的分数值,并通过重新插入这个成员元素, 来保证该成员在正确的位置上。分数值可以是整数值或双精度浮点数。 param: key string param: args ...interface{} 添加更多成员,需要按照 member, score, member, score 依次排列 注意:⚠️ 与 redis 命令不一样,需要按照 member, score, member, score, 格式传入
func (*Query) ZCount ¶
ZCount 计算有序集合中指定分数区间的成员数量 param: key string param: min interface{} param: max interface{}
func (*Query) ZIncrBy ¶
ZIncrBy 对有序集合中指定成员的分数加上增量 increment,可以通过传递一个负数值 increment , 让分数减去相应的值,比如 ZINCRBY key -5 member , 就是让 member 的 score 值减去 5 。当 key 不存在,或分数不是 key 的成员时, ZINCRBY key increment member 等同于 ZADD key increment member 。当 key 不是有序集类型时,返回一个错误。分数值可以是整数值或双精度浮点数。 param: key string param: member interface{} 任意类型数据 param: incr interface{} 增量值,可以为整数或双精度浮点
func (*Query) ZPopMax ¶
ZPopMax 移除并弹出有序集合中分值最大的的 count 个元素 redis v5.0.0+ param: key string param: count ...int64 不设置count参数时,弹出一个元素
func (*Query) ZPopMin ¶
ZPopMin 移除并弹出有序集合中分值最小的 count 个元素 redis v5.0.0+ param: key string param: count ...int64 不设置count参数时,弹出一个元素
func (*Query) ZRange ¶
ZRange 返回有序集中,指定区间内的成员。其中成员的位置按分数值递增(从小到大)来排序。 param: key string param: int start, stop 以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,你也可以使用负数下标, param: withScore 是否返回有序集的分数, true - 返回,false - 不返回,默认不返回,结果分开在两个数组存储,但是数组下标是一一对应的,比如 member[3] 成员的分数是 score[3] 以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。
func (*Query) ZRangeByScore ¶
func (s *Query) ZRangeByScore(key string, min, max interface{}, withScores bool, limit ...int64) *Query
ZRangeByScore 根据分数返回有序集中指定区间的成员,顺序从小到大 param: key string param: int min, max 分数的范围,类型必须为 int, float,但是 -inf +inf 表示负正无穷大 param: withScores 是否返回有序集的分数, true - 返回,false - 不返回,默认不返回,结果分开在两个数组存储,但是数组下标是一一对应的,比如 member[3] 成员的分数是 score[3] param: limit offset count 游标
func (*Query) ZRank ¶
ZRank 返回有序集中指定成员的排名。其中有序集成员按分数值递增(从小到大)顺序排列。 param: key string param: member interface{} 成员,任意类型
func (*Query) ZRem ¶
ZRem 移除有序集中的一个或多个成员,不存在的成员将被忽略。 param: key string param: members ...interface{} 任意类型的多条数据
func (*Query) ZRemRangeByRank ¶
ZRemRangeByRank 移除有序集中,指定排名(rank)区间内的所有成员。 param: key string param: start stop int 排名区间
func (*Query) ZRemRangeByScore ¶
ZRemRangeByScore 移除有序集中,指定分数(score)区间内的所有成员。 param: key string param: interface{} min max 分数区间,类型为整数或者浮点数
func (*Query) ZRevRange ¶
ZRevRange 返回有序集中指定区间的成员,其中成员的位置按分数值递减(从大到小)来排列。 param: key string param: start, stop 排名区间,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,你也可以使用负数下标, param: withScore 是否返回有序集的分数, true - 返回,false - 不返回,默认不返回,结果分开在两个数组存储,但是数组下标是一一对应的,比如 member[3] 成员的分数是 score[3] 以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。
func (*Query) ZRevRangeByScore ¶
func (s *Query) ZRevRangeByScore(key string, max, min interface{}, withScore bool, limit ...int64) *Query
ZRevRangeByScore 返回有序集中指定分数区间内的所有的成员。有序集成员按分数值递减(从大到小)的次序排列。 param: key string param: max, min interface{} 分数区间,类型为整数或双精度浮点数,但是 -inf +inf 表示负正无穷大 param: withScore 是否返回有序集的分数, true - 返回,false - 不返回,默认不返回,结果分开在两个数组存储,但是数组下标是一一对应的,比如 member[3] 成员的分数是 score[3] param: limit offset count 游标
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client is horm-go client, including network transportation, resolving, routing etc.
|
Package client is horm-go client, including network transportation, resolving, routing etc. |
|
pool
Package pool provides the connection pool.
|
Package pool provides the connection pool. |
|
selector
Package selector determines how database chooses a backend node by service name.
|
Package selector determines how database chooses a backend node by service name. |