base

package
v0.0.0-...-1cab694 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatches = errors.New("no matches found for query")

ErrNoMatches indicates that no matches were found for a query

View Source
var ErrUnexpectedInsertResult = errors.New("unexpected insert result")

ErrUnexpectedInsertResult indicates that a result set is not a valid insert result

Functions

This section is empty.

Types

type FindOptions

type FindOptions struct {
	PageSize int64
	Page     int64
	Sorting  map[string]interface{}
}

FindOptions represents Find function options

type ModelInterface

type ModelInterface interface {
	Exists() bool
	GetID() interface{}
	SetID(interface{})
}

ModelInterface defines common mongo models

type MongoClient

type MongoClient interface {
	Connect(context.Context) error
	Database(string, ...*options.DatabaseOptions) *mongo.Database
}

MongoClient encapsulates the MongoDB Client struct

type MongoDB

type MongoDB interface {
	Collection(string, ...*options.CollectionOptions) *mongo.Collection
}

MongoDB encapsulates the MongoDB DB struct

type MongoHelper

type MongoHelper interface {
	NewClient(uri string) (MongoClient, error)
	Find(ctx context.Context, coll string, filter interface{}, item interface{}, opts FindOptions) (pagination.Result, error)
	FindOne(ctx context.Context, coll string, filter interface{}, item interface{})
	InsertOne(ctx context.Context, coll string, item interface{}) (primitive.ObjectID, error)
	GetIDFromInsertOneResult(*mongo.InsertOneResult) (primitive.ObjectID, error)
	UpdateOne(ctx context.Context, coll string, filter interface{}, item interface{}) error
	GetIndex(ctx context.Context, coll string, index string) (*bson.M, error)
	HasIndex(ctx context.Context, coll string, index string) (bool, error)
	AddIndexIfNotExists(ctx context.Context, coll string, name string, keys interface{}) error
	Aggregate(ctx context.Context, coll string, pipeline mongo.Pipeline) ([]bson.M, error)
}

MongoHelper is used for helper functions

func NewHelper

func NewHelper(db MongoDB) MongoHelper

NewHelper get an implementation of a MongoHelper

Jump to

Keyboard shortcuts

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