Documentation ¶
Index ¶
- Constants
- func ApplyQueryModifiers(r RepositoryProvider, query *mgo.Query, params ...interface{}) (*mgo.Query, error)
- func Count(r RepositoryProvider, params ...interface{}) (n int, err error)
- func CountAndFindAll(r RepositoryProvider, dst interface{}, params ...interface{}) (n int, err error)
- func CountAndQuery(r RepositoryProvider, c *mgo.Collection, params ...interface{}) (*mgo.Query, int, error)
- func Create(r RepositoryProvider, object ...interface{}) error
- func Delete(r RepositoryProvider, params ...interface{}) error
- func DeleteAll(r RepositoryProvider, params ...interface{}) (n int, resultErr error)
- func Find(r RepositoryProvider, dst interface{}, params ...interface{}) error
- func FindAll(r RepositoryProvider, objects interface{}, params ...interface{}) error
- func FindByID(r RepositoryProvider, id interface{}, dst interface{}, params ...interface{}) error
- func GetQueryCriteria(defaultCriteria interface{}, params ...interface{}) (bson.D, error)
- func NewErrTypeNotSupported(v interface{}) error
- func Projection(fields ...interface{}) *projection
- func Query(r RepositoryProvider, c *mgo.Collection, params ...interface{}) (*mgo.Query, error)
- func Update(r RepositoryProvider, id interface{}, object interface{}) error
- func UpdateAndFind(r RepositoryProvider, id interface{}, dst interface{}, object interface{}, ...) error
- func UpdateRaw(r RepositoryProvider, id interface{}, object interface{}) error
- func UpdateRawWithCriteria(r RepositoryProvider, object interface{}, selector ...interface{}) error
- func Upsert(r RepositoryProvider, object interface{}, selector ...interface{}) error
- type BinaryOperator
- func ByID(id interface{}) BinaryOperator
- func EQ(field string, value interface{}) BinaryOperator
- func Exists(field string, value bool) BinaryOperator
- func GT(field string, value interface{}) BinaryOperator
- func GTE(field string, value interface{}) BinaryOperator
- func IN(field string, value interface{}) BinaryOperator
- func LT(field string, value interface{}) BinaryOperator
- func LTE(field string, value interface{}) BinaryOperator
- func NE(field string, value interface{}) BinaryOperator
- func NIN(field string, value interface{}) BinaryOperator
- func Regex(field string, value interface{}, options string) BinaryOperator
- type BinaryOperatorImpl
- type BooleanOperator
- func And(conditions ...interface{}) *BooleanOperator
- func ElemMatch(field string, value ...interface{}) *BooleanOperator
- func Nor(conditions ...interface{}) *BooleanOperator
- func Not(conditions interface{}) *BooleanOperator
- func Or(conditions ...interface{}) *BooleanOperator
- func Text(value FindText) *BooleanOperator
- type Criteria
- type FindText
- type MgoServiceRunner
- type OperatorSkipLimit
- type QueryBuilder
- type QueryModifier
- type QueryRunner
- type RawCriteria
- type Repository
- func (r *Repository) Count(params ...interface{}) (n int, err error)
- func (r *Repository) CountAndFindAll(dst interface{}, params ...interface{}) (n int, err error)
- func (r *Repository) Create(object interface{}) error
- func (r *Repository) Delete(params ...interface{}) error
- func (r *Repository) DeleteAll(params ...interface{}) (n int, resultErr error)
- func (r *Repository) Find(dst interface{}, params ...interface{}) error
- func (r *Repository) FindAll(objects interface{}, params ...interface{}) error
- func (r *Repository) FindByID(id interface{}, dst interface{}, params ...interface{}) error
- func (r *Repository) GetCollectionName() string
- func (r *Repository) GetDefaultCriteria() interface{}
- func (r *Repository) GetDefaultSorting() []string
- func (r *Repository) GetQueryRunner() QueryRunner
- func (r *Repository) Update(id interface{}, object interface{}) error
- func (r *Repository) UpdateAndFind(id interface{}, dst interface{}, object interface{}, params ...interface{}) error
- func (r *Repository) UpdateRaw(id interface{}, object interface{}) error
- func (r *Repository) UpdateRawWithCriteria(object interface{}, selector ...interface{}) error
- func (r *Repository) Upsert(object interface{}, selector ...interface{}) error
- type RepositoryConfig
- type RepositoryProvider
- type SimpleQueryRunner
- type Sort
Constants ¶
const ( // Comparison Operators BinaryOperatorTypeEq = iota BinaryOperatorTypeGT BinaryOperatorTypeGTE BinaryOperatorTypeIN BinaryOperatorTypeLT BinaryOperatorTypeLTE BinaryOperatorTypeNE BinaryOperatorTypeNIN // Element Operators BinaryOperatorTypeExists // Evaluation Operators BinaryOperatorTypeRegex )
const ( OperatorAnd operatorType = iota OperatorNot OperatorNor OperatorOr // Evaluation Operators OperatorText // Array Operators OperatorTypeElemMatch )
Variables ¶
This section is empty.
Functions ¶
func ApplyQueryModifiers ¶
func Count ¶
func Count(r RepositoryProvider, params ...interface{}) (n int, err error)
func CountAndFindAll ¶
func CountAndFindAll(r RepositoryProvider, dst interface{}, params ...interface{}) (n int, err error)
func CountAndQuery ¶
func CountAndQuery(r RepositoryProvider, c *mgo.Collection, params ...interface{}) (*mgo.Query, int, error)
CountAndQuery will use the same idea as `Query`. However, before applying the modifications from `QueryModifier` it saves the count and returns it with the reference of the `mgo.Query` obtained.
func Create ¶
func Create(r RepositoryProvider, object ...interface{}) error
func Delete ¶
func Delete(r RepositoryProvider, params ...interface{}) error
func DeleteAll ¶
func DeleteAll(r RepositoryProvider, params ...interface{}) (n int, resultErr error)
func Find ¶
func Find(r RepositoryProvider, dst interface{}, params ...interface{}) error
func FindAll ¶
func FindAll(r RepositoryProvider, objects interface{}, params ...interface{}) error
func FindByID ¶
func FindByID(r RepositoryProvider, id interface{}, dst interface{}, params ...interface{}) error
FindByID finds a model based on its ID. If not model is found in the collection, this method will return a mgo.ErrNotFound error.
When generating the query for the MongoDB, this method will use the defaultCriteria.
If no model is found, it returns an `mgo.ErrNotFound`.
func GetQueryCriteria ¶
GetQueryCriteria builds the criteria that will be performed in the Find method of a `mgo.Collection.Find` method.
The parameter `defaultCriteria` represents an initial set of criterias that be mixed with the passed parameters.
An error can be returned when building the criteria, due to a non supported datatype being used. Otherwise, a ready for use criteria object is returned.
func NewErrTypeNotSupported ¶
func NewErrTypeNotSupported(v interface{}) error
func Projection ¶
func Projection(fields ...interface{}) *projection
func Query ¶
func Query(r RepositoryProvider, c *mgo.Collection, params ...interface{}) (*mgo.Query, error)
Query builds the criteria, using `GetQueryCriteria`, and performs the `mgo.Collection.Find` for building the `mgo.Query`.
Then, the generated `mgo.Query` will be passed through each `QueryModifier` passed as param.
Finally, it will return the `mgo.Query` prepared for execution.
func Update ¶
func Update(r RepositoryProvider, id interface{}, object interface{}) error
Update does a complete update of a model.
func UpdateAndFind ¶ added in v0.2.0
func UpdateAndFind(r RepositoryProvider, id interface{}, dst interface{}, object interface{}, params ...interface{}) error
UpdateAndFind does an update and returns the updated model.
func UpdateRaw ¶
func UpdateRaw(r RepositoryProvider, id interface{}, object interface{}) error
UpdateRaw does a complete update of a model.
func UpdateRawWithCriteria ¶
func UpdateRawWithCriteria(r RepositoryProvider, object interface{}, selector ...interface{}) error
UpdateRawWithCriteria does a update of a model based on any selector.
func Upsert ¶ added in v0.1.0
func Upsert(r RepositoryProvider, object interface{}, selector ...interface{}) error
Upsert find a single document, if matching update else create.
Types ¶
type BinaryOperator ¶
func ByID ¶
func ByID(id interface{}) BinaryOperator
func EQ ¶
func EQ(field string, value interface{}) BinaryOperator
func Exists ¶
func Exists(field string, value bool) BinaryOperator
func GT ¶
func GT(field string, value interface{}) BinaryOperator
func GTE ¶
func GTE(field string, value interface{}) BinaryOperator
func IN ¶
func IN(field string, value interface{}) BinaryOperator
func LT ¶
func LT(field string, value interface{}) BinaryOperator
func LTE ¶
func LTE(field string, value interface{}) BinaryOperator
func NE ¶
func NE(field string, value interface{}) BinaryOperator
func NIN ¶
func NIN(field string, value interface{}) BinaryOperator
func Regex ¶
func Regex(field string, value interface{}, options string) BinaryOperator
type BinaryOperatorImpl ¶
type BinaryOperatorImpl struct { OpField *string FieldName string Type binaryOperatorType Value interface{} }
func (*BinaryOperatorImpl) GetCondition ¶
func (o *BinaryOperatorImpl) GetCondition() (bson.DocElem, error)
type BooleanOperator ¶
type BooleanOperator struct { Field *string Type operatorType Conditions []interface{} }
func And ¶
func And(conditions ...interface{}) *BooleanOperator
func ElemMatch ¶
func ElemMatch(field string, value ...interface{}) *BooleanOperator
func Nor ¶
func Nor(conditions ...interface{}) *BooleanOperator
func Not ¶
func Not(conditions interface{}) *BooleanOperator
func Or ¶
func Or(conditions ...interface{}) *BooleanOperator
func Text ¶
func Text(value FindText) *BooleanOperator
func (*BooleanOperator) GetCondition ¶
func (o *BooleanOperator) GetCondition() (bson.DocElem, error)
type Criteria ¶
type Criteria struct {
Conditions []interface{}
}
func WithCriteria ¶
func WithCriteria(params ...interface{}) *Criteria
type MgoServiceRunner ¶
type OperatorSkipLimit ¶
func Limit ¶
func Limit(limit int) *OperatorSkipLimit
func Skip ¶
func Skip(skip int) *OperatorSkipLimit
func WithPage ¶
func WithPage(page, pageSize int) *OperatorSkipLimit
type QueryBuilder ¶
type QueryBuilder interface { // `GetQuery` is used for filtering information. It is the object that // would be passed to the `mgo.Collection.Find` method to return a // `mgo.Query`. But it returns just a piece of it for further aggregation // inside of the `Query` method. GetQuery() (bson.D, error) }
Queryable objects will be treated as special objects during the query building.
type QueryModifier ¶
QueryModifier is the interface that describes an object that can modify one `mgo.Query`
type QueryRunner ¶
QueryRunner provide a infrastructure for executing querys in different contexts.
In case of managing a single database, a simple `QueryRunner` implementation can be easily grab a connection from the pool and call the handler providing the DB reference.
Additionaly, it also can implement be linked to a multi-tenanti environment that implements a database for each account. In that scenario, the `QueryRunner` implementation would make sure to take select the right database before calling the handler.
type RawCriteria ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶ added in v0.4.0
func NewRepository(config RepositoryConfig) *Repository
func (*Repository) Count ¶ added in v0.4.0
func (r *Repository) Count(params ...interface{}) (n int, err error)
func (*Repository) CountAndFindAll ¶ added in v0.4.0
func (r *Repository) CountAndFindAll(dst interface{}, params ...interface{}) (n int, err error)
func (*Repository) Create ¶ added in v0.4.0
func (r *Repository) Create(object interface{}) error
func (*Repository) Delete ¶ added in v0.4.0
func (r *Repository) Delete(params ...interface{}) error
func (*Repository) DeleteAll ¶ added in v0.4.0
func (r *Repository) DeleteAll(params ...interface{}) (n int, resultErr error)
func (*Repository) Find ¶ added in v0.4.0
func (r *Repository) Find(dst interface{}, params ...interface{}) error
func (*Repository) FindAll ¶ added in v0.4.0
func (r *Repository) FindAll(objects interface{}, params ...interface{}) error
func (*Repository) FindByID ¶ added in v0.4.0
func (r *Repository) FindByID(id interface{}, dst interface{}, params ...interface{}) error
func (*Repository) GetCollectionName ¶
func (r *Repository) GetCollectionName() string
func (*Repository) GetDefaultCriteria ¶
func (r *Repository) GetDefaultCriteria() interface{}
func (*Repository) GetDefaultSorting ¶
func (r *Repository) GetDefaultSorting() []string
func (*Repository) GetQueryRunner ¶
func (r *Repository) GetQueryRunner() QueryRunner
func (*Repository) Update ¶ added in v0.4.0
func (r *Repository) Update(id interface{}, object interface{}) error
func (*Repository) UpdateAndFind ¶ added in v0.4.0
func (r *Repository) UpdateAndFind(id interface{}, dst interface{}, object interface{}, params ...interface{}) error
func (*Repository) UpdateRaw ¶ added in v0.4.0
func (r *Repository) UpdateRaw(id interface{}, object interface{}) error
func (*Repository) UpdateRawWithCriteria ¶ added in v0.4.0
func (r *Repository) UpdateRawWithCriteria(object interface{}, selector ...interface{}) error
func (*Repository) Upsert ¶ added in v0.4.0
func (r *Repository) Upsert(object interface{}, selector ...interface{}) error
type RepositoryConfig ¶ added in v0.4.0
type RepositoryConfig struct { Collection string QueryRunner QueryRunner DefaultCriteria interface{} DefaultSorting []string }
type RepositoryProvider ¶ added in v0.4.0
type RepositoryProvider interface { GetCollectionName() string GetQueryRunner() QueryRunner GetDefaultCriteria() interface{} GetDefaultSorting() []string }
type SimpleQueryRunner ¶
type SimpleQueryRunner struct {
// contains filtered or unexported fields
}
func NewSimpleQueryRunner ¶
func NewSimpleQueryRunner(service MgoServiceRunner, database string) *SimpleQueryRunner
Source Files ¶
- binary_operator.go
- boolean_operator.go
- count.go
- count_and_find.go
- create.go
- criteria.go
- delete.go
- delete_all.go
- find.go
- find_all.go
- find_by_id.go
- limit.go
- operators_array.go
- operators_comparison.go
- operators_element.go
- operators_evaluation.go
- operators_logical.go
- projection.go
- queries.go
- query.go
- query_runner.go
- repository.go
- simple_query_runner.go
- sort.go
- update.go
- update_raw_with_criteria.go
- upsert.go