xmgo

package
v0.0.0-...-3f3ae68 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyInSlice

func AnyInSlice[T AnyInSliceType](v T, slice []T) bool

func AnyPtr

func AnyPtr[T any](v T) *T

func AnySet

func AnySet[T AnyInSliceType](list []T) []T

func BatchInsertMany

func BatchInsertMany[T any](

	collection *qmgo.QmgoClient,

	ctx context.Context,

	models []T,

	batchSize int,

	opts ...opts.InsertManyOptions,
) error

BatchInsertMany 批量插入 防止一次插入太多数据 mongodb限制一次插入的数据量

func CreateIndex

func CreateIndex(ctx context.Context, qmgoClient *qmgo.QmgoClient, indexer Indexer) error

func EnumInSlice

func EnumInSlice[T EnumInSliceType](v T, slice []T) bool

func ErrIsDup

func ErrIsDup(err error) bool

ErrIsDup 判断mongo error是不是唯一索引冲突

func MustNewMongoCollection

func MustNewMongoCollection(config MongoCollectionConf, model any) *qmgo.QmgoClient

Types

type AnyInSliceType

type AnyInSliceType interface {
	string | int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | float32 | float64 | bool
}

type EnumInSliceType

type EnumInSliceType interface {
	String() string
}

type Indexer

type Indexer interface {
	GetIndexes() []opts.IndexModel
}

type MongoCollectionConf

type MongoCollectionConf struct {
	// Uri is the connection URI for the mongo instance
	// example: mongodb://$user:$pwd@$host:$port
	// example: mongodb://172.88.10.41:27017/?replicaSet=rs0
	Uri             string
	Database        string
	Collection      string
	MaxPoolSize     uint64 `json:",default=100"`
	MinPoolSize     uint64 `json:",optional"`
	SocketTimeoutMS int64  `json:",default=300000"` // default is 5 minutes
	//ReadPreference 读偏好模式
	//DefaultMode:0 默认不设置
	//PrimaryMode:1 从主节点读取数据
	//PrimaryPreferredMode:2 优先从主节点读取数据,如果主节点不可用,从从节点读取数据
	//SecondaryMode:3 从从节点读取数据
	//SecondaryPreferredMode:4 优先从从节点读取数据,如果从节点不可用,从主节点读取数据
	//NearestMode:5 从最近的成员读取数据
	ReadPreference int `json:",optional"` // default is primary
}

Jump to

Keyboard shortcuts

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