storage

package
v0.0.0-...-a85f282 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkWriteOptions

type BulkWriteOptions struct {
	DbName      string            // 数据库名称
	CollName    string            // 集合名称
	Documents   []*bson.M         // 要写入的文档指针数组
	RetryPolicy retry.RetryPolicy // 重试策略接口
}

BulkWriteOptions 封装了BulkWriteWithRetry函数所需的参数

type FieldMapping

type FieldMapping map[string]string

FieldMapping 定义字段映射

type MongoDB

type MongoDB interface {
	// ReadByPage 读取mongo指定集合表中指定分页的数据
	ReadByPage(ctx context.Context, params PaginatedQueryParams) ([]bson.M, error)
	// BulkWriteWithRetry 带有重试策略的批量写操作
	BulkWriteWithRetry(ctx context.Context, opts *BulkWriteOptions) error
}

MongoDB mongo接口定义

type MongoDBImpl

type MongoDBImpl struct {
	// contains filtered or unexported fields
}

MongoDBImpl mongo的具体实例

func GetMongoDBInstance

func GetMongoDBInstance(ctx context.Context, retryPolicy retry.RetryPolicy, basic *options.ClientOptions,
	opts ...func(*options.ClientOptions),
) (*MongoDBImpl, error)

GetMongoDBInstance 单例方式初始化 MongoDB 实例

func (*MongoDBImpl) BulkWriteWithRetry

func (m *MongoDBImpl) BulkWriteWithRetry(ctx context.Context, opts *BulkWriteOptions) error

BulkWriteWithRetry 带有重试策略的批量写

func (*MongoDBImpl) GetBatchPool

func (m *MongoDBImpl) GetBatchPool() *pool.BatchPool[pool.BSONBatch]

GetBatchPool 返回批处理对象池

func (*MongoDBImpl) GetClient

func (m *MongoDBImpl) GetClient() *mongo.Client

GetClient 返回mongo的client

func (*MongoDBImpl) InitBatchPool

func (m *MongoDBImpl) InitBatchPool(poolSize int)

InitBatchPool 初始化对象池

func (*MongoDBImpl) ReadByPage

func (m *MongoDBImpl) ReadByPage(ctx context.Context, params PaginatedQueryParams) ([]bson.M, error)

ReadByPage 读取指定页码的数据

func (*MongoDBImpl) SetPoolSize

func (m *MongoDBImpl) SetPoolSize(defaultPoolSize int)

SetPoolSize 设置连接池大小

type PaginatedQueryParams

type PaginatedQueryParams struct {
	DbName   string
	CollName string
	Page     int64
	PageSize int64
}

PaginatedQueryParams 分页读取的选项

func (*PaginatedQueryParams) Validate

func (p *PaginatedQueryParams) Validate() error

Validate 验证PaginatedQueryParams的字段是否已被正确设置

type RenameOption

type RenameOption struct {
	Mapping      FieldMapping
	KeepOriginal bool // 是否保留原始字段
}

RenameOption 定义重命名选项

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL