Пример #1
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
}
Пример #2
0
func (d *database) insertComment(c *Comment) error {
	err := d.QueryRow("select floor from comments where item_id=? and item_type=? order by floor desc limit 1", c.ItemID, c.ItemType).Scan(&c.Floor)
	if err != sql.ErrNoRows && err != nil {
		gox.LError("insertComment", err)
		return err
	}
	c.Floor++
	_, err = d.Exec("insert into comments ("+commentFields+") values(?,?,?,?,?,?,?,?,?,?,?,?,?)",
		c.ID, c.UserID, c.ItemID, c.ItemType, c.ToCommentID, gox.JSONMarshalStr(c.Content), c.CreatedAt, c.Status, c.Floor,
		gox.JSONMarshalStr(c.AtUserIDs), c.Location, c.Lat, c.Lng)
	if err != nil {
		gox.LError("insertComment", err)
	}
	return err
}
Пример #3
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
}