local

package
v0.0.0-...-cb472e6 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayDecodeValue

func ArrayDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

ArrayDecodeValue is the ValueDecoderFunc for array types.

func EmptyInterfaceDecodeValue

func EmptyInterfaceDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

EmptyInterfaceDecodeValue is the ValueDecoderFunc for interface{}.

func GenSessionID

func GenSessionID() (string, error)

func GenTxnCableAndSetHeader

func GenTxnCableAndSetHeader(header http.Header, opts ...metadata.TxnOption) (*metadata.TxnCapable, error)

generate a session id and set it to header.

func MapDecodeValue

func MapDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

MapDecodeValue is the ValueDecoderFunc for map[string]* types.

func SliceDecodeValue

func SliceDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error

SliceDecodeValue is the ValueDecoderFunc for slice types.

Types

type Collection

type Collection struct {
	*Mongo
	// contains filtered or unexported fields
}

Collection implement client.Collection interface

func (*Collection) AddColumn

func (c *Collection) AddColumn(ctx context.Context, column string, value interface{}) error

AddColumn add a new column for the collection

func (*Collection) AggregateAll

func (c *Collection) AggregateAll(ctx context.Context, pipeline interface{}, result interface{}) error

AggregateAll aggregate all operation

func (*Collection) AggregateOne

func (c *Collection) AggregateOne(ctx context.Context, pipeline interface{}, result interface{}) error

AggregateOne aggregate one operation

func (*Collection) CreateIndex

func (c *Collection) CreateIndex(ctx context.Context, index types.Index) error

CreateIndex 创建索引

func (*Collection) Delete

func (c *Collection) Delete(ctx context.Context, filter types.Filter) error

Delete 删除数据

func (*Collection) Distinct

func (c *Collection) Distinct(ctx context.Context, field string, filter types.Filter) ([]interface{}, error)

Distinct Finds the distinct values for a specified field across a single collection or view and returns the results in an field the field for which to return distinct values. filter query that specifies the documents from which to retrieve the distinct values.

func (*Collection) DropColumn

func (c *Collection) DropColumn(ctx context.Context, field string) error

DropColumn remove a column by the name

func (*Collection) DropColumns

func (c *Collection) DropColumns(ctx context.Context, filter types.Filter, fields []string) error

DropColumns remove many columns by the name

func (*Collection) DropDocsColumn

func (c *Collection) DropDocsColumn(ctx context.Context, field string, filter types.Filter) error

DropDocsColumn remove a column by the name for doc use filter

func (*Collection) DropIndex

func (c *Collection) DropIndex(ctx context.Context, indexName string) error

DropIndex remove index by name

func (*Collection) Find

func (c *Collection) Find(filter types.Filter) types.Find

Find 查询多个并反序列化到 Result

func (*Collection) Indexes

func (c *Collection) Indexes(ctx context.Context) ([]types.Index, error)

Indexes get all indexes for the collection

func (*Collection) Insert

func (c *Collection) Insert(ctx context.Context, docs interface{}) error

Insert 插入数据, docs 可以为 单个数据 或者 多个数据

func (*Collection) RenameColumn

func (c *Collection) RenameColumn(ctx context.Context, oldName, newColumn string) error

RenameColumn rename a column for the collection

func (*Collection) Update

func (c *Collection) Update(ctx context.Context, filter types.Filter, doc interface{}) error

Update 更新数据

func (*Collection) UpdateMultiModel

func (c *Collection) UpdateMultiModel(ctx context.Context, filter types.Filter, updateModel ...types.ModeUpdate) error

UpdateMultiModel 根据不同的操作符去更新数据

func (*Collection) Upsert

func (c *Collection) Upsert(ctx context.Context, filter types.Filter, doc interface{}) error

Upsert 数据存在更新数据,否则新加数据

type Find

type Find struct {
	*Collection
	// contains filtered or unexported fields
}

Find define a find operation

func (*Find) All

func (f *Find) All(ctx context.Context, result interface{}) error

All 查询多个

func (*Find) Count

func (f *Find) Count(ctx context.Context) (uint64, error)

Count 统计数量(非事务)

func (*Find) Fields

func (f *Find) Fields(fields ...string) types.Find

Fields 查询字段

func (*Find) Limit

func (f *Find) Limit(limit uint64) types.Find

Limit 查询限制

func (*Find) One

func (f *Find) One(ctx context.Context, result interface{}) error

One 查询一个

func (*Find) Sort

func (f *Find) Sort(sort string) types.Find

Sort 查询排序

func (*Find) Start

func (f *Find) Start(start uint64) types.Find

Start 查询上标

type Idgen

type Idgen struct {
	ID         string `bson:"_id"`
	SequenceID uint64 `bson:"SequenceID"`
}

type Mongo

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

