mongo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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 ConnectionOptions struct {
	Address        string
	Username       string
	Password       string
	DBName         string
	CollectionName string
}

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

func (m *MongoConnection) ConditionalUpdate(key string, value txn.DataItem, doCreat bool) 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.

func (*MongoConnection) Put

func (m *MongoConnection) Put(key string, value any) error

Put stores the given value with the specified key in the MongoDB database. It will overwrite the value if the key already exists. It returns an error if the operation fails.

func (*MongoConnection) PutItem

func (m *MongoConnection) PutItem(key string, value txn.DataItem) error

PutItem puts an item into the MongoDB database with the specified key and value. The function returns an error if there was a problem executing the MongoDB commands.

type MongoConnectionInterface

type MongoConnectionInterface interface {
	Connect() error
	GetItem(key string) (MongoItem, error)
	PutItem(key string, value MongoItem) error
	ConditionalUpdate(key string, value MongoItem) error
	Get(name string) (string, error)
	Put(name string, value any) error
	Delete(name string) error
}

type MongoDatastore

type MongoDatastore struct {
	*txn.Datastore
}

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"`
}

func (*MongoItem) Equal

func (r *MongoItem) Equal(other MongoItem) bool

func (MongoItem) GetKey

func (m MongoItem) GetKey() string

func (MongoItem) MarshalBSONValue

func (mi MongoItem) MarshalBSONValue() (bsontype.Type, []byte, error)

func (MongoItem) MarshalBinary

func (mi MongoItem) MarshalBinary() (data []byte, err error)

func (MongoItem) String

func (r MongoItem) String() string

func (*MongoItem) UnmarshalBSONValue

func (mi *MongoItem) UnmarshalBSONValue(t bsontype.Type, raw []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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