mongo

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectCreatePool

func InjectCreatePool(fun CreateConnectFunc)

InjectCreatePool 注入连接池的创建过程 connect 连接mongo配置 可以为空,如果为空需要自己创建数据连接查询配置后返回 fun 回调函数返回mongo连接配置

Types

type CreateConnectFunc

type CreateConnectFunc func(*MongoDB) []MongoConnect

CreateConnectFunc 创建连接

type DBInfo

type DBInfo struct {
	Client   *mongo.Client
	Database *mongo.Database
	Config   MongoConnect
}

DBInfo

func (*DBInfo) Close

func (d *DBInfo) Close()

Close

type Host

type Host struct {
	Hst  string `json:"host"`
	Port string `json:"port"`
}

Host

type MongoConnect

type MongoConnect struct {
	Name           string  `json:"name"`
	UserName       string  `json:"userName"`
	Password       string  `json:"password"`
	Hosts          []Host  `json:"hosts"`
	Database       string  `json:"database"`
	Option         Options `json:"option"`
	ConnectTimeout int     `json:"connectTimeout"`
	ExecuteTimeout int     `json:"executeTimeout"`
}

MongoConnect

func (MongoConnect) String

func (m MongoConnect) String() string

String

type MongoDB

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

MongoDB

func NewDB

func NewDB() *MongoDB

NewDB

func (*MongoDB) SetDB

func (db *MongoDB) SetDB(connectName, databaseName string) *MongoDB

SetDB 设置连接名和数据库名称

func (*MongoDB) SetPool

func (db *MongoDB) SetPool(pool MongoPooler) *MongoDB

SetPool 设置连接池

type MongoPool

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

MongoPool

func (*MongoPool) AddConnect

func (m *MongoPool) AddConnect(connect MongoConnect)

AddConnect 添加连接

func (*MongoPool) AddConnects

func (m *MongoPool) AddConnects(connects []MongoConnect)

AddConnects 添加多个连接

func (*MongoPool) GetDB

func (m *MongoPool) GetDB(connectName string) *DBInfo

GetDB

func (*MongoPool) Init

func (m *MongoPool) Init(connects []MongoConnect)

Init

type MongoPooler

type MongoPooler interface {
	GetDB(connectName string) *DBInfo
	Init(connect []MongoConnect)
	AddConnect(connect MongoConnect)
	AddConnects(connects []MongoConnect)
}

MongoPooler

func NewPool

func NewPool(config MongoConnect) MongoPooler

NewPool 初始化数据库连接

func NewPools

func NewPools(configs []MongoConnect) MongoPooler

NewPools 初始化多数据库连接

type Options

type Options struct {
	ReplicaSet       string `json:"replicaSet"`
	SlaveOk          bool   `json:"slaveOk"`
	Safe             bool   `json:"safe"`
	WtimeoutMS       int64  `json:"wtimeoutMS"`
	ConnectTimeoutMS int64  `json:"connectTimeoutMS"`
	SocketTimeoutMS  int64  `json:"socketTimeoutMS"`
	MaxPoolSize      int    `json:"maxPoolSize"`
	MinPoolSize      int    `json:"minPoolSize"`
	MaxIdleTimeMS    int64  `json:"maxIdleTimeMS"`
}

Options

type Table

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

Table 操作表

func (*Table) Aggregate

func (t *Table) Aggregate(pipeline interface{}, result interface{})

Aggregate

func (*Table) CreateCollection

func (t *Table) CreateCollection()

CreateCollection 创建集合

func (*Table) DeleteMany

func (t *Table) DeleteMany(filter interface{}) *mongo.DeleteResult

DeleteMany

func (*Table) DeleteOne

func (t *Table) DeleteOne(filter interface{}) *mongo.DeleteResult

DeleteOne

func (*Table) Find

func (t *Table) Find(filter interface{}, result interface{})

Find

func (*Table) FindOne

func (t *Table) FindOne(filter interface{}, result interface{})

FindOne

func (*Table) InsertMany

func (t *Table) InsertMany(documents []interface{}) []primitive.ObjectID

InsertMany

func (*Table) InsertOne

func (t *Table) InsertOne(document interface{}) primitive.ObjectID

InsertOne

func (*Table) Pager

func (t *Table) Pager(filter interface{}, result interface{}, page, pageSize int64)

Pager

func (*Table) ReplaceOne

func (t *Table) ReplaceOne(filter interface{}, update interface{}) *mongo.UpdateResult

ReplaceOne

func (*Table) SetDB

func (t *Table) SetDB(db *MongoDB)

SetDB 设置数据库

func (*Table) UpdateByID

func (t *Table) UpdateByID(id interface{}, update interface{}) *mongo.UpdateResult

UpdateByID

func (*Table) UpdateMany

func (t *Table) UpdateMany(filter interface{}, update interface{}) *mongo.UpdateResult

UpdateMany

func (*Table) UpdateOne

func (t *Table) UpdateOne(filter interface{}, update interface{}) *mongo.UpdateResult

UpdateOne

type Tabler

type Tabler interface {
	SetDB(db *MongoDB)
	InsertOne(document interface{}) primitive.ObjectID
	InsertMany(documents []interface{}) []primitive.ObjectID
	UpdateOne(filter interface{}, update interface{}) *mongo.UpdateResult
	UpdateMany(filter interface{}, update interface{}) *mongo.UpdateResult
	UpdateByID(id interface{}, update interface{}) *mongo.UpdateResult
	ReplaceOne(filter interface{}, update interface{}) *mongo.UpdateResult
	DeleteOne(filter interface{}) *mongo.DeleteResult
	DeleteMany(filter interface{}) *mongo.DeleteResult
	FindOne(filter interface{}, result interface{})
	Find(filter interface{}, result interface{})
	Pager(filter interface{}, result interface{}, page, pageSize int64)
	Aggregate(pipeline interface{}, result interface{})
}

Tabler

func NewModel

func NewModel(dbName, tableName string) Tabler

NewModel

func NewModelByConnectName

func NewModelByConnectName(connectName, dbName, tableName string) Tabler

NewModelByConnectName 新建一个模型

func NewTable

func NewTable(db *MongoDB, tableName string) Tabler

NewTable 初始化表

Jump to

Keyboard shortcuts

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