示例#1
0
文件: model.go 项目: kranthic/justily
func (u *User) Save() error {
	session := db.Session()
	defer session.Close()

	c := session.DB(db.Name).C(collection)
	return c.Insert(&u)
}
示例#2
0
文件: model.go 项目: kranthic/justily
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)
}
示例#3
0
文件: model.go 项目: kranthic/justily
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
}
示例#4
0
文件: model.go 项目: kranthic/justily
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
}
示例#5
0
文件: model.go 项目: kranthic/justily
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
}