forked from chanbakjsd/TerraOceanPlugin
go: db: Implement active level
parent
e97bc82606
commit
1963c773d6
@ -0,0 +1,23 @@
|
||||
package db
|
||||
|
||||
func GetActiveLevel(discordID string) (int, error) {
|
||||
rows, err := db.Query("SELECT level FROM activeLevel WHERE id=?", discordID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
if rows.Next() {
|
||||
var activeLevel int
|
||||
err := rows.Scan(&activeLevel)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return activeLevel, nil
|
||||
}
|
||||
return 0, ErrNotFound
|
||||
}
|
||||
|
||||
func AddActiveLevel(discordID string, addedLevel int) error {
|
||||
_, err := db.Exec("INSERT INTO activeLevel(id, level) VALUES(?, ?) ON DUPLICATE KEY UPDATE level=level+?", discordID, addedLevel, addedLevel)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue