forked from chanbakjsd/TerraOceanPlugin
24 lines
585 B
Go
24 lines
585 B
Go
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
|
|
}
|