mongo

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 12 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 KeyValueItem

type KeyValueItem struct {
	Key   string `bson:"_id"`
	Value string `bson:"Value"`
}

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.

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) (string, 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 {
	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) Empty

func (r *MongoItem) Empty() bool

func (*MongoItem) Equal

func (r *MongoItem) Equal(other txn.DataItem) bool

func (*MongoItem) IsDeleted

func (m *MongoItem) IsDeleted() bool

func (*MongoItem) Key

func (m *MongoItem) Key() string

func (*MongoItem) LinkedLen

func (m *MongoItem) LinkedLen() int

func (MongoItem) MarshalBSONValue

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

func (MongoItem) MarshalBinary

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

func (*MongoItem) Prev

func (m *MongoItem) Prev() string

func (*MongoItem) SetIsDeleted

func (m *MongoItem) SetIsDeleted(isDeleted bool)

func (*MongoItem) SetLinkedLen

func (m *MongoItem) SetLinkedLen(linkedLen int)

func (*MongoItem) SetPrev

func (m *MongoItem) SetPrev(prev string)

func (*MongoItem) SetTLease

func (m *MongoItem) SetTLease(tLease time.Time)

func (*MongoItem) SetTValid

func (m *MongoItem) SetTValid(tValid time.Time)

func (*MongoItem) SetTxnState

func (m *MongoItem) SetTxnState(state config.State)

func (*MongoItem) SetValue

func (m *MongoItem) SetValue(value string)

func (*MongoItem) SetVersion

func (m *MongoItem) SetVersion(version string)

func (MongoItem) String

func (r MongoItem) String() string

func (*MongoItem) TLease

func (m *MongoItem) TLease() time.Time

func (*MongoItem) TValid

func (m *MongoItem) TValid() time.Time

func (*MongoItem) TxnId

func (m *MongoItem) TxnId() string

func (*MongoItem) TxnState

func (m *MongoItem) TxnState() config.State

func (*MongoItem) UnmarshalBSONValue

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

func (*MongoItem) Value

func (m *MongoItem) Value() string

func (*MongoItem) Version

func (m *MongoItem) Version() string

type MongoItemFactory

type MongoItemFactory struct{}

func (*MongoItemFactory) NewDataItem

func (m *MongoItemFactory) NewDataItem(options txn.ItemOptions) txn.DataItem

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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