Documentation
¶
Index ¶
- func NewMongoDatastore(name string, conn txn.Connector) txn.Datastorer
- type ConnectionOptions
- type KeyValueItem
- type MongoConnection
- func (m *MongoConnection) AtomicCreate(key string, value any) (string, error)
- func (m *MongoConnection) Close() error
- func (m *MongoConnection) ConditionalCommit(key string, version string) (string, error)
- func (m *MongoConnection) ConditionalUpdate(key string, value txn.DataItem, doCreat bool) (string, 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) (string, error)
- type MongoConnectionInterface
- type MongoDatastore
- type MongoItem
- func (r *MongoItem) Empty() bool
- func (r *MongoItem) Equal(other txn.DataItem) bool
- func (m *MongoItem) IsDeleted() bool
- func (m *MongoItem) Key() string
- func (m *MongoItem) LinkedLen() int
- func (mi MongoItem) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (mi MongoItem) MarshalBinary() (data []byte, err error)
- func (m *MongoItem) Prev() string
- func (m *MongoItem) SetIsDeleted(isDeleted bool)
- func (m *MongoItem) SetLinkedLen(linkedLen int)
- func (m *MongoItem) SetPrev(prev string)
- func (m *MongoItem) SetTLease(tLease time.Time)
- func (m *MongoItem) SetTValid(tValid time.Time)
- func (m *MongoItem) SetTxnState(state config.State)
- func (m *MongoItem) SetValue(value string)
- func (m *MongoItem) SetVersion(version string)
- func (r MongoItem) String() string
- func (m *MongoItem) TLease() time.Time
- func (m *MongoItem) TValid() time.Time
- func (m *MongoItem) TxnId() string
- func (m *MongoItem) TxnState() config.State
- func (mi *MongoItem) UnmarshalBSONValue(t bsontype.Type, raw []byte) error
- func (m *MongoItem) Value() string
- func (m *MongoItem) Version() string
- type MongoItemFactory
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 KeyValueItem ¶
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) AtomicCreate ¶
func (m *MongoConnection) AtomicCreate(key string, value any) (string, error)
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) ConditionalCommit ¶
func (m *MongoConnection) ConditionalCommit(key string, version string) (string, error)
ConditionalCommit updates the txnState and version of a Mongo item if the version matches the provided value. It takes a key string and a version string as parameters. If the item's version does not match, it returns a version mismatch error. Otherwise, it updates the item with the provided values and returns the updated item.
func (*MongoConnection) ConditionalUpdate ¶
func (m *MongoConnection) ConditionalUpdate(key string, value txn.DataItem, doCreat bool) (string, error)
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 {
MKey string `bson:"_id" json:"Key"`
MValue string `bson:"Value" json:"Value"`
MTxnId string `bson:"TxnId" json:"TxnId"`
MTxnState config.State `bson:"TxnState" json:"TxnState"`
MTValid time.Time `bson:"TValid" json:"TValid"`
MTLease time.Time `bson:"TLease" json:"TLease"`
MPrev string `bson:"Prev" json:"Prev"`
MLinkedLen int `bson:"LinkedLen" json:"LinkedLen"`
MIsDeleted bool `bson:"IsDeleted" json:"IsDeleted"`
MVersion string `bson:"Version" json:"Version"`
}
func NewMongoItem ¶
func NewMongoItem(options txn.ItemOptions) *MongoItem
func (MongoItem) MarshalBSONValue ¶
func (MongoItem) MarshalBinary ¶
func (*MongoItem) SetIsDeleted ¶
func (*MongoItem) SetLinkedLen ¶
func (*MongoItem) SetTxnState ¶
func (*MongoItem) SetVersion ¶
func (*MongoItem) UnmarshalBSONValue ¶
type MongoItemFactory ¶
type MongoItemFactory struct{}
func (*MongoItemFactory) NewDataItem ¶
func (m *MongoItemFactory) NewDataItem(options txn.ItemOptions) txn.DataItem