Created
June 15, 2018 12:45
-
-
Save 2garryn/7e8329cc9d95b1705ec12c31fcdd0e5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func message_new() (hnd eventHandler, name string, stmt string) { | |
type newMessage struct { | |
Date json.Number `json:"date"` | |
UserId json.Number `json:"user_id"` | |
} | |
table := config.GetDbConfig().Database + ".event_message_new" | |
name = "message_new" | |
stmt = "insert into " + table + "(groupid,timestamp,sender,unique_key,amount) VALUES($1,$2,$3,$4,1) on conflict(unique_key) DO UPDATE SET amount=event_message_new.amount + 1;" | |
hnd = func (groupid string, object json.RawMessage, inserter database.EventInserter) error { | |
var nm newMessage | |
err := json.Unmarshal(object, &nm) | |
if err != nil { | |
fmt.Println("Event object error ", err) | |
return errors.New("parse error") | |
} | |
d := string(nm.Date) | |
u := string(nm.UserId) | |
err1 := inserter(name, groupid, d, u, groupid + "_" + u) | |
return err1 | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment