mdb

package
v0.0.0-...-633417b Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: MIT Imports: 8 Imported by: 0

README

MongoDB Implementation

MongoDB Implementation is a code generation package that provides a basic implementation for interacting with a underine mongodb database.

Following methods are implemented:

WithIndex

AddIndex(ctx context.Context, db MongoDB, col string, indexes ...mgo.Index) error) error

Count

Count(ctx context.Context, db MongoDB, col string) (int, error)

Exec

Exec(ctx context.Context, db MongoDB, col string, isread bool, fx func(col *mgo.Collection) error) error

Documentation

Overview

Package mongoapi provides a auto-generated package which contains a mongo base pkg for db operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("record not found")
	ErrExpiredContext = errors.New("context has expired")
)

errors ...

Functions

func AddIndex

func AddIndex(db MongoDB, m metrics.Metrics, col string, indexes ...mgo.Index) error

AddIndex adds provided index if any to giving collection within database exposed by the provided MongoDB instance.

func Count

func Count(ctx context.Context, db MongoDB, m metrics.Metrics, col string) (int, error)

Count attempts to return the total number of record from the db.

func Exec

func Exec(ctx context.Context, db MongoDB, m metrics.Metrics, col string, isread bool, fx func(col *mgo.Collection) error) error

Exec provides a function which allows the execution of a custom function against the collection.

Types

type Config

type Config struct {
	DB       string `toml:"db" json:"db"`
	AuthDB   string `toml:"authdb" json:"authdb"`
	User     string `toml:"user" json:"user"`
	Password string `toml:"password" json:"password"`
	Host     string `toml:"host" json:"host"`
}

Config embodies the data used to connect to user's mongo connection.

func (Config) Empty

func (mgc Config) Empty() bool

Empty returns true/false if all Config values are at default/empty/non-set state.

func (Config) Validate

func (mgc Config) Validate() error

Validate returns an error if the config is invalid.

type MongoDB

type MongoDB interface {
	New(isread bool) (*mgo.Database, *mgo.Session, error)
}

MongoDB defines a interface which exposes a method for retrieving a mongo.Database and mongo.Session.

func NewMongoDB

func NewMongoDB(conf Config) MongoDB

NewMongoDB returns a new instance of a MongoDB.

Jump to

Keyboard shortcuts

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