Documentation ¶
Index ¶
- func NewMongoDatastore(name string, conn txn.Connector) txn.Datastorer
- type ConnectionOptions
- type MongoConnection
- func (m *MongoConnection) Close() error
- func (m *MongoConnection) ConditionalUpdate(key string, value txn.DataItem, doCreat bool) error
- func (m *MongoConnection) Connect() error
- func (m *MongoConnection) Delete(key string) error
- func (m *MongoConnection) Get(key string) (string, error)
- func (m *MongoConnection) GetItem(key string) (txn.DataItem, error)
- func (m *MongoConnection) Put(key string, value any) error
- func (m *MongoConnection) PutItem(key string, value txn.DataItem) error
- type MongoConnectionInterface
- type MongoDatastore
- type MongoItem
- func (r *MongoItem) Equal(other MongoItem) bool
- func (m MongoItem) GetKey() string
- func (mi MongoItem) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (mi MongoItem) MarshalBinary() (data []byte, err error)
- func (r MongoItem) String() string
- func (mi *MongoItem) UnmarshalBSONValue(t bsontype.Type, raw []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMongoDatastore ¶
func NewMongoDatastore(name string, conn txn.Connector) txn.Datastorer
Types ¶
type ConnectionOptions ¶
type MongoConnection ¶
type MongoConnection struct { Address string // contains filtered or unexported fields }
func NewMongoConnection ¶
func NewMongoConnection(config *ConnectionOptions) *MongoConnection
NewMongoConnection creates a new MongoDB connection using the provided configuration options. If the config parameter is nil, default values will be used. The MongoDB connection is established using the specified address, username, password, and database name. The address format should be in the form "mongodb://host:port". The se parameter is used for data serialization and deserialization. If se is nil, a default JSON serializer will be used. Returns a pointer to the created MongoConnection.
func (*MongoConnection) Close ¶
func (m *MongoConnection) Close() error
Close closes the MongoDB connection. It's important to defer this function after creating a new connection.
func (*MongoConnection) ConditionalUpdate ¶
ConditionalUpdate updates the value of a Mongo item if the version matches the provided value. It takes a key string and a txn.DataItem value as parameters. If the item's version does not match, it returns a version mismatch error. Note: if the previous version of the item is not found, it will return a key not found error. Otherwise, it updates the item with the provided values and returns the updated item.
func (*MongoConnection) Connect ¶
func (m *MongoConnection) Connect() error
Connect establishes a connection to the MongoDB server. It returns an error if the connection cannot be established.
func (*MongoConnection) Delete ¶
func (m *MongoConnection) Delete(key string) error
Delete removes the specified key from the MongoDB database. It allows for the deletion of a key that does not exist.
func (*MongoConnection) Get ¶
func (m *MongoConnection) Get(key string) (string, error)
Get retrieves the value associated with the given key from the MongoDB database. If the key is not found, it returns an empty string and an error indicating the key was not found. If an error occurs during the retrieval, it returns an empty string and the error. Otherwise, it returns the retrieved value and nil error.
func (*MongoConnection) GetItem ¶
func (m *MongoConnection) GetItem(key string) (txn.DataItem, error)
GetItem retrieves a txn.DataItem from the MongoDB database based on the specified key. If the key is not found, it returns an empty txn.DataItem and an error.
type MongoDatastore ¶
type MongoItem ¶
type MongoItem struct { Key string `bson:"Key"` Value string `bson:"Value"` TxnId string `bson:"TxnId"` TxnState config.State `bson:"TxnState"` TValid time.Time `bson:"TValid"` TLease time.Time `bson:"TLease"` Prev string `bson:"Prev"` LinkedLen int `bson:"LinkedLen"` IsDeleted bool `bson:"IsDeleted"` Version int `bson:"Version"` }