Documentation ¶
Index ¶
- Variables
- func AddIndex(db MongoDB, m metrics.Metrics, col string, indexes ...mgo.Index) error
- func Count(ctx context.Context, db MongoDB, m metrics.Metrics, col string) (int, error)
- func Create(ctx context.Context, db MongoDB, m metrics.Metrics, col string, ...) error
- func Delete(ctx context.Context, db MongoDB, m metrics.Metrics, col string, ...) error
- func Exec(ctx context.Context, db MongoDB, m metrics.Metrics, col string, isread bool, ...) error
- func Get(ctx context.Context, db MongoDB, m metrics.Metrics, col string, ...) (methods.User, error)
- func GetAll(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, ...) ([]methods.User, int, error)
- func GetAllByOrder(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, ...) ([]methods.User, error)
- func GetByField(ctx context.Context, db MongoDB, m metrics.Metrics, col string, key string, ...) (methods.User, error)
- func Update(ctx context.Context, db MongoDB, m metrics.Metrics, col string, ...) error
- type Config
- type MongoDB
- type UserConsumer
- type UserFields
- type Validation
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("record not found") ErrExpiredContext = errors.New("context has expired") )
errors ...
Functions ¶
func AddIndex ¶
AddIndex adds provided index if any to giving collection within database exposed by the provided MongoDB instance.
func Create ¶
func Create(ctx context.Context, db MongoDB, m metrics.Metrics, col string, elem methods.User) error
Create attempts to add the record into the db using the provided instance of the methods.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 Delete ¶
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 methods.User struct.
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.
func Get ¶
func Get(ctx context.Context, db MongoDB, m metrics.Metrics, col string, publicID string) (methods.User, error)
Get retrieves a record from the db using the publicID and returns the methods.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 GetAll ¶
func GetAll(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, orderBy string, page int, responsePerPage int) ([]methods.User, int, error)
GetAll retrieves all records from the db and returns a slice of methods.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 GetAllByOrder ¶
func GetAllByOrder(ctx context.Context, db MongoDB, m metrics.Metrics, col string, order string, orderBy string) ([]methods.User, error)
GetAllByOrder retrieves all records from the db and returns a slice of methods.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 GetByField ¶
func GetByField(ctx context.Context, db MongoDB, m metrics.Metrics, col string, key string, value interface{}) (methods.User, error)
GetByField retrieves a record from the db using the provided field key and value returns the methods.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 Update ¶
func Update(ctx context.Context, db MongoDB, m metrics.Metrics, col string, publicID string, elem methods.User) error
Update uses a record from the db using the publicID and returns the methods.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.
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.
type MongoDB ¶
MongoDB defines a interface which exposes a method for retrieving a mongo.Database and mongo.Session.
func NewMongoDB ¶
NewMongoDB returns a new instance of a MongoDB.
type UserConsumer ¶
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 UserFields ¶
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.