db

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BackendNotInitializedError = errors.New("backend not initialized")
	BackendTypeError           = errors.New("object type is incorrect")
)

Functions

func Each

func Each(i Iterator, fn func(interface{}) error) error

Types

type Backend

type Backend interface {
	Find(objectType string, query map[string]interface{}) (Iterator, error)
	Upsert(objectType string, id, object interface{}) error
	Close() error
}

type Iterator

type Iterator interface {
	Next() (value interface{}, done bool, err error)
}

type MongoDB

type MongoDB struct {
	Session *mgo.Session
	DB      *mgo.Database
}

MongoDB encapsulates a mongo database and session

func NewMongoDB

func NewMongoDB(url string) *MongoDB

func (*MongoDB) Close

func (m *MongoDB) Close()

Close closes the mongodb session; must be called, else the session remains open

func (*MongoDB) Find

func (m *MongoDB) Find(objectType string, query map[string]interface{}) (Iterator, error)

Find finds from a collection using the query

func (*MongoDB) IsValid

func (m *MongoDB) IsValid() bool

IsValid returns true for a valid session, false otherwise

func (*MongoDB) Upsert

func (m *MongoDB) Upsert(objectType string, id, object interface{}) error

Upsert upserts a specific entity into the given collection

type Query

type Query map[interface{}]interface{}

Jump to

Keyboard shortcuts

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