database

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, c *mongo.Collection, e Entity) error

Create new entity in database.

func Delete

func Delete(ctx context.Context, c *mongo.Collection, e Entity) error

Delete existing entity in database.

func DeleteAll

func DeleteAll(ctx context.Context, c *mongo.Collection, q Query) (int64, error)

DeleteAll documents in collection that match query.

func EnsureIndexes

func EnsureIndexes(ctx context.Context, c *mongo.Collection, ks ...string) error

EnsureIndexes create custom and default indexes.

func Get

func Get(ctx context.Context, c *mongo.Collection, q Query, i interface{}) error

Get result of given pipeline, take a ptr to value. If no result found reset the value.

func GetAll

GetAll populates entity array with results of given pipeline.

Types

type BasicCriteria

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

BasicCriteria for documents.

func NewBasicCriteria

func NewBasicCriteria() *BasicCriteria

NewBasicCriteria .

func (*BasicCriteria) AppendQuery

func (b *BasicCriteria) AppendQuery(q Query)

AppendQuery add a new query to the list.

func (*BasicCriteria) Build

func (b *BasicCriteria) Build() Query

Build the query from criteria.

func (*BasicCriteria) ID

ID appender for basic criteria.

func (*BasicCriteria) UUID

func (b *BasicCriteria) UUID(uuids ...string) *BasicCriteria

UUID appender for basic criteria.

type BasicEntity

type BasicEntity struct {
	ID           objectid.ObjectID `bson:"_id" json:"-"`
	UUID         string            `bson:"uuid" json:"uuid"`
	CreationDate *time.Time        `bson:"creation_date,omitempty" json:"creation_date"`
	UpdateDate   *time.Time        `bson:"update_date,omitempty" json:"update_date"`
}

BasicEntity struct contains fields for documents.

func (*BasicEntity) GenerateIDs

func (b *BasicEntity) GenerateIDs()

GenerateIDs create values for ID and UUID.

func (BasicEntity) GetID

func (b BasicEntity) GetID() objectid.ObjectID

GetID returns ID for basic entity.

func (BasicEntity) GetUUID

func (b BasicEntity) GetUUID() string

GetUUID returns UUID for basic entity.

type Criteria

type Criteria interface {
	Build() Query
}

Criteria is used to build database query.

type Entity

type Entity interface {
	GetID() objectid.ObjectID
	GetUUID() string
	GenerateIDs()
}

Entity interface.

type EntityArray

type EntityArray interface {
	New() interface{}
}

EntityArray struct.

type Pipeline

type Pipeline []Query

Pipeline type for database request.

type Query

type Query map[string]interface{}

Query type for database request.

func And

func And(qs ...Query) Query

And returns new $and query for given list.

func In

func In(f string, i interface{}) Query

In returns new $in query for f key.

func Match

func Match(q Query) Query

Match returns new $match query from query.

func Or

func Or(qs ...Query) Query

Or returns new $or query for given list.

Jump to

Keyboard shortcuts

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