gmo

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 10 Imported by: 0

README

GMO

Generically Modified ODM — A generic wrapper around the MongoDB driver.

TODOs

  • Implement additional functions.
    • Implement Delete functions.
      • DeleteOne.
      • DeleteByID.
  • Improve and stabilise the API.
  • Write Documentation
    • Add a simple usage tutorial.
    • Improve GoDoc.

LICENSE

MIT.

Documentation

Overview

Package gmo implements a simple generic wrapper around the MongoDB driver. Also check https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultContext

func DefaultContext() context.Context

DefaultContext creates a context for convenience.

Types

type Collection

type Collection[T any] struct {
	// contains filtered or unexported fields
}

Collection is a generic wrapper around mongo.Collection.

func (*Collection[T]) CountDocuments

func (c *Collection[T]) CountDocuments(filter any) (int64, error)

CountDocuments returns the number of documents in the collection.

func (*Collection[T]) Find

func (c *Collection[T]) Find(ctx context.Context, filter any, opts ...*options.FindOptions) (result []T, err error)

Find executes a find command and returns a slice of the matching documents.

func (*Collection[T]) FindByID

func (c *Collection[T]) FindByID(ctx context.Context, id string) (result T, err error)

FindByID executes a find command based on the ID.

func (*Collection[T]) FindOne

func (c *Collection[T]) FindOne(ctx context.Context, filter any,
	opts ...*options.FindOneOptions) (result T, err error)

FindOne executes a find command and a document in the collection.

func (*Collection[T]) Insert

func (c *Collection[T]) Insert(document T) (T, error)

Insert executes an insert command to insert a single document into the collection.

func (*Collection[T]) UpdateByID

func (c *Collection[T]) UpdateByID(ctx context.Context, id string, document T) error

UpdateByID executes an update command based on the ID.

func (*Collection[T]) UpdateOne

func (c *Collection[T]) UpdateOne(ctx context.Context, filter any, document T) error

UpdateOne executes an update command to update at most one document in the collection.

type Database

type Database struct {
	DBName string
	// contains filtered or unexported fields
}

func New

func New(connString string) (database Database, err error)

New creates an instance of gmo.Database.

func (*Database) ListCollectionNames

func (d *Database) ListCollectionNames(ctx context.Context, filter any, opts ...*options.ListCollectionsOptions) ([]string, error)

ListCollectionNames lists all the collections in the DB.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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