Beispiel #1
0
func UserGroupCount(query interface{}) (result int) {
	session, col := db.GetCol("UserGroup")
	defer session.Close()

	result, _ = col.Find(query).Count()
	return
}
Beispiel #2
0
func UserGroupRemoveByID(id string) (result *UserGroup, err error) {
	session, col := db.GetCol("UserGroup")
	defer session.Close()

	if !bson.IsObjectIdHex(id) {
		err = mgo.ErrNotFound
		return
	}
	err = col.RemoveId(bson.ObjectIdHex(id))
	return
}
Beispiel #3
0
func UserGroupFindAll(query interface{}, sortFields ...string) (result []*UserGroup, err error) {
	session, col := db.GetCol("UserGroup")
	defer session.Close()

	q := col.Find(query)

	usergroupSort(q, sortFields)

	err = q.All(&result)
	return
}
Beispiel #4
0
func UserFindByID(id string) (result *User, err error) {
	session, col := db.GetCol("User")
	defer session.Close()

	if !bson.IsObjectIdHex(id) {
		err = mgo.ErrNotFound
		return
	}
	err = col.FindId(bson.ObjectIdHex(id)).One(&result)
	return
}
Beispiel #5
0
func UserFind(query interface{}, limit int, offset int, sortFields ...string) (result []*User, err error) {
	session, col := db.GetCol("User")
	defer session.Close()

	q := col.Find(query).Limit(limit).Skip(offset)

	userSort(q, sortFields)

	err = q.All(&result)
	return
}
Beispiel #6
0
func UserFindOne(query interface{}, sortFields ...string) (result *User, err error) {
	session, col := db.GetCol("User")
	defer session.Close()

	q := col.Find(query)

	userSort(q, sortFields)

	err = q.One(&result)
	return
}
Beispiel #7
0
func UserGroupFindByIDs(id []string) (result []*UserGroup, err error) {
	session, col := db.GetCol("UserGroup")
	defer session.Close()

	ids := make([]bson.ObjectId, 0, len(id))
	for _, i := range id {
		if bson.IsObjectIdHex(i) {
			ids = append(ids, bson.ObjectIdHex(i))
		}
	}
	err = col.Find(db.M{"_id": db.M{"$in": ids}}).All(&result)
	return
}
Beispiel #8
0
func initUserIndex() {
	session, collection := db.GetCol(UserTableName)
	defer session.Close()

reEnsureUserName:
	if err := collection.EnsureIndex(mgo.Index{
		Key:    []string{"UserName"},
		Unique: true,
		Sparse: true,
	}); err != nil {
		println("error ensureIndex User UserName", err.Error())
		err = collection.DropIndex("UserName")
		if err != nil {
			panic(err)
		}
		goto reEnsureUserName

	}

}
Beispiel #9
0
func UserGroupRemoveAll(query interface{}) (info *mgo.ChangeInfo, err error) {
	session, col := db.GetCol("UserGroup")
	defer session.Close()

	return col.RemoveAll(query)
}
Beispiel #10
0
func UserGroupCol() (session *mgo.Session, col *mgo.Collection) {
	return db.GetCol(UserGroupTableName)
}