master v1.0.44
李光春 2 years ago
parent a383dc98c2
commit 3b662a2351

@ -4,7 +4,7 @@ import (
"github.com/uptrace/bun"
)
type ConfigBunClient struct {
type BunClientConfig struct {
Dns string // 地址
}
@ -12,5 +12,5 @@ type ConfigBunClient struct {
// https://bun.uptrace.dev/
type BunClient struct {
Db *bun.DB // 驱动
config *ConfigBunClient // 配置
config *BunClientConfig // 配置
}

@ -1,3 +1,3 @@
package dorm
const Version = "1.0.43"
const Version = "1.0.44"

@ -16,14 +16,12 @@ type GormClientFun func() *GormClient
// string 表名
type GormClientTableFun func() (*GormClient, string)
type ConfigGormClient struct {
type GormClientConfig struct {
Dns string // 地址
LogStatus bool // 日志 - 状态
LogPath string // 日志 - 路径
LogSlow int64 // 日志 - 慢SQL阈值
LogLevel string // 日志 - 级别
LogNotFoundError bool // 日志 - 忽略ErrRecordNotFound记录未找到错误
LogColorful bool // 日志 - 禁用彩色打印
ConnSetMaxIdle int // 连接 - 设置空闲连接池中连接的最大数量
ConnSetMaxOpen int // 连接 - 设置打开数据库连接的最大数量
ConnSetConnMaxLifetime int64 // 连接 - 设置了连接可复用的最大时间
@ -33,7 +31,7 @@ type ConfigGormClient struct {
// https://gorm.io/
type GormClient struct {
Db *gorm.DB // 驱动
config *ConfigGormClient // 配置
config *GormClientConfig // 配置
}
type writer struct{}

@ -10,7 +10,7 @@ import (
"time"
)
func NewGormMysqlClient(config *ConfigGormClient) (*GormClient, error) {
func NewGormMysqlClient(config *GormClientConfig) (*GormClient, error) {
var err error
c := &GormClient{config: config}
@ -41,10 +41,10 @@ func NewGormMysqlClient(config *ConfigGormClient) (*GormClient, error) {
Logger: logger.New(
writer{},
logger.Config{
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: c.config.LogNotFoundError, // 忽略ErrRecordNotFound记录未找到错误
Colorful: c.config.LogColorful, // 禁用彩色打印
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound记录未找到错误
Colorful: true, // 禁用彩色打印
},
),
NowFunc: func() time.Time {

@ -10,7 +10,7 @@ import (
"time"
)
func NewGormPostgresClient(config *ConfigGormClient) (*GormClient, error) {
func NewGormPostgresClient(config *GormClientConfig) (*GormClient, error) {
var err error
c := &GormClient{}
@ -42,10 +42,10 @@ func NewGormPostgresClient(config *ConfigGormClient) (*GormClient, error) {
Logger: logger.New(
writer{},
logger.Config{
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: c.config.LogNotFoundError, // 忽略ErrRecordNotFound记录未找到错误
Colorful: c.config.LogColorful, // 禁用彩色打印
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound记录未找到错误
Colorful: true, // 禁用彩色打印
},
),
NowFunc: func() time.Time {
@ -89,7 +89,7 @@ func NewGormPostgresClient(config *ConfigGormClient) (*GormClient, error) {
return c, nil
}
func NewGormPostgresqlClient(config *ConfigGormClient) (*GormClient, error) {
func NewGormPostgresqlClient(config *GormClientConfig) (*GormClient, error) {
var err error
c := &GormClient{}
@ -121,10 +121,10 @@ func NewGormPostgresqlClient(config *ConfigGormClient) (*GormClient, error) {
Logger: logger.New(
writer{},
logger.Config{
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: c.config.LogNotFoundError, // 忽略ErrRecordNotFound记录未找到错误
Colorful: c.config.LogColorful, // 禁用彩色打印
SlowThreshold: slowThreshold, // 慢SQL阈值
LogLevel: logLevel, // 日志级别
IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound记录未找到错误
Colorful: true, // 禁用彩色打印
},
),
NowFunc: func() time.Time {

@ -26,6 +26,11 @@ func (cc *MongoCollectionOptions) DeleteMany(ctx context.Context, filter interfa
return cc.dbCollection.DeleteMany(ctx, filter, opts...)
}
// ReplaceOne 替换一个文档
func (cc *MongoCollectionOptions) ReplaceOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error) {
return cc.dbCollection.ReplaceOne(ctx, filter, update, opts...)
}
// UpdateOne 更新一个文档
func (cc *MongoCollectionOptions) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
return cc.dbCollection.UpdateOne(ctx, filter, update, opts...)
@ -45,3 +50,8 @@ func (cc *MongoCollectionOptions) FindOne(ctx context.Context, filter interface{
func (cc *MongoCollectionOptions) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error) {
return cc.dbCollection.Find(ctx, filter, opts...)
}
// Aggregate 统计分析
func (cc *MongoCollectionOptions) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error) {
return cc.dbCollection.Aggregate(ctx, pipeline, opts...)
}

@ -25,6 +25,11 @@ func (csc *MongoSessionCollectionOptions) DeleteMany(filter interface{}, opts ..
return csc.dbCollection.DeleteMany(csc.sessionContext, filter, opts...)
}
// ReplaceOne 替换一个文档
func (csc *MongoSessionCollectionOptions) ReplaceOne(filter interface{}, update interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error) {
return csc.dbCollection.ReplaceOne(csc.sessionContext, filter, update, opts...)
}
// UpdateOne 更新一个文档
func (csc *MongoSessionCollectionOptions) UpdateOne(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
return csc.dbCollection.UpdateOne(csc.sessionContext, filter, update, opts...)
@ -44,3 +49,8 @@ func (csc *MongoSessionCollectionOptions) FindOne(filter interface{}, opts ...*o
func (csc *MongoSessionCollectionOptions) Find(filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error) {
return csc.dbCollection.Find(csc.sessionContext, filter, opts...)
}
// Aggregate 统计分析
func (csc *MongoSessionCollectionOptions) Aggregate(pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error) {
return csc.dbCollection.Aggregate(csc.sessionContext, pipeline, opts...)
}

@ -11,7 +11,7 @@ import (
// RedisClientFun *RedisClient 驱动
type RedisClientFun func() *RedisClient
type ConfigRedisClient struct {
type RedisClientConfig struct {
Addr string // 地址
Password string // 密码
DB int // 数据库
@ -23,10 +23,10 @@ type ConfigRedisClient struct {
// https://redis.uptrace.dev/
type RedisClient struct {
Db *redis.Client // 驱动
config *ConfigRedisClient // 配置
config *RedisClientConfig // 配置
}
func NewRedisClient(config *ConfigRedisClient) (*RedisClient, error) {
func NewRedisClient(config *RedisClientConfig) (*RedisClient, error) {
c := &RedisClient{}
c.config = config

@ -4,13 +4,13 @@ import (
"xorm.io/xorm"
)
type ConfigXormClient struct {
type XormClientConfigXorm struct {
Dns string // 地址
}
// XormClient
// https://xorm.io/
type XormClient struct {
Db *xorm.Engine // 驱动
config *ConfigXormClient // 配置
Db *xorm.Engine // 驱动
config *XormClientConfigXorm // 配置
}

@ -7,7 +7,7 @@ import (
"xorm.io/xorm"
)
func NewXormMysqlClient(config *ConfigXormClient) (*XormClient, error) {
func NewXormMysqlClient(config *XormClientConfigXorm) (*XormClient, error) {
var err error
c := &XormClient{config: config}

@ -7,7 +7,7 @@ import (
"xorm.io/xorm"
)
func NewXormPostgresClient(config *ConfigXormClient) (*XormClient, error) {
func NewXormPostgresClient(config *XormClientConfigXorm) (*XormClient, error) {
var err error
c := &XormClient{config: config}

Loading…
Cancel
Save