Release v2.0.5 (#5033)
* 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 (#5032) 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>
This commit is contained in:
12
client/cache/cache.go
vendored
12
client/cache/cache.go
vendored
@@ -53,21 +53,21 @@ type Cache interface {
|
||||
Get(ctx context.Context, key string) (interface{}, error)
|
||||
// GetMulti is a batch version of Get.
|
||||
GetMulti(ctx context.Context, keys []string) ([]interface{}, error)
|
||||
// Set a cached value with key and expire time.
|
||||
// Put Set a cached value with key and expire time.
|
||||
Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error
|
||||
// Delete cached value by key.
|
||||
// Should not return error if key not found
|
||||
Delete(ctx context.Context, key string) error
|
||||
// Increment a cached int value by key, as a counter.
|
||||
// Incr Increment a cached int value by key, as a counter.
|
||||
Incr(ctx context.Context, key string) error
|
||||
// Decrement a cached int value by key, as a counter.
|
||||
// Decr Decrement a cached int value by key, as a counter.
|
||||
Decr(ctx context.Context, key string) error
|
||||
// Check if a cached value exists or not.
|
||||
// IsExist Check if a cached value exists or not.
|
||||
// if key is expired, return (false, nil)
|
||||
IsExist(ctx context.Context, key string) (bool, error)
|
||||
// Clear all cache.
|
||||
// ClearAll Clear all cache.
|
||||
ClearAll(ctx context.Context) error
|
||||
// Start gc routine based on config string settings.
|
||||
// StartAndGC Start gc routine based on config string settings.
|
||||
StartAndGC(config string) error
|
||||
}
|
||||
|
||||
|
||||
75
client/cache/random_expired_cache.go
vendored
Normal file
75
client/cache/random_expired_cache.go
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// 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 cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandomExpireCacheOption implement genreate random time offset expired option
|
||||
type RandomExpireCacheOption func(*RandomExpireCache)
|
||||
|
||||
// WithOffsetFunc returns a RandomExpireCacheOption that configures the offset function
|
||||
func WithOffsetFunc(fn func() time.Duration) RandomExpireCacheOption {
|
||||
return func(cache *RandomExpireCache) {
|
||||
cache.offset = fn
|
||||
}
|
||||
}
|
||||
|
||||
// RandomExpireCache prevent cache batch invalidation
|
||||
// Cache random time offset expired
|
||||
type RandomExpireCache struct {
|
||||
Cache
|
||||
offset func() time.Duration
|
||||
}
|
||||
|
||||
// Put random time offset expired
|
||||
func (rec *RandomExpireCache) Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error {
|
||||
timeout += rec.offset()
|
||||
return rec.Cache.Put(ctx, key, val, timeout)
|
||||
}
|
||||
|
||||
// NewRandomExpireCache return random expire cache struct
|
||||
func NewRandomExpireCache(adapter Cache, opts ...RandomExpireCacheOption) Cache {
|
||||
rec := RandomExpireCache{
|
||||
Cache: adapter,
|
||||
offset: defaultExpiredFunc(),
|
||||
}
|
||||
for _, fn := range opts {
|
||||
fn(&rec)
|
||||
}
|
||||
return &rec
|
||||
}
|
||||
|
||||
// defaultExpiredFunc return a func that used to generate random time offset (range: [3s,8s)) expired
|
||||
func defaultExpiredFunc() func() time.Duration {
|
||||
const size = 5
|
||||
var randTimes [size]time.Duration
|
||||
for i := range randTimes {
|
||||
randTimes[i] = time.Duration(i+3) * time.Second
|
||||
}
|
||||
// shuffle values
|
||||
for i := range randTimes {
|
||||
n := rand.Intn(size)
|
||||
randTimes[i], randTimes[n] = randTimes[n], randTimes[i]
|
||||
}
|
||||
var i uint64
|
||||
return func() time.Duration {
|
||||
return randTimes[atomic.AddUint64(&i, 1)%size]
|
||||
}
|
||||
}
|
||||
99
client/cache/random_expired_cache_test.go
vendored
Normal file
99
client/cache/random_expired_cache_test.go
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
// 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 cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRandomExpireCache(t *testing.T) {
|
||||
bm, err := NewCache("memory", `{"interval":20}`)
|
||||
assert.Nil(t, err)
|
||||
|
||||
cache := NewRandomExpireCache(bm)
|
||||
// should not be nil
|
||||
assert.NotNil(t, cache.(*RandomExpireCache).offset)
|
||||
|
||||
timeoutDuration := 3 * time.Second
|
||||
|
||||
if err = cache.Put(context.Background(), "Leon Ding", 22, timeoutDuration); err != nil {
|
||||
t.Error("set Error", err)
|
||||
}
|
||||
|
||||
// testing random expire cache
|
||||
time.Sleep(timeoutDuration + 3 + time.Second)
|
||||
|
||||
if res, _ := cache.IsExist(context.Background(), "Leon Ding"); !res {
|
||||
t.Error("check err")
|
||||
}
|
||||
|
||||
if v, _ := cache.Get(context.Background(), "Leon Ding"); v.(int) != 22 {
|
||||
t.Error("get err")
|
||||
}
|
||||
|
||||
cache.Delete(context.Background(), "Leon Ding")
|
||||
res, _ := cache.IsExist(context.Background(), "Leon Ding")
|
||||
assert.False(t, res)
|
||||
|
||||
assert.Nil(t, cache.Put(context.Background(), "Leon Ding", "author", timeoutDuration))
|
||||
|
||||
cache.Delete(context.Background(), "astaxie")
|
||||
res, _ = cache.IsExist(context.Background(), "astaxie")
|
||||
assert.False(t, res)
|
||||
|
||||
assert.Nil(t, cache.Put(context.Background(), "astaxie", "author", timeoutDuration))
|
||||
|
||||
res, _ = cache.IsExist(context.Background(), "astaxie")
|
||||
assert.True(t, res)
|
||||
|
||||
v, _ := cache.Get(context.Background(), "astaxie")
|
||||
assert.Equal(t, "author", v)
|
||||
|
||||
assert.Nil(t, cache.Put(context.Background(), "astaxie1", "author1", timeoutDuration))
|
||||
|
||||
res, _ = cache.IsExist(context.Background(), "astaxie1")
|
||||
assert.True(t, res)
|
||||
|
||||
vv, _ := cache.GetMulti(context.Background(), []string{"astaxie", "astaxie1"})
|
||||
assert.Equal(t, 2, len(vv))
|
||||
assert.Equal(t, "author", vv[0])
|
||||
assert.Equal(t, "author1", vv[1])
|
||||
|
||||
vv, err = cache.GetMulti(context.Background(), []string{"astaxie0", "astaxie1"})
|
||||
assert.Equal(t, 2, len(vv))
|
||||
assert.Nil(t, vv[0])
|
||||
assert.Equal(t, "author1", vv[1])
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "key isn't exist"))
|
||||
}
|
||||
|
||||
func TestWithOffsetFunc(t *testing.T) {
|
||||
bm, err := NewCache("memory", `{"interval":20}`)
|
||||
assert.Nil(t, err)
|
||||
|
||||
magic := -time.Duration(rand.Int())
|
||||
cache := NewRandomExpireCache(bm, WithOffsetFunc(func() time.Duration {
|
||||
return magic
|
||||
}))
|
||||
// offset should return the magic value
|
||||
assert.Equal(t, magic, cache.(*RandomExpireCache).offset())
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func WithEnableCookie(enable bool) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnableCookie will adds UA in all subsequent request
|
||||
// WithUserAgent will adds UA in all subsequent request
|
||||
func WithUserAgent(userAgent string) ClientOption {
|
||||
return func(client *Client) {
|
||||
client.Setting.UserAgent = userAgent
|
||||
@@ -105,7 +105,7 @@ func WithCookie(cookie *http.Cookie) BeegoHTTPRequestOption {
|
||||
}
|
||||
}
|
||||
|
||||
// Withtokenfactory adds a custom function to set Authorization
|
||||
// WithTokenFactory adds a custom function to set Authorization
|
||||
func WithTokenFactory(tokenFactory func() string) BeegoHTTPRequestOption {
|
||||
return func(request *BeegoHTTPRequest) {
|
||||
t := tokenFactory()
|
||||
|
||||
@@ -264,7 +264,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// create insert sql preparation statement object.
|
||||
// PrepareInsert create insert sql preparation statement object.
|
||||
func (d *dbBase) PrepareInsert(ctx context.Context, q dbQuerier, mi *modelInfo) (stmtQuerier, string, error) {
|
||||
Q := d.ins.TableQuote()
|
||||
|
||||
@@ -290,7 +290,7 @@ func (d *dbBase) PrepareInsert(ctx context.Context, q dbQuerier, mi *modelInfo)
|
||||
return stmt, query, err
|
||||
}
|
||||
|
||||
// insert struct with prepared statement and given struct reflect value.
|
||||
// InsertStmt insert struct with prepared statement and given struct reflect value.
|
||||
func (d *dbBase) InsertStmt(ctx context.Context, stmt stmtQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location) (int64, error) {
|
||||
values, _, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, nil, tz)
|
||||
if err != nil {
|
||||
@@ -371,7 +371,7 @@ func (d *dbBase) Read(ctx context.Context, q dbQuerier, mi *modelInfo, ind refle
|
||||
return nil
|
||||
}
|
||||
|
||||
// execute insert sql dbQuerier with given struct reflect.Value.
|
||||
// Insert execute insert sql dbQuerier with given struct reflect.Value.
|
||||
func (d *dbBase) Insert(ctx context.Context, q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location) (int64, error) {
|
||||
names := make([]string, 0, len(mi.fields.dbcols))
|
||||
values, autoFields, err := d.collectValues(mi, ind, mi.fields.dbcols, false, true, &names, tz)
|
||||
@@ -390,7 +390,7 @@ func (d *dbBase) Insert(ctx context.Context, q dbQuerier, mi *modelInfo, ind ref
|
||||
return id, err
|
||||
}
|
||||
|
||||
// multi-insert sql with given slice struct reflect.Value.
|
||||
// InsertMulti multi-insert sql with given slice struct reflect.Value.
|
||||
func (d *dbBase) InsertMulti(ctx context.Context, q dbQuerier, mi *modelInfo, sind reflect.Value, bulk int, tz *time.Location) (int64, error) {
|
||||
var (
|
||||
cnt int64
|
||||
@@ -454,7 +454,7 @@ func (d *dbBase) InsertMulti(ctx context.Context, q dbQuerier, mi *modelInfo, si
|
||||
return cnt, err
|
||||
}
|
||||
|
||||
// execute insert sql with given struct and given values.
|
||||
// InsertValue execute insert sql with given struct and given values.
|
||||
// insert the given values, not the field values in struct.
|
||||
func (d *dbBase) InsertValue(ctx context.Context, q dbQuerier, mi *modelInfo, isMulti bool, names []string, values []interface{}) (int64, error) {
|
||||
Q := d.ins.TableQuote()
|
||||
@@ -612,7 +612,7 @@ func (d *dbBase) InsertOrUpdate(ctx context.Context, q dbQuerier, mi *modelInfo,
|
||||
return id, err
|
||||
}
|
||||
|
||||
// execute update sql dbQuerier with given struct reflect.Value.
|
||||
// Update execute update sql dbQuerier with given struct reflect.Value.
|
||||
func (d *dbBase) Update(ctx context.Context, q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location, cols []string) (int64, error) {
|
||||
pkName, pkValue, ok := getExistPk(mi, ind)
|
||||
if !ok {
|
||||
@@ -677,7 +677,7 @@ func (d *dbBase) Update(ctx context.Context, q dbQuerier, mi *modelInfo, ind ref
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// execute delete sql dbQuerier with given struct reflect.Value.
|
||||
// Delete execute delete sql dbQuerier with given struct reflect.Value.
|
||||
// delete index is pk.
|
||||
func (d *dbBase) Delete(ctx context.Context, q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Location, cols []string) (int64, error) {
|
||||
var whereCols []string
|
||||
@@ -725,7 +725,7 @@ func (d *dbBase) Delete(ctx context.Context, q dbQuerier, mi *modelInfo, ind ref
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// update table-related record by querySet.
|
||||
// UpdateBatch update table-related record by querySet.
|
||||
// need querySet not struct reflect.Value to update related records.
|
||||
func (d *dbBase) UpdateBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, params Params, tz *time.Location) (int64, error) {
|
||||
columns := make([]string, 0, len(params))
|
||||
@@ -843,7 +843,7 @@ func (d *dbBase) deleteRels(ctx context.Context, q dbQuerier, mi *modelInfo, arg
|
||||
return nil
|
||||
}
|
||||
|
||||
// delete table-related records.
|
||||
// DeleteBatch delete table-related records.
|
||||
func (d *dbBase) DeleteBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, tz *time.Location) (int64, error) {
|
||||
tables := newDbTables(mi, d.ins)
|
||||
tables.skipEnd = true
|
||||
@@ -920,7 +920,7 @@ func (d *dbBase) DeleteBatch(ctx context.Context, q dbQuerier, qs *querySet, mi
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// read related records.
|
||||
// ReadBatch read related records.
|
||||
func (d *dbBase) ReadBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, container interface{}, tz *time.Location, cols []string) (int64, error) {
|
||||
val := reflect.ValueOf(container)
|
||||
ind := reflect.Indirect(val)
|
||||
@@ -1145,7 +1145,7 @@ func (d *dbBase) ReadBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *m
|
||||
return cnt, nil
|
||||
}
|
||||
|
||||
// excute count sql and return count result int64.
|
||||
// Count excute count sql and return count result int64.
|
||||
func (d *dbBase) Count(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, tz *time.Location) (cnt int64, err error) {
|
||||
tables := newDbTables(mi, d.ins)
|
||||
tables.parseRelated(qs.related, qs.relDepth)
|
||||
@@ -1173,7 +1173,7 @@ func (d *dbBase) Count(ctx context.Context, q dbQuerier, qs *querySet, mi *model
|
||||
return
|
||||
}
|
||||
|
||||
// generate sql with replacing operator string placeholders and replaced values.
|
||||
// GenerateOperatorSQL generate sql with replacing operator string placeholders and replaced values.
|
||||
func (d *dbBase) GenerateOperatorSQL(mi *modelInfo, fi *fieldInfo, operator string, args []interface{}, tz *time.Location) (string, []interface{}) {
|
||||
var sql string
|
||||
params := getFlatParams(fi, args, tz)
|
||||
@@ -1233,7 +1233,7 @@ func (d *dbBase) GenerateOperatorSQL(mi *modelInfo, fi *fieldInfo, operator stri
|
||||
return sql, params
|
||||
}
|
||||
|
||||
// gernerate sql string with inner function, such as UPPER(text).
|
||||
// GenerateOperatorLeftCol gernerate sql string with inner function, such as UPPER(text).
|
||||
func (d *dbBase) GenerateOperatorLeftCol(*fieldInfo, string, *string) {
|
||||
// default not use
|
||||
}
|
||||
@@ -1615,7 +1615,7 @@ setValue:
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// query sql, read values , save to *[]ParamList.
|
||||
// ReadValues query sql, read values , save to *[]ParamList.
|
||||
func (d *dbBase) ReadValues(ctx context.Context, q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition, exprs []string, container interface{}, tz *time.Location) (int64, error) {
|
||||
var (
|
||||
maps []Params
|
||||
@@ -1788,7 +1788,7 @@ func (d *dbBase) ReadValues(ctx context.Context, q dbQuerier, qs *querySet, mi *
|
||||
return cnt, nil
|
||||
}
|
||||
|
||||
// flag of update joined record.
|
||||
// SupportUpdateJoin flag of update joined record.
|
||||
func (d *dbBase) SupportUpdateJoin() bool {
|
||||
return true
|
||||
}
|
||||
@@ -1797,12 +1797,12 @@ func (d *dbBase) MaxLimit() uint64 {
|
||||
return 18446744073709551615
|
||||
}
|
||||
|
||||
// return quote.
|
||||
// TableQuote return quote.
|
||||
func (d *dbBase) TableQuote() string {
|
||||
return "`"
|
||||
}
|
||||
|
||||
// replace value placeholder in parametered sql string.
|
||||
// ReplaceMarks replace value placeholder in parametered sql string.
|
||||
func (d *dbBase) ReplaceMarks(query *string) {
|
||||
// default use `?` as mark, do nothing
|
||||
}
|
||||
@@ -1817,22 +1817,22 @@ func (d *dbBase) setval(ctx context.Context, db dbQuerier, mi *modelInfo, autoFi
|
||||
return nil
|
||||
}
|
||||
|
||||
// convert time from db.
|
||||
// TimeFromDB convert time from db.
|
||||
func (d *dbBase) TimeFromDB(t *time.Time, tz *time.Location) {
|
||||
*t = t.In(tz)
|
||||
}
|
||||
|
||||
// convert time to db.
|
||||
// TimeToDB convert time to db.
|
||||
func (d *dbBase) TimeToDB(t *time.Time, tz *time.Location) {
|
||||
*t = t.In(tz)
|
||||
}
|
||||
|
||||
// get database types.
|
||||
// DbTypes get database types.
|
||||
func (d *dbBase) DbTypes() map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// gt all tables.
|
||||
// GetTables gt all tables.
|
||||
func (d *dbBase) GetTables(db dbQuerier) (map[string]bool, error) {
|
||||
tables := make(map[string]bool)
|
||||
query := d.ins.ShowTablesQuery()
|
||||
@@ -1857,7 +1857,7 @@ func (d *dbBase) GetTables(db dbQuerier) (map[string]bool, error) {
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
// get all cloumns in table.
|
||||
// GetColumns get all cloumns in table.
|
||||
func (d *dbBase) GetColumns(ctx context.Context, db dbQuerier, table string) (map[string][3]string, error) {
|
||||
columns := make(map[string][3]string)
|
||||
query := d.ins.ShowColumnsQuery(table)
|
||||
|
||||
@@ -45,7 +45,7 @@ func MockMethod(method string, resp ...interface{}) *Mock {
|
||||
return NewMock(NewSimpleCondition("", method), resp, nil)
|
||||
}
|
||||
|
||||
// MockOrmRead support orm.Read and orm.ReadWithCtx
|
||||
// MockRead support orm.Read and orm.ReadWithCtx
|
||||
// cb is used to mock read data from DB
|
||||
func MockRead(tableName string, cb func(data interface{}), err error) *Mock {
|
||||
return NewMock(NewSimpleCondition(tableName, "ReadWithCtx"), []interface{}{err}, func(inv *orm.Invocation) {
|
||||
|
||||
Reference in New Issue
Block a user