func (u *User) Save() error { session := db.Session() defer session.Close() c := session.DB(db.Name).C(collection) return c.Insert(&u) }
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) }
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 }
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 }
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 }