store

package
v0.0.0-...-689f3c9 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoInstance

type MongoInstance struct {

	// The MongoDB client.
	Client *mongo.Client
}

Description:

A MongoDB instance.
A wrapper around the MongoDB client.

func NewMongoInstance

func NewMongoInstance(uri string) (*MongoInstance, error)

Description:

Creates a new mongo instance.
Connects instantly to the given URI.

Parameters:

uri The MongoDB connection URI.

Returns:

The created mongo instance, or an error, if the connection fails.

type MongoStore

type MongoStore[T interface{}] struct {

	// The MongoDB collection.
	Collection *mongo.Collection
}

Description:

A MongoDB store.
A wrapper around the MongoDB collection.

func NewMongoStore

func NewMongoStore[T interface{}](instance *MongoInstance, database string, collection string) *MongoStore[T]

Description:

Creates a new mongo store.

Parameters:

instance 	The mongo instance which is referred to.
database 	The mongo database name referring to.
collection 	The mongo collection name referring to.

Type Parameters:

T The type of document stored in the mongo store to create.

Returns:

The created mongo store.

func (*MongoStore[T]) CreateItem

func (store *MongoStore[T]) CreateItem(item interface{}) error

Description:

Creates a new item.

Parameters:

item The item to create.

Returns:

An error if creation fails.

func (MongoStore[T]) DeleteItem

func (store MongoStore[T]) DeleteItem(id string) (int64, error)

Description:

Deletes an item by its ID.

Parameters:

The ID of the document to delete.

Returns:

The number of deleted documents.
An error if the request fails.

func (*MongoStore[T]) FindItems

func (store *MongoStore[T]) FindItems(filter *query.Filter) ([]T, error)

Description:

Queries items in the store.

Parameters:

The query filter to use.

Returns:

An array of all items matching the given query filter.
An error if the query fails.

func (*MongoStore[T]) UpdateItem

func (store *MongoStore[T]) UpdateItem(filter *query.Filter, update *query.Update) (int64, error)

Description:

Updates a single item.

Parameters:

filter The filter used for searching the documents to update.
update The update operator used for updating the filtered documents.

Returns:

The number of modified documents.
An error if the update fails.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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