Пример #1
0
func (self *BaseModel) PrepareSave() {
	if !self.Id.Valid() {
		self.Id = bson.NewObjectId()
	}

	if !(self.CreatedOn > 0) {
		self.CreatedOn = utils.EpochNow()
	}

	self.ModifiedOn = utils.EpochNow()
}
Пример #2
0
// Save updates the last seen time stamp if the record already exists for the user
// otherwise it creates one
func Save(args *RequestArgs) error {
	user := args.User
	appName := args.AppName
	org := args.Organization

	stats_query := utils.M{
		"user":     user,
		"app_name": appName,
		"org":      org,
	}

	save_doc := utils.M{
		"user":      user,
		"app_name":  appName,
		"org":       org,
		"timestamp": utils.EpochNow(),
	}

	return db.Conn.Upsert(db.StatsCollection, stats_query, save_doc)
}
Пример #3
0
func (self *MConn) Update(table string, query utils.M, doc utils.M) error {

	//Create a Session Copy and be responsible for Closing it.
	session := self.Session.Copy()
	db := session.DB(self.Dbname)
	defer session.Close()

	coll := db.C(table)
	var update_err error
	if len(doc) == 0 {
		update_err = errors.New(
			"Empty Update is blocked. Refer to " +
				"https://github.com/Simversity/blackjack/issues/1051",
		)
	} else {
		AlterDoc(&doc, "$set", utils.M{"updated_on": utils.EpochNow()})
		_, update_err = coll.UpdateAll(query, doc)
	}

	if update_err != nil {
		log.Println("Error Updating:", table, update_err)
	}
	return update_err
}