Exemplo n.º 1
0
func (u *User) Save() error {
	session := db.Session()
	defer session.Close()

	c := session.DB(db.Name).C(collection)
	return c.Insert(&u)
}
Exemplo n.º 2
0
func (r *Restaurant) Save() error {
	session := db.Session()
	defer session.Close()

	c := session.DB(db.Name).C(collection)
	c.EnsureIndex(mgo.Index{Key: []string{"key"}, Unique: true})
	return c.Insert(&r)
}
Exemplo n.º 3
0
func ByKey(key string) (*Restaurant, error) {
	session := db.Session()
	defer session.Close()

	r := &Restaurant{}
	c := session.DB(db.Name).C(collection)
	err := c.Find(bson.M{"key": key}).One(r)

	return r, err
}
Exemplo n.º 4
0
func ById(id string) (*Restaurant, error) {
	session := db.Session()
	defer session.Close()

	r := &Restaurant{}
	c := session.DB(db.Name).C(collection)
	err := c.Find(bson.M{"_id": id}).One(r)

	return r, err
}
Exemplo n.º 5
0
func ById(id string) (*User, error) {
	session := db.Session()
	defer session.Close()

	u := &User{}
	c := session.DB(db.Name).C(collection)
	err := c.Find(bson.M{"_id": id}).One(u)

	return u, err
}