upd
This commit is contained in:
parent
d54829cafb
commit
20c88eed24
1
main.go
1
main.go
@ -46,6 +46,7 @@ const (
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
UserID64 int64 `json:"user_id"`
|
||||
Direction MsgDirection `json:"direction"`
|
||||
MsgText string `json:"msg"`
|
||||
|
8
sql.go
8
sql.go
@ -66,10 +66,12 @@ func initDB() {
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE msg (
|
||||
id BIGINT UNSIGNED NOT NULL
|
||||
,chat_id BIGINT UNSIGNED NOT NULL
|
||||
,user_id BIGINT UNSIGNED NOT NULL
|
||||
,direction ENUM('incoming', 'outgoing')
|
||||
,date TIMESTAMP NOT NULL
|
||||
,text VARCHAR(4096) NOT NULL
|
||||
,PRIMARY KEY (id, chat_id)
|
||||
) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_unicode_ci;`) // ,FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -79,13 +81,13 @@ func initDB() {
|
||||
}
|
||||
|
||||
func putMsg(m ChatWarsMessage) {
|
||||
stmt, err := db.Prepare(`INSERT INTO msg (id, user_id, direction, date, text)
|
||||
VALUES (?, ?, ?, FROM_UNIXTIME(?), ?);`)
|
||||
stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, direction, date , text)
|
||||
VALUES (?, ?, ?, ?, FROM_UNIXTIME(?), ?);`)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(m.MsgID64, m.UserID64, m.Direction, m.MsgDate, m.MsgText)
|
||||
_, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.Direction, m.MsgDate, m.MsgText)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user