* add: generic cache random time offset expired. * bugfix: Csrf token should be Secure and httpOnly, but not now * fix: expose the Offset property to allow external modifications * improving the concurrency performance of random value calculation * add WithOffsetFunc to define private RandomExpireCache.offset field * fix: add seconds definition * build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.8.0 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.1 to 1.8.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.1...v1.8.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix 4907: force admin service http only * Feat: add get all tasks function (#4999) * feat: add get all tasks function * Refine Comments : admin/profile.go,bean/mock.go,config/global.go... (#5009) * Refine Comments * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * refine comments for for four files (#5011) * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * Update db.go * fix pass []any as any in variadic function by asasalint (#5012) * fix pass []any as any in variadic function * add change log * build(deps): bump go.opentelemetry.io/otel/trace from 1.7.0 to 1.8.0 (#5019) Bumps [go.opentelemetry.io/otel/trace](https://github.com/open-telemetry/opentelemetry-go) from 1.7.0 to 1.8.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.7.0...v1.8.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel/trace dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * refine comments for package core (#5014) * Refine Comments * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * refine comments * refine comments * Update db.go * refine comments for core * build(deps): bump go.opentelemetry.io/otel/exporters/stdout/stdouttrace (#5018) Bumps [go.opentelemetry.io/otel/exporters/stdout/stdouttrace](https://github.com/open-telemetry/opentelemetry-go) from 1.7.0 to 1.8.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.7.0...v1.8.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel/exporters/stdout/stdouttrace dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix 5022: Miss assiging ln to graceful Server (#5028) * prepare for releasing v2.0.5 * prepare for releasing v2.0.5 (#5032) * feat: make commands and docker compose for ORM unit tests (#5031) * feat: make commands and docker compose for ORM unit tests Signed-off-by: mango <xu.weiKyrie@foxmail.com> * add changelog Signed-off-by: mango <xu.weiKyrie@foxmail.com> Signed-off-by: mango <xu.weiKyrie@foxmail.com> * Modify comment syntax error (#5094) * fix: revise the body wrapper to handle empty body case (#5102) Fix the router.go serverHttp method, wrap the body if the request body is empty, which can avoid panic when calling the CopyBody method. Signed-off-by: chlins <chenyuzh@vmware.com> Signed-off-by: chlins <chenyuzh@vmware.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: mango <xu.weiKyrie@foxmail.com> Signed-off-by: chlins <chenyuzh@vmware.com> Co-authored-by: auual <ding@ibyte.me> Co-authored-by: Leon Ding <deen.job@qq.com> Co-authored-by: dada0z <zhang.guangda@qq.com> Co-authored-by: kevinzeng <kevinzeng@zego.im> Co-authored-by: Kevin Tsang <39397413+ktalg@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 日暮颂歌1991 <448081525@qq.com> Co-authored-by: Regan Yue <1131625869@qq.com> Co-authored-by: alingse <alingse@foxmail.com> Co-authored-by: mango <35127166+mangoGoForward@users.noreply.github.com> Co-authored-by: 王哈哈 <31426858+wanghaha-dev@users.noreply.github.com> Co-authored-by: Chlins Zhang <chlins.zhang@gmail.com>
161 lines
4.3 KiB
Go
161 lines
4.3 KiB
Go
// Copyright 2014 beego Author. All Rights Reserved.
|
|
//
|
|
// 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.
|
|
|
|
package orm
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/beego/beego/v2/client/orm/clauses"
|
|
)
|
|
|
|
// ExprSep define the expression separation
|
|
const (
|
|
ExprSep = clauses.ExprSep
|
|
)
|
|
|
|
type condValue struct {
|
|
exprs []string
|
|
args []interface{}
|
|
cond *Condition
|
|
isOr bool
|
|
isNot bool
|
|
isCond bool
|
|
isRaw bool
|
|
sql string
|
|
}
|
|
|
|
// Condition struct.
|
|
// work for WHERE conditions.
|
|
type Condition struct {
|
|
params []condValue
|
|
}
|
|
|
|
// NewCondition return new condition struct
|
|
func NewCondition() *Condition {
|
|
c := &Condition{}
|
|
return c
|
|
}
|
|
|
|
// Raw add raw sql to condition
|
|
func (c Condition) Raw(expr string, sql string) *Condition {
|
|
if len(sql) == 0 {
|
|
panic(fmt.Errorf("<Condition.Raw> sql cannot empty"))
|
|
}
|
|
c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), sql: sql, isRaw: true})
|
|
return &c
|
|
}
|
|
|
|
// And add expression to condition
|
|
func (c Condition) And(expr string, args ...interface{}) *Condition {
|
|
if expr == "" || len(args) == 0 {
|
|
panic(fmt.Errorf("<Condition.And> args cannot empty"))
|
|
}
|
|
c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args})
|
|
return &c
|
|
}
|
|
|
|
// AndNot add NOT expression to condition
|
|
func (c Condition) AndNot(expr string, args ...interface{}) *Condition {
|
|
if expr == "" || len(args) == 0 {
|
|
panic(fmt.Errorf("<Condition.AndNot> args cannot empty"))
|
|
}
|
|
c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true})
|
|
return &c
|
|
}
|
|
|
|
// AndCond combine a condition to current condition
|
|
func (c *Condition) AndCond(cond *Condition) *Condition {
|
|
if c == cond {
|
|
panic(fmt.Errorf("<Condition.AndCond> cannot use self as sub cond"))
|
|
}
|
|
|
|
c = c.clone()
|
|
|
|
if cond != nil {
|
|
c.params = append(c.params, condValue{cond: cond, isCond: true})
|
|
}
|
|
return c
|
|
}
|
|
|
|
// AndNotCond combine an AND NOT condition to current condition
|
|
func (c *Condition) AndNotCond(cond *Condition) *Condition {
|
|
c = c.clone()
|
|
if c == cond {
|
|
panic(fmt.Errorf("<Condition.AndNotCond> cannot use self as sub cond"))
|
|
}
|
|
|
|
if cond != nil {
|
|
c.params = append(c.params, condValue{cond: cond, isCond: true, isNot: true})
|
|
}
|
|
return c
|
|
}
|
|
|
|
// Or add OR expression to condition
|
|
func (c Condition) Or(expr string, args ...interface{}) *Condition {
|
|
if expr == "" || len(args) == 0 {
|
|
panic(fmt.Errorf("<Condition.Or> args cannot empty"))
|
|
}
|
|
c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isOr: true})
|
|
return &c
|
|
}
|
|
|
|
// OrNot add OR NOT expression to condition
|
|
func (c Condition) OrNot(expr string, args ...interface{}) *Condition {
|
|
if expr == "" || len(args) == 0 {
|
|
panic(fmt.Errorf("<Condition.OrNot> args cannot empty"))
|
|
}
|
|
c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true, isOr: true})
|
|
return &c
|
|
}
|
|
|
|
// OrCond combine an OR condition to current condition
|
|
func (c *Condition) OrCond(cond *Condition) *Condition {
|
|
c = c.clone()
|
|
if c == cond {
|
|
panic(fmt.Errorf("<Condition.OrCond> cannot use self as sub cond"))
|
|
}
|
|
if cond != nil {
|
|
c.params = append(c.params, condValue{cond: cond, isCond: true, isOr: true})
|
|
}
|
|
return c
|
|
}
|
|
|
|
// OrNotCond combine an OR NOT condition to current condition
|
|
func (c *Condition) OrNotCond(cond *Condition) *Condition {
|
|
c = c.clone()
|
|
if c == cond {
|
|
panic(fmt.Errorf("<Condition.OrNotCond> cannot use self as sub cond"))
|
|
}
|
|
|
|
if cond != nil {
|
|
c.params = append(c.params, condValue{cond: cond, isCond: true, isNot: true, isOr: true})
|
|
}
|
|
return c
|
|
}
|
|
|
|
// IsEmpty check the condition arguments are empty or not.
|
|
func (c *Condition) IsEmpty() bool {
|
|
return len(c.params) == 0
|
|
}
|
|
|
|
// clone clone a condition
|
|
func (c Condition) clone() *Condition {
|
|
params := make([]condValue, len(c.params))
|
|
copy(params, c.params)
|
|
c.params = params
|
|
return &c
|
|
}
|