* 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>
122 lines
3.9 KiB
Go
122 lines
3.9 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 (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
)
|
|
|
|
// DriverType database driver constant int.
|
|
type DriverType orm.DriverType
|
|
|
|
// Enum the Database driver
|
|
const (
|
|
DRMySQL = DriverType(orm.DRMySQL)
|
|
DRSqlite = DriverType(orm.DRSqlite) // sqlite
|
|
DROracle = DriverType(orm.DROracle) // oracle
|
|
DRPostgres = DriverType(orm.DRPostgres) // pgsql
|
|
DRTiDB = DriverType(orm.DRTiDB) // TiDB
|
|
)
|
|
|
|
type DB orm.DB
|
|
|
|
func (d *DB) Begin() (*sql.Tx, error) {
|
|
return (*orm.DB)(d).Begin()
|
|
}
|
|
|
|
func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) {
|
|
return (*orm.DB)(d).BeginTx(ctx, opts)
|
|
}
|
|
|
|
func (d *DB) Prepare(query string) (*sql.Stmt, error) {
|
|
return (*orm.DB)(d).Prepare(query)
|
|
}
|
|
|
|
func (d *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
|
|
return (*orm.DB)(d).PrepareContext(ctx, query)
|
|
}
|
|
|
|
func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
|
|
return (*orm.DB)(d).Exec(query, args...)
|
|
}
|
|
|
|
func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
|
|
return (*orm.DB)(d).ExecContext(ctx, query, args...)
|
|
}
|
|
|
|
func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
|
|
return (*orm.DB)(d).Query(query, args...)
|
|
}
|
|
|
|
func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
|
|
return (*orm.DB)(d).QueryContext(ctx, query, args...)
|
|
}
|
|
|
|
func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row {
|
|
return (*orm.DB)(d).QueryRow(query, args...)
|
|
}
|
|
|
|
func (d *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
|
|
return (*orm.DB)(d).QueryRowContext(ctx, query, args...)
|
|
}
|
|
|
|
// AddAliasWthDB add a aliasName for the drivename
|
|
func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error {
|
|
return orm.AddAliasWthDB(aliasName, driverName, db)
|
|
}
|
|
|
|
// RegisterDataBase Setting the database connect params. Use the database driver self dataSource args.
|
|
func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error {
|
|
opts := make([]orm.DBOption, 0, 2)
|
|
if len(params) > 0 {
|
|
opts = append(opts, orm.MaxIdleConnections(params[0]))
|
|
}
|
|
|
|
if len(params) > 1 {
|
|
opts = append(opts, orm.MaxOpenConnections(params[1]))
|
|
}
|
|
return orm.RegisterDataBase(aliasName, driverName, dataSource, opts...)
|
|
}
|
|
|
|
// RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.
|
|
func RegisterDriver(driverName string, typ DriverType) error {
|
|
return orm.RegisterDriver(driverName, orm.DriverType(typ))
|
|
}
|
|
|
|
// SetDataBaseTZ Change the database default used timezone
|
|
func SetDataBaseTZ(aliasName string, tz *time.Location) error {
|
|
return orm.SetDataBaseTZ(aliasName, tz)
|
|
}
|
|
|
|
// SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name
|
|
func SetMaxIdleConns(aliasName string, maxIdleConns int) {
|
|
orm.SetMaxIdleConns(aliasName, maxIdleConns)
|
|
}
|
|
|
|
// SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name
|
|
func SetMaxOpenConns(aliasName string, maxOpenConns int) {
|
|
orm.SetMaxOpenConns(aliasName, maxOpenConns)
|
|
}
|
|
|
|
// GetDB Get *sql.DB from registered database by db alias name.
|
|
// Use "default" as alias name if you not set.
|
|
func GetDB(aliasNames ...string) (*sql.DB, error) {
|
|
return orm.GetDB(aliasNames...)
|
|
}
|