Beispiel #1
0
func (d *database) UpdateDevice(device *gox.Device) error {
	device.CreatedAt = time.Now().Unix()
	_, err := gox.ExecSQL(d.DB, `insert into devices(`+deviceFields+`) values(?,?,?,?)
	on duplicate key update user_id=?, badge=?, created_at=?`,
		device.Token, device.UserID, device.Badge, device.CreatedAt, device.UserID, device.Badge, device.CreatedAt)
	return err
}
Beispiel #2
0
func (d *database) Insert(userID gox.ID, n *Notice) error {
	n.ID = gox.NewID()
	n.NewCount = 1
	n.TotalCount = 1
	n.UpdatedAt = time.Now().Unix()
	_, err := gox.ExecSQL(d.DB, "insert into notices("+noticeFields+
		") values(?,?,?,?,?,?,?,?,?) on duplicate key update total_count=total_count+1, new_count=new_count+1",
		n.ID, userID, n.Type, n.ContentID, gox.JSONMarshalStr(n.Content), n.Title, n.TotalCount, n.NewCount, n.UpdatedAt)
	return err
}
Beispiel #3
0
func (d *database) InsertTopic(t *Topic) error {
	t.CreatedAt = time.Now().Unix()
	t.CommentedAt = t.CreatedAt
	t.ID = gox.NewID()
	_, err := gox.ExecSQL(d.DB,
		"insert into topics ("+topicFields+") values(?,?,?,?,?,?,?,?,?,?,?,?,?)",
		t.ID, t.UserID, t.ChannelID, gox.JSONMarshalStr(t.Content), t.CreatedAt, t.CommentedAt, t.Status,
		gox.JSONMarshalStr(t.Types), gox.JSONMarshalStr(t.Tags), gox.JSONMarshalStr(t.AtUserIDs),
		t.Location, t.Lat, t.Lng)
	return err
}
Beispiel #4
0
func (d *database) DelNotice(t NoticeType, contentID gox.ID) error {
	_, err := gox.ExecSQL(d.DB, "delete from notices where type=? and content_id=?", t, contentID)
	return err
}
Beispiel #5
0
func (d *database) ClearNewCount(userID gox.ID) error {
	_, err := gox.ExecSQL(d.DB, "update notices set new_count=0 where user_id=?", userID)
	return err
}
Beispiel #6
0
func (d *database) DelTopicAction(userID gox.ID, topicID gox.ID, action int) error {
	_, err := gox.ExecSQL(d.DB, "delete from topic_actions where topic_id=? and user_id=? and action=?", topicID, userID, action)
	return err
}
Beispiel #7
0
func (d *database) AddTopicAction(userID gox.ID, topicID gox.ID, action int) error {
	_, err := gox.ExecSQL(d.DB, "insert ignore into topic_actions(topic_id, user_id, action, created_at) values(?,?,?,?)",
		topicID, userID, action, time.Now().Unix())
	return err
}
Beispiel #8
0
func (d *database) DelTopic(topicID gox.ID) error {
	_, err := gox.ExecSQL(d.DB, "update topics set status=? where id=?", gox.StatusClosed, topicID)
	return err
}
Beispiel #9
0
func (d *database) RemoveImage(albumID gox.ID, albumType int, imgUrl string) error {
	id := calID(albumID, albumType, imgUrl)
	_, err := gox.ExecSQL(d.DB, "delete from albums where id=?", id)
	return err
}
Beispiel #10
0
func (d *database) InsertImage(albumID gox.ID, albumType int, img string) error {
	id := calID(albumID, albumType, img)
	_, err := gox.ExecSQL(d.DB, "insert ignore into albums("+albumsFields+") values(?,?,?,?,?,?)",
		id, gox.XTypeImage, img, time.Now().Unix(), albumID, albumType)
	return err
}
Beispiel #11
0
func (d *database) UpdateBadge(token string, badge int) error {
	_, err := gox.ExecSQL(d.DB, `update devices set badge=? where token=?`, badge, token)
	return err
}
Beispiel #12
0
func (d *database) DeleteDevice(token string) error {
	_, err := gox.ExecSQL(d.DB, "delete from devices where token=?", token)
	return err
}