Documentation
¶
Index ¶
- func ArrayDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func EmptyInterfaceDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func GenSessionID() (string, error)
- func GenTxnCableAndSetHeader(header http.Header, opts ...metadata.TxnOption) (*metadata.TxnCapable, error)
- func MapDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func SliceDecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- type Collection
- func (c *Collection) AddColumn(ctx context.Context, column string, value interface{}) error
- func (c *Collection) AggregateAll(ctx context.Context, pipeline interface{}, result interface{}) error
- func (c *Collection) AggregateOne(ctx context.Context, pipeline interface{}, result interface{}) error
- func (c *Collection) CreateIndex(ctx context.Context, index types.Index) error
- func (c *Collection) Delete(ctx context.Context, filter types.Filter) error
- func (c *Collection) Distinct(ctx context.Context, field string, filter types.Filter) ([]interface{}, error)
- func (c *Collection) DropColumn(ctx context.Context, field string) error
- func (c *Collection) DropColumns(ctx context.Context, filter types.Filter, fields []string) error
- func (c *Collection) DropDocsColumn(ctx context.Context, field string, filter types.Filter) error
- func (c *Collection) DropIndex(ctx context.Context, indexName string) error
- func (c *Collection) Find(filter types.Filter) types.Find
- func (c *Collection) Indexes(ctx context.Context) ([]types.Index, error)
- func (c *Collection) Insert(ctx context.Context, docs interface{}) error
- func (c *Collection) RenameColumn(ctx context.Context, oldName, newColumn string) error
- func (c *Collection) Update(ctx context.Context, filter types.Filter, doc interface{}) error
- func (c *Collection) UpdateMultiModel(ctx context.Context, filter types.Filter, updateModel ...types.ModeUpdate) error
- func (c *Collection) Upsert(ctx context.Context, filter types.Filter, doc interface{}) error
- type Find
- func (f *Find) All(ctx context.Context, result interface{}) error
- func (f *Find) Count(ctx context.Context) (uint64, error)
- func (f *Find) Fields(fields ...string) types.Find
- func (f *Find) Limit(limit uint64) types.Find
- func (f *Find) One(ctx context.Context, result interface{}) error
- func (f *Find) Sort(sort string) types.Find
- func (f *Find) Start(start uint64) types.Find
- type Idgen
- type Mongo
- func (c *Mongo) AbortTransaction(ctx context.Context, cap *metadata.TxnCapable) error
- func (c *Mongo) Close() error
- func (c *Mongo) CommitTransaction(ctx context.Context, cap *metadata.TxnCapable) error
- func (c *Mongo) CreateTable(ctx context.Context, collName string) error
- func (c *Mongo) DropTable(ctx context.Context, collName string) error
- func (c *Mongo) GetDBClient() *mongo.Client
- func (c *Mongo) GetDBName() string
- func (c *Mongo) HasTable(ctx context.Context, collName string) (bool, error)
- func (c *Mongo) InitTxnManager(r *redis.Client) error
- func (c *Mongo) IsDuplicatedError(err error) bool
- func (c *Mongo) IsNotFoundError(err error) bool
- func (c *Mongo) NextSequence(ctx context.Context, sequenceName string) (uint64, error)
- func (c *Mongo) Ping() error
- func (c *Mongo) Table(collName string) types.Table
- type MongoConf
- type StructCodec
- type TxnManager
- func (t *TxnManager) AutoRunWithTxn(ctx context.Context, cli *mongo.Client, cmd func(ctx context.Context) error) error
- func (t *TxnManager) GenTxnNumber(sessionID string, ttl time.Duration) (int64, error)
- func (t *TxnManager) GetTxnContext(ctx context.Context, cli *mongo.Client) (context.Context, mongo.Session, bool, error)
- func (t *TxnManager) GetTxnNumber(sessionID string) (int64, error)
- func (t *TxnManager) InitTxnManager(r *redis.Client) error
- func (t *TxnManager) PrepareCommit(cli *mongo.Client) (mongo.Session, error)
- func (t *TxnManager) PrepareTransaction(cap *metadata.TxnCapable, cli *mongo.Client) (mongo.Session, error)
- func (t *TxnManager) ReloadSession(sess mongo.Session, info *mongo.SessionInfo) (mongo.Session, error)
- func (t *TxnManager) RemoveSessionKey(sessionID string) error
- type Zeroer
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 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 ¶
CreateIndex 创建索引
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 ¶
DropColumns remove many columns by the name
func (*Collection) DropDocsColumn ¶
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) 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) UpdateMultiModel ¶
func (c *Collection) UpdateMultiModel(ctx context.Context, filter types.Filter, updateModel ...types.ModeUpdate) error
UpdateMultiModel 根据不同的操作符去更新数据
type Find ¶
type Find struct { *Collection // contains filtered or unexported fields }
Find define a find operation
type Mongo ¶
type Mongo struct {
// contains filtered or unexported fields
}
func (*Mongo) AbortTransaction ¶
AbortTransaction 取消事务
func (*Mongo) CommitTransaction ¶
CommitTransaction 提交事务
func (*Mongo) CreateTable ¶
CreateTable 创建集合 TODO test
func (*Mongo) InitTxnManager ¶
InitTxnManager TxnID management of initial transaction
func (*Mongo) IsDuplicatedError ¶
IsDuplicatedError check duplicated error
func (*Mongo) IsNotFoundError ¶
IsNotFoundError check the not found error
func (*Mongo) NextSequence ¶
NextSequence 获取新序列号(非事务)
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 ¶
func (sc *StructCodec) DecodeValue(r bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
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 (*TxnManager) GenTxnNumber ¶
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 (*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