usermgo

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: 10 Imported by: 0

README

User MongoDB API

Go Report Card

User MongoDB API is a auto-generated CRUD implementation for the User in package github.com/gokit/mgokit/example/api.

The following method exists for custom operations:

Exec

Exec(ctx context.Context, fx func(col *mgo.Collection) error) error

The following methods exists in the generated API as pertaining to CRUD:

Count

Count(ctx context.Context) (int, error)

Create

Create(ctx context.Context, elem api.User) error

Get

Get(ctx context.Context, publicID string) (api.User, error)

Get All

GetAll(ctx context.Context) ([]api.User, error)

Update

Update(ctx context.Context, publicID string, elem api.User) error

Delete

Delete(ctx context.Context, publicID string) error

Documentation

Overview

Package usermgo provides a auto-generated package which contains a sql CRUD API for the specific User struct in package api.

Index

Constants

This section is empty.

Variables

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

errors ...

Functions

This section is empty.

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.

type UserConsumer

type UserConsumer interface {
	Consume(map[string]interface{}) error
}

UserConsumer defines an interface which accepts a map of data which will be consumed into the giving implementing structure as decided by the structure.

type UserDB

type UserDB struct {
	// contains filtered or unexported fields
}

UserDB defines a structure which provide DB CRUD operations using mongo as the underline db.

func New

func New(col string, m metrics.Metrics, mo MongoDB, indexes ...mgo.Index) *UserDB

New returns a new instance of UserDB.

func (*UserDB) Count

func (mdb *UserDB) Count(ctx context.Context) (int, error)

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

func (*UserDB) Create

func (mdb *UserDB) Create(ctx context.Context, elem api.User) error

Create attempts to add the record into the db using the provided instance of the api.User. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func (*UserDB) Delete

func (mdb *UserDB) Delete(ctx context.Context, publicID string) error

Delete attempts to remove the record from the db using the provided publicID. Records using this DB must have a public id value, expressed either by a bson or json tag on the given api.User struct.

func (*UserDB) Exec

func (mdb *UserDB) Exec(ctx context.Context, isread bool, fx func(col *mgo.Collection) error) error

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

func (*UserDB) Get

func (mdb *UserDB) Get(ctx context.Context, publicID string) (api.User, error)

Get retrieves a record from the db using the publicID and returns the api.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func (*UserDB) GetAll

func (mdb *UserDB) GetAll(ctx context.Context, order string, orderBy string, page int, responsePerPage int) ([]api.User, int, error)

GetAll retrieves all records from the db and returns a slice of api.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func (*UserDB) GetAllByOrder

func (mdb *UserDB) GetAllByOrder(ctx context.Context, order, orderBy string) ([]api.User, error)

GetAllByOrder retrieves all records from the db and returns a slice of api.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func (*UserDB) GetByField

func (mdb *UserDB) GetByField(ctx context.Context, key string, value interface{}) (api.User, error)

GetByField retrieves a record from the db using the provided field key and value returns the api.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

func (*UserDB) Update

func (mdb *UserDB) Update(ctx context.Context, publicID string, elem api.User) error

Update uses a record from the db using the publicID and returns the api.User type. Records using this DB must have a public id value, expressed either by a bson or json tag on the given User struct.

type UserFields

type UserFields interface {
	Fields() (map[string]interface{}, error)
}

UserFields defines an interface which exposes method to return a map of all attributes associated with the defined structure as decided by the structure.

type Validation

type Validation interface {
	Validate() error
}

Validation defines an interface which expose a method to validate a giving type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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