repository

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 4 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

CircleCI codecov GoDoc Report card

Repository

The repository is the first ORM initiative for being used with MongoDB (mgo library).

Usage

TODO: Use it and then grab some examples.

License

MIT

Documentation

Index

Constants

View Source
const (
	// Comparison Operators
	BinaryOperatorTypeEq = iota
	BinaryOperatorTypeGT
	BinaryOperatorTypeGTE
	BinaryOperatorTypeIN
	BinaryOperatorTypeLT
	BinaryOperatorTypeLTE
	BinaryOperatorTypeNE
	BinaryOperatorTypeNIN

	// Element Operators
	BinaryOperatorTypeExists

	// Evaluation Operators
	BinaryOperatorTypeRegex
)
View Source
const (
	OperatorAnd operatorType = iota
	OperatorNot
	OperatorNor
	OperatorOr

	// Evaluation Operators
	OperatorText

	// Array Operators
	OperatorTypeElemMatch
)

Variables

This section is empty.

Functions

func ApplyQueryModifiers

func ApplyQueryModifiers(r RepositoryProvider, query *mgo.Query, params ...interface{}) (*mgo.Query, error)

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

func GetQueryCriteria(defaultCriteria interface{}, params ...interface{}) (bson.D, error)

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

type BinaryOperator interface {
	GetCondition() (bson.DocElem, error)
}

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

func (*Criteria) GetQuery

func (c *Criteria) GetQuery() (bson.D, error)

type FindText

type FindText struct {
	Search             string  `bson:"$search"`
	Language           *string `bson:"$language,omitempty"`
	CaseSensitive      bool    `bson:"$caseSensitive,omitempty"`
	DiacriticSensitive bool    `bson:"$diacriticSensitive,omitempty"`
}

type MgoServiceRunner

type MgoServiceRunner interface {
	RunWithSession(handler func(session *mgo.Session) error) error
}

type OperatorSkipLimit

type OperatorSkipLimit struct {
	Skip  int
	Limit int
}

func Limit

func Limit(limit int) *OperatorSkipLimit

func Skip

func Skip(skip int) *OperatorSkipLimit

func WithPage

func WithPage(page, pageSize int) *OperatorSkipLimit

func (*OperatorSkipLimit) Apply

func (o *OperatorSkipLimit) Apply(query *mgo.Query) (*mgo.Query, error)

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

type QueryModifier interface {
	// Apply will
	Apply(query *mgo.Query) (*mgo.Query, error)
}

QueryModifier is the interface that describes an object that can modify one `mgo.Query`

type QueryRunner

type QueryRunner interface {
	RunWithDB(handler func(db *mgo.Database) error) error
}

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 RawCriteria bson.D

func (*RawCriteria) GetQuery

func (c *RawCriteria) GetQuery() (bson.D, error)

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

func (*SimpleQueryRunner) RunWithDB

func (runner *SimpleQueryRunner) RunWithDB(handler func(db *mgo.Database) error) error

RunWithDB runs

type Sort

type Sort struct {
	Fields []string
}

func WithSort

func WithSort(fields ...string) *Sort

Jump to

Keyboard shortcuts

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