Documentation ¶
Overview ¶
Package mongos author gmfan date 2023/2/28
Package mongos author gmfan date 2023/3/2
Package mongos author gmfan date 2023/2/27
Index ¶
- Constants
- func Bucket(table string) (bucket *gridfs.Bucket, err error)
- func DB() *mongo.Database
- func DelMany(ctx context.Context, table string, filter bson.D, deletedBy int64) (err error)
- func DownloadFile(table, fid string) (data []byte, err error)
- func GetNextInt64(ctx context.Context, table string) (nextInt int64, err error)
- func InitDatabase(ctx context.Context, c Conf) (err error)
- func LoadEnvConf(c *Conf, must bool)
- func PageQuery(ctx context.Context, table string, filter bson.D, page *model.Page, res any, ...) (total int64, err error)
- func Query(ctx context.Context, table string, filter bson.D, res any, ...) error
- func QueryOne(ctx context.Context, table string, filter bson.D, res any, ...) error
- func StructureBsonD(arg any, model int) bson.D
- func ToObjectIDS(strs []string) (ids []primitive.ObjectID)
- func UploadFile(table string, data []byte) (fid string, err error)
- func UpsertMany(ctx context.Context, table string, filters []bson.D, updates any, upsert bool) (res *mongo.BulkWriteResult, err error)
- func UpsertOne(ctx context.Context, table string, filter bson.D, update any, upsert bool) (*mongo.UpdateResult, error)
- type BaseModel
- type Conf
Constants ¶
View Source
const ( MODEL1 = 1 MODEL2 = 2 MODEL3 = 3 )
Variables ¶
This section is empty.
Functions ¶
func DownloadFile ¶ added in v1.2.1
DownloadFile 下载文件
func GetNextInt64 ¶ added in v1.2.1
GetNextInt64 获取集合的自增值,此操作同时会更新集合的自增值。给定集合如果不存在 _id 为 next_int64 则会自动创建如下文档:
{ "_id":"next_int64", "next_int64":1 }
则会抛出异常
func InitDatabase ¶ added in v1.2.1
InitDatabase 初始化 Mongo
func LoadEnvConf ¶ added in v1.2.1
LoadEnvConf 加载环境变量中的 Mongo 配置,must 设置为环境变量中是否必须存在
func PageQuery ¶ added in v1.2.1
func PageQuery(ctx context.Context, table string, filter bson.D, page *model.Page, res any, projections ...string) (total int64, err error)
PageQuery 分页查询
func QueryOne ¶ added in v1.2.1
func QueryOne(ctx context.Context, table string, filter bson.D, res any, projections ...string) error
QueryOne 简化查询集合单条信息函数
func StructureBsonD ¶ added in v1.2.1
StructureBsonD 构建bson D对象同时解析含_id后缀的值为ObjectID),MODEL1 直接构建不做处理 MODEL2 跳过默认值构建,MODEL3跳过默认值其中整型的默认值为-1
func ToObjectIDS ¶ added in v1.2.1
ToObjectIDS 将十六进制字符串类型ID转换为primitive.ObjectID
func UploadFile ¶ added in v1.2.1
UploadFile 上传文件,上传成功返回 fid
Types ¶
type BaseModel ¶ added in v1.2.1
type BaseModel struct { ID primitive.ObjectID `bson:"_id,omitempty"` CreatedBy int64 `bson:"created_by,omitempty"` CreatedAt int64 `bson:"created_at,omitempty"` UpdatedBy int64 `bson:"updated_by,omitempty"` UpdatedAt int64 `bson:"updated_at,omitempty"` IsDeleted int8 `bson:"is_deleted"` }
func CreateBaseModel ¶ added in v1.2.1
Click to show internal directories.
Click to hide internal directories.