mongo

package
v0.0.0-...-7378411 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 添加字段

func (*Collection) CreateIndex

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

CreateIndex 创建索引

func (*Collection) Delete

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

Delete 删除数据

func (*Collection) DropColumn

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

DropColumn 移除字段

func (*Collection) DropIndex

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

DropIndex 移除索引

func (*Collection) Find

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

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

func (*Collection) Indexes

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

Indexes 查询索引

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 重命名字段

func (*Collection) Update

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

Update 更新数据

type Config

type Config struct {
	Connect      string
	Address      string
	User         string
	Password     string
	Port         string
	Database     string
	Mechanism    string
	MaxOpenConns string
	MaxIdleConns string
}

Config config

func ParseConfigFromKV

func ParseConfigFromKV(prefix string, conifgmap map[string]string) Config

ParseConfigFromKV returns a new config

func (Config) BuildURI

func (c Config) BuildURI() string

BuildURI return mongo uri according to https://docs.mongodb.com/manual/reference/connection-string/ format example: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

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) dal.Find

Fields 查询字段

func (*Find) Limit

func (f *Find) Limit(limit uint64) dal.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) dal.Find

Sort 查询排序

func (*Find) Start

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

Start 查询上标

type Idgen

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

type Mock

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

Mock implement client.DALRDB interface

func NewMock

func NewMock() *Mock

NewMock returns new RDB

func (*Mock) Abort

func (c *Mock) Abort(ctx context.Context) error

Abort 取消事务

func (*Mock) Clone

func (c *Mock) Clone() dal.RDB

Clone return the new client

func (*Mock) Close

func (c *Mock) Close() error

Close replica client

func (*Mock) Commit

func (c *Mock) Commit(ctx context.Context) error

Commit 提交事务

func (*Mock) CreateTable

func (c *Mock) CreateTable(collName string) error

CreateTable 创建集合

func (*Mock) DropTable

func (c *Mock) DropTable(collName string) error

DropTable 移除集合

func (*Mock) HasTable

func (c *Mock) HasTable(collName string) (bool, error)

HasTable 判断是否存在集合

func (*Mock) IsDuplicatedError

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

IsDuplicatedError returns whether error is Duplicated Error

func (*Mock) IsNotFoundError

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

IsNotFoundError returns whether error is Not Found Error

func (*Mock) Mock

func (c *Mock) Mock(retval MockResult) *Mock

func (*Mock) NextSequence

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

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

func (*Mock) Ping

func (c *Mock) Ping() error

Ping replica client

func (*Mock) StartTransaction

func (c *Mock) StartTransaction(ctx context.Context) (dal.RDB, error)

StartTransaction 开启新事务

func (*Mock) Table

func (c *Mock) Table(collName string) dal.Table

Table collection operation

func (*Mock) TxnInfo

func (c *Mock) TxnInfo() *types.Transaction

TxnInfo 当前事务信息,用于事务发起者往下传递

type MockCollection

type MockCollection struct {
	*Mock
	// contains filtered or unexported fields
}

MockCollection implement client.Collection interface

func (*MockCollection) AddColumn

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

AddColumn 添加字段

func (*MockCollection) CreateIndex

func (c *MockCollection) CreateIndex(ctx context.Context, index dal.Index) error

CreateIndex 创建索引

func (*MockCollection) Delete

func (c *MockCollection) Delete(ctx context.Context, filter dal.Filter) error

Delete 删除数据

func (*MockCollection) DropColumn

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

DropColumn 移除字段

func (*MockCollection) DropIndex

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

DropIndex 移除索引

func (*MockCollection) Find

func (c *MockCollection) Find(filter dal.Filter) dal.Find

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

func (*MockCollection) Indexes

func (c *MockCollection) Indexes(ctx context.Context) ([]dal.Index, error)

func (*MockCollection) Insert

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

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

func (*MockCollection) RenameColumn

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

RenameColumn 重命名字段

func (*MockCollection) Update

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

Update 更新数据

type MockFind

type MockFind struct {
	*MockCollection `json:"-"`
	// contains filtered or unexported fields
}

MockFind define a find operation

func (*MockFind) All

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

All 查询多个

func (*MockFind) Count

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

Count 统计数量(非事务)

func (*MockFind) Fields

func (f *MockFind) Fields(fields ...string) dal.Find

Fields 查询字段

func (*MockFind) Limit

func (f *MockFind) Limit(limit uint64) dal.Find

Limit 查询限制

func (*MockFind) One

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

One 查询一个

func (*MockFind) Sort

func (f *MockFind) Sort(sort string) dal.Find

Sort 查询排序

func (*MockFind) Start

func (f *MockFind) Start(start uint64) dal.Find

Start 查询上标

type MockResult

type MockResult struct {
	Err        error
	OK         bool
	RawResult  []byte
	Count      uint64
	SequenceID uint64
	Info       types.Transaction
	Indexs     []dal.Index
}

type Mongo

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

Mongo implement client.DALRDB interface

func NewMgo

func NewMgo(uri string) (*Mongo, error)

NewMgo returns new RDB

func (*Mongo) Abort

