db

package
v0.0.0-...-d378361 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2017 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDB

func InitDB(mongo *configs.Mongo)

Initialize global defaultDB instance

Types

type Collection

type Collection interface {
	// Returns Query with objects with given id
	FindId(id interface{}) Query

	// Returns Query that build atop of given query spec.
	Find(query interface{}) Query

	// Inserts object.
	Insert(value interface{}) error

	// Finds object with "selector" and update it using "update" object.
	Update(selector, update interface{}) error
}

Interface for generic collection.

type DataSource

type DataSource interface {
	// Returns collection by name
	C(name string) Collection

	// Returns copy of data source (may be copy of session as well)
	Copy() DataSource

	// Closes data source (it will be runtime error to use it after close)
	Close()
}

Interface for generic data source (e.g. database).

func Copy

func Copy() DataSource

Returns current data source with new session

func Get

func Get() DataSource

Returns current data source.

type MongoCollection

type MongoCollection struct {
	*mgo.Collection
}

Wrapper around *mgo.Collection

func (MongoCollection) Find

func (c MongoCollection) Find(query interface{}) Query

Return Query with objects that match given query

func (MongoCollection) FindId

func (c MongoCollection) FindId(id interface{}) Query

Return Query with objects with given id

func (MongoCollection) Insert

func (c MongoCollection) Insert(value interface{}) error

Inserts value in collection.

func (MongoCollection) Update

func (c MongoCollection) Update(selector, update interface{}) error

Updates collection documents found by selector with "update" document.

type MongoDatabase

type MongoDatabase struct {
	*mgo.Database
}

Wrapper around *mgo.DataSource.

func (MongoDatabase) C

func (d MongoDatabase) C(name string) Collection

Override C method of mgo.DataSource to return wrapper around *mgo.Collection

func (MongoDatabase) Close

func (d MongoDatabase) Close()

Closes current session with mongo db

func (MongoDatabase) Copy

func (d MongoDatabase) Copy() DataSource

Returns database associated with copied session

type MongoQuery

type MongoQuery struct {
	*mgo.Query
}

Wrapper around *mgo.Query

func (MongoQuery) IsEmpty

func (q MongoQuery) IsEmpty() (empty bool, err error)

Returns true if query is empty

func (MongoQuery) Select

func (q MongoQuery) Select(selector interface{}) Query

Returns query selected from initial by selector.

type MongoSession

type MongoSession struct {
	*mgo.Session
}

Wrapper around *mgo.Session.

func (MongoSession) Source

func (s MongoSession) Source(name string) DataSource

Override Source method of mgo.Session to return wrapper around *mgo.DataSource.

type Query

type Query interface {
	// Returns all query entries in result object.
	// NOTE: Result MUST be POINTER to slice of objects with specified type.
	All(result interface{}) error

	// Return first object in query
	// NOTE: Result MUST be POINTER to object with specified type.
	One(result interface{}) error

	// Count all objects in query
	Count() (count int, err error)

	// Returns query with fields specified in selector
	Select(selector interface{}) Query

	// Returns true if query is empty
	IsEmpty() (empty bool, err error)
}

Interface for generic queries.

type Session

type Session interface {
	// Returns data source associated with this session with "name"
	Source(name string) DataSource

	// Closes session with data source other methods should panic
	// if you are trying to use closed session
	Close()
}

Interface for generic session with data source.

func NewMongoSession

func NewMongoSession(mgoURI string) (Session, error)

Creates new mongo session

Jump to

Keyboard shortcuts

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