1 Star 0 Fork 0

ktcatv / mgohelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
intf.go 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
apsaras 提交于 2022-03-28 16:16 . initial project
package abstr
import (
"context"
"reflect"
"time"
"go.mongodb.org/mongo-driver/mongo"
)
// 数据库操作默认超时时间(5 秒)
const DefaultTimeout = 5 * time.Second
type DBHelper interface {
Aggregate(ctx context.Context, collname string, pipeline []map[string]interface{}, value interface{}) error
CountDocuments(ctx context.Context, collname string, filter map[string]interface{}) (int64, error)
CreateOne(ctx context.Context, collname string, rec interface{}) error
CreateMany(ctx context.Context, collname string, recs ...interface{}) error
FindOne(ctx context.Context, collname string, value interface{}, options ...FindOption) error
FindOneAndDelete(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
List(ctx context.Context, collname string, value interface{}, options ...FindOption) (*Page, error)
// $pull
Pull(ctx context.Context, collname string, filter map[string]interface{}, value interface{}) error
RemoveMany(ctx context.Context, collname string, filter map[string]interface{}) error
// $unset
Unmark(ctx context.Context, collname string, filter map[string]interface{}, value interface{}) error
UpdateMany(ctx context.Context, collname string, filter interface{}, update interface{}) (*mongo.UpdateResult, error)
UpdateOne(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
// 对 UpdateOne 的扩展,允许使用 $set 之外的操作符
UpdateOneMore(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
}
//Init init db session
// t 要注册的类型
type Init func(dbc DBConfig, t ...reflect.Type) error
//Decrypt decrypt db config
type Decrypt func(src string) string
type DBConfig struct {
URI string `yaml:"uri"`
PoolSize int `yaml:"poolSize"`
SSLEnabled bool `yaml:"sslEnabled"`
RootCA string `yaml:"rootCAFile"`
Timeout string `yaml:"timeout"`
VerifyPeer bool `yaml:"verifyPeer"`
}
Go
1
https://gitee.com/ktcatv/mgohelper.git
git@gitee.com:ktcatv/mgohelper.git
ktcatv
mgohelper
mgohelper
v0.1.1

搜索帮助