db

package
v0.0.0-...-5798410 Latest Latest
Warning

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

Go to latest
Published: May 19, 2013 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Current = new(Connection)
View Source
var Models = []Model{}

Functions

func Connect

func Connect(url, database string)

Connect to an mgo url

func Cursor

func Cursor(m Model) *mgo.Collection

func Exists

func Exists(u Updatable) bool

func Find

func Find(m Model, query interface{}) *mgo.Query

func Latest

func Latest(o OrderedModel, query interface{}) *mgo.Query

func Register

func Register(m Model)

func RegisterAllIndexes

func RegisterAllIndexes()

func RegisterIndexes

func RegisterIndexes(m Model)

func Upsert

func Upsert(u Updatable) (info *mgo.ChangeInfo, err error)

Types

type Connection

type Connection struct {
	Session *mgo.Session
	Db      *mgo.Database
	Url     string
	Host    string
	Port    int
}

type Model

type Model interface {
	Collection() string
	Indexes() [][]string
}

A thin Model interface. Implementing this interface will allow a number of simplifications to be executed on that model, like applying default ordering, atomatically creating indexes, etc. Though not necessary to use the interface, you should add an empty instance of your model to db.Models, which will auto-register indexes at connection time.

type OrderedModel

type OrderedModel interface {
	Model
	Sorting() string
}

type Updatable

type Updatable interface {
	Model
	Unique() bson.M
	PreSave()
}

Jump to

Keyboard shortcuts

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