func (c *Mongo) Abort(ctx context.Context) error

Abort 取消事务

func (*Mongo) Clone

func (c *Mongo) Clone() dal.RDB

Clone return the new client

func (*Mongo) Close

func (c *Mongo) Close() error

Close replica client

func (*Mongo) Commit

func (c *Mongo) Commit(ctx context.Context) error

Commit 提交事务

func (*Mongo) CreateTable

func (c *Mongo) CreateTable(collName string) error

CreateTable 创建集合

func (*Mongo) DropTable

func (c *Mongo) DropTable(collName string) error

DropTable 移除集合

func (*Mongo) HasTable

func (c *Mongo) HasTable(collName string) (bool, error)

HasTable 判断是否存在集合

func (*Mongo) IsDuplicatedError

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

func (*Mongo) IsNotFoundError

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

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) StartTransaction

func (c *Mongo) StartTransaction(ctx context.Context) (dal.RDB, error)

StartTransaction 开启新事务

func (*Mongo) Table

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

Table collection operation

func (*Mongo) TxnInfo

func (c *Mongo) TxnInfo() *types.Transaction

TxnInfo 当前事务信息,用于事务发起者往下传递

type RPC

type RPC struct {
	RequestID string // 请求ID,可选项
	TxnID     string // 事务ID,uuid
	// contains filtered or unexported fields
}

RPC implement client.DALRDB interface

func NewRPC

func NewRPC(uri string) (*RPC, error)

NewRPC returns new RDB

func NewRPCWithDiscover

func NewRPCWithDiscover(getServer types.GetServerFunc) (*RPC, error)

NewRPCWithDiscover returns new RDB

func (*RPC) Abort

func (c *RPC) Abort(ctx context.Context) error

Abort 取消事务

func (*RPC) Clone

func (c *RPC) Clone() dal.RDB

func (*RPC) Close

func (c *RPC) Close() error

Close replica client

func (*RPC) Commit

func (c *RPC) Commit(ctx context.Context) error

Commit 提交事务

func (*RPC) CreateTable

func (c *RPC) CreateTable(tablename string) error

CreateTable 创建集合

func (*RPC) DropTable

func (c *RPC) DropTable(tablename string) error

DropTable 移除集合

func (*RPC) HasTable

func (c *RPC) HasTable(tablename string) (bool, error)

HasTable 判断是否存在集合

func (*RPC) IsDuplicatedError

func (c *RPC) IsDuplicatedError(error) bool

func (*RPC) IsNotFoundError

func (c *RPC) IsNotFoundError(error) bool

func (*RPC) NextSequence

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

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

func (*RPC) Ping

func (c *RPC) Ping() error

Ping replica client

func (*RPC) StartTransaction

func (c *RPC) StartTransaction(ctx context.Context) (dal.RDB, error)

StartTransaction 开启新事务

func (*RPC) Table

func (c *RPC) Table(collection string) dal.Table

Table collection operation

func (*RPC) TxnInfo

func (c *RPC) TxnInfo() *types.Transaction

TxnInfo 当前事务信息,用于事务发起者往下传递

type RPCCollection

type RPCCollection struct {
	RequestID string // 请求ID,可选项
	Processor string // 处理进程号,结构为"IP:PORT-PID"用于识别事务session被存于那个TM多活实例
	TxnID     string // 事务ID,uuid
	// contains filtered or unexported fields
}

RPCCollection implement client.Collection interface

func (*RPCCollection) AddColumn

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

AddColumn 添加字段

func (*RPCCollection) CreateIndex

func (c *RPCCollection) CreateIndex(ctx context.Context, index dal.Index) error

CreateIndex 创建索引

func (*RPCCollection) Delete

func (c *RPCCollection) Delete(ctx context.Context, filter dal.Filter) error

Delete 删除数据

func (*RPCCollection) DropColumn

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

DropColumn 移除字段

func (*RPCCollection) DropIndex

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

DropIndex 移除索引

func (*RPCCollection) Find

func (c *RPCCollection) Find(filter dal.Filter) dal.Find

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

func (*RPCCollection) Indexes

func (c *RPCCollection) Indexes(ctx context.Context) ([]dal.Index, error)

Indexes 查询索引

func (*RPCCollection) Insert

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

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

func (*RPCCollection) RenameColumn

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

RenameColumn 重命名字段

func (*RPCCollection) Update

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

Update 更新数据

type RPCFind

type RPCFind struct {
	*RPCCollection
	// contains filtered or unexported fields
}

RPCFind define a find operation

func (*RPCFind) All

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

All 查询多个

func (*RPCFind) Count

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

Count 统计数量(非事务)

func (*RPCFind) Fields

func (f *RPCFind) Fields(fields ...string) dal.Find

Fields 查询字段

func (*RPCFind) Limit

func (f *RPCFind) Limit(limit uint64) dal.Find

Limit 查询限制

func (*RPCFind) One

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

One 查询一个

func (*RPCFind) Sort

func (f *RPCFind) Sort(sort string) dal.Find

Sort 查询排序

func (*RPCFind) Start

func (f *RPCFind) Start(start uint64) dal.Find

Start 查询上标

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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