示例#1
0
func EnsureIndex(dbConn *mgo.Session, dbName string, collName string, index *mgo.Index) error {
	var err = dbConn.DB(dbName).C(collName).EnsureIndex(*index)
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
示例#2
0
func Insert(dbConn *mgo.Session, dbName string, collName string, recs ...interface{}) error {
	var err = dbConn.DB(dbName).C(collName).Insert(recs...)
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
示例#3
0
func DropDatabase(dbConn *mgo.Session, dbName string) error {
	var err = dbConn.DB(dbName).DropDatabase()
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
示例#4
0
文件: model.go 项目: mocchira/digestw
func (su *StatsUnit) Find(sess *mgo.Session, col, uid, unitid string) os.Error {
	c := sess.DB(MGO_DB).C(col)
	if unitid == "" {
		return c.Find(bson.M{"userid": uid}).One(su)
	}
	return c.Find(bson.M{"userid": uid, "unitid": unitid}).One(su)
}
示例#5
0
func getPage(session *mgo.Session, title string) (result *Page, err error) {
	result = new(Page)
	c := session.DB(dbname).C("pages")
	err = c.Find(bson.M{"title": title}).One(result)
	return
}
示例#6
0
func Find(dbConn *mgo.Session, dbName string, collName string, query interface{}) *mgo.Query {
	return dbConn.DB(dbName).C(collName).Find(query)
}
示例#7
0
文件: model.go 项目: mocchira/digestw
func (su *DigestwUser) Find(sess *mgo.Session, ns int64) *mgo.Iter {
	c := sess.DB(MGO_DB).C(MGO_COL_USER)
	return c.Find(bson.M{"nextseconds": bson.M{"$lt": ns}}).Limit(CRAWL_UNIT).Iter()
}
示例#8
0
文件: model.go 项目: mocchira/digestw
func (su *DigestwUser) FindOne(sess *mgo.Session, sn string) os.Error {
	c := sess.DB(MGO_DB).C(MGO_COL_USER)
	return c.Find(bson.M{"screen_name": sn}).One(su)
}
示例#9
0
文件: model.go 项目: mocchira/digestw
func (su *DigestwUser) Upsert(sess *mgo.Session) (interface{}, os.Error) {
	c := sess.DB(MGO_DB).C(MGO_COL_USER)
	return c.Upsert(bson.M{"screen_name": su.TwUser.Screen_Name}, su)
}
示例#10
0
文件: model.go 项目: mocchira/digestw
func (su *StatsUnit) Upsert(sess *mgo.Session, col, uid, unitid string) (interface{}, os.Error) {
	c := sess.DB(MGO_DB).C(col)
	return c.Upsert(bson.M{"userid": uid, "unitid": unitid}, su)
}