Exemple #1
0
func (u *User) Create(c *mgo.Collection) error {
	u.ID = bson.NewObjectId()
	u.Created = time.Now()
	u.Updated = time.Now()

	return c.Insert(u)
}
Exemple #2
0
func AddKeyword(org model.Organization, c *mgo.Collection) {
	keyword := model.Keyword{
		OrgID:     org.ID,
		Name:      org.Name,
		Short:     util.ShortenOrgName(org.Name),
		IsGeneral: true,
		Sub:       []string{},
	}
	c.Insert(keyword)
}
Exemple #3
0
func statsHandler(station storage.Station, cStatuses *mgo.Collection) storage.StationStats {
	var elevatorIds []string
	for _, stationElevator := range station.Elevators {
		elevatorIds = append(elevatorIds, stationElevator.ID)
	}
	var dbStatuses []dataStatus

	cStatuses.Find(bson.M{"elevator": bson.M{"$in": elevatorIds}}).
		Sort("lastupdate").
		All(&dbStatuses)

	events := statusesToEvents(dbStatuses)
	stats := statusesToStatistics(events)
	stats.Name = station.Name
	return stats
}
Exemple #4
0
func NextV(c *tmgo.Collection, id string, increase int64) (oldv int64, newv int64, err error) {
	var res = bson.M{}
	info, err := c.Find(bson.M{"_id": id}).Select(bson.M{"sequence": 1}).Apply(tmgo.Change{
		Update:    bson.M{"$inc": bson.M{"sequence": increase}},
		ReturnNew: true,
		Upsert:    true,
	}, &res)
	if err != nil {
		err = util.Err("require sequence(increase:%v) for %v fail, err:%v ", increase, id, err)
		return
	}
	if info.Updated != 1 && info.UpsertedId == nil {
		err = util.Err("require sequence(increase:%v) for %v fail, %v updated ", increase, id, info.Updated)
		return
	}
	newv = res["sequence"].(int64)
	oldv = newv - increase
	return
}
Exemple #5
0
Fichier : db.go Projet : saml/jscan
func findSubmittedData(c *mgo.Collection, ty string, skip int, limit int) ([]SubmittedData, error) {
	var a []SubmittedData
	err := c.Find(bson.M{"_type": ty}).Sort("-UpdateDate").Skip(skip).Limit(limit).All(&a)
	return a, err
}