database

package
v0.0.173 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Delete

func Delete[T any](collectionName string, id primitive.ObjectID) (bool, error)

Delete a document from the database.

func Get

func Get[T any](collection string, id primitive.ObjectID) (*T, error)

Get a single document from the database.

func Insert

func Insert[T any](collectionName string, doc T) (primitive.ObjectID, error)

Insert a new document into the database.

func Query

func Query[T any](collectionName string, filter bson.D, sort bson.D, projection bson.D, start int64, limit int) ([]*T, error)

Query the database for multiple documents.

@Param collectionName The name of the collection to query.

@Param filter A BSON document specifying a filter to apply to the query.

@Param sort A BSON document specifying how to sort the returned results.

{'field': order}
where 'field' is the name of the field in the database, and <order> is an integer value specifying
whether the field should be sorted ascending (1) or descending (-1)

@Param projection A BSON document specifying a specific set of fields to return or ignore

{'field': value}
where 'field' is the name of the field in the database, and <value> is an integer value specifying
whether the field should be returned (1, excluding others) or ignored (0)

@Param start The starting document for the query results.

@Param limit The maximum number of documents to return in the query.

@Return An array of the documents matching the query parameters, or an error.

func SetupDatabase

func SetupDatabase()

SetupDatabase initializes the database connection and sets up the database instance.

func TeardownDatabase

func TeardownDatabase()

TeardownDatabase closes the connection to the database. It should be called when the application is shutting down.

func Update

func Update[T any](collectionName string, id primitive.ObjectID, doc T) (int, int, error)

Update a document in the database.

Types

This section is empty.

Jump to

Keyboard shortcuts

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