func NewMgo

func NewMgo(config MongoConf, timeout time.Duration) (*Mongo, error)

NewMgo returns new RDB

func (*Mongo) AbortTransaction

func (c *Mongo) AbortTransaction(ctx context.Context, cap *metadata.TxnCapable) error

AbortTransaction 取消事务

func (*Mongo) Close

func (c *Mongo) Close() error

Close replica client

func (*Mongo) CommitTransaction

func (c *Mongo) CommitTransaction(ctx context.Context, cap *metadata.TxnCapable) error

CommitTransaction 提交事务

func (*Mongo) CreateTable

func (c *Mongo) CreateTable(ctx context.Context, collName string) error

CreateTable 创建集合 TODO test

func (*Mongo) DropTable

func (c *Mongo) DropTable(ctx context.Context, collName string) error

DropTable 移除集合

func (*Mongo) GetDBClient

func (c *Mongo) GetDBClient() *mongo.Client

get db client

func (*Mongo) GetDBName

func (c *Mongo) GetDBName() string

get db name

func (*Mongo) HasTable

func (c *Mongo) HasTable(ctx context.Context, collName string) (bool, error)

HasTable 判断是否存在集合

func (*Mongo) InitTxnManager

func (c *Mongo) InitTxnManager(r *redis.Client) error

InitTxnManager TxnID management of initial transaction

func (*Mongo) IsDuplicatedError

func (c *Mongo) IsDuplicatedError(err error) bool

IsDuplicatedError check duplicated error

func (*Mongo) IsNotFoundError

func (c *Mongo) IsNotFoundError(err error) bool

IsNotFoundError check the not found error

func (*Mongo) NextSequence

func (c *Mongo) NextSequence(ctx context.Context, sequenceName string) (uint64, error)

NextSequence 获取新序列号(非事务)

func (*Mongo) Ping

func (c *Mongo) Ping() error

Ping replica client

func (*Mongo) Table

func (c *Mongo) Table(collName string) types.Table

Table collection operation

type MongoConf

type MongoConf struct {
	TimeoutSeconds int
	MaxOpenConns   uint64
	MaxIdleConns   uint64
	URI            string
	RsName         string
}

type StructCodec

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

StructCodec is the Codec used for struct values.

func NewStructCodec

func NewStructCodec(p bsoncodec.StructTagParser) (*StructCodec, error)

NewStructCodec returns a StructCodec that uses p for struct tag parsing.

func (*StructCodec) DecodeValue

DecodeValue implements the Codec interface. By default, map types in val will not be cleared. If a map has existing key/value pairs, it will be extended with the new ones from vr. For slices, the decoder will set the length of the slice to zero and append all elements. The underlying array will not be cleared.

type TxnManager

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

a transaction manager

func (*TxnManager) AutoRunWithTxn

func (t *TxnManager) AutoRunWithTxn(ctx context.Context, cli *mongo.Client, cmd func(ctx context.Context) error) error

func (*TxnManager) GenTxnNumber

func (t *TxnManager) GenTxnNumber(sessionID string, ttl time.Duration) (int64, error)

GenTxnNumber generate the transaction number from redis.

func (*TxnManager) GetTxnContext

func (t *TxnManager) GetTxnContext(ctx context.Context, cli *mongo.Client) (context.Context, mongo.Session, bool, error)

GetTxnContext create a session if the ctx is a session context, and the bool value is true. so the caller must check the bool, and use session only when the bool is true. otherwise the caller should not use the session, should call the mongodb command directly. Note: this function is always used with mongo.CmdbReleaseSession(ctx, sessCtx) to release the session connection.

func (*TxnManager) GetTxnNumber

func (t *TxnManager) GetTxnNumber(sessionID string) (int64, error)

func (*TxnManager) InitTxnManager

func (t *TxnManager) InitTxnManager(r *redis.Client) error

InitTxnManager is to init txn manager, set the redis storage

func (*TxnManager) PrepareCommit

func (t *TxnManager) PrepareCommit(cli *mongo.Client) (mongo.Session, error)

func (*TxnManager) PrepareTransaction

func (t *TxnManager) PrepareTransaction(cap *metadata.TxnCapable, cli *mongo.Client) (mongo.Session, error)

func (*TxnManager) ReloadSession

func (t *TxnManager) ReloadSession(sess mongo.Session, info *mongo.SessionInfo) (mongo.Session, error)

func (*TxnManager) RemoveSessionKey

func (t *TxnManager) RemoveSessionKey(sessionID string) error

type Zeroer

type Zeroer interface {
	IsZero() bool
}

Zeroer allows custom struct types to implement a report of zero state. All struct types that don't implement Zeroer or where IsZero returns false are considered to be not zero.

Jump to

Keyboard shortcuts

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