This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/db/xp.go

29 lines
689 B
Go

package db
import "fmt"
func IncrementXP(discordID string, amount int) error {
_, err := db.Exec(
"INSERT INTO xp(id, xp) VALUES(?, ?) ON CONFLICT(id) DO UPDATE SET xp = xp+?",
discordID, amount, amount,
)
if err != nil {
return fmt.Errorf("db: IncrementXP: underlying SQL error on 'insert' (%s, %d): %w", discordID, amount, err)
}
return nil
}
func GetXP(discordID string) (int, error) {
rows, err := db.Query("SELECT xp FROM xp WHERE id=?", discordID)
if err != nil {
return 0, fmt.Errorf("db: GetXP: underlying SQL error on 'select' (%s): %w", discordID, err)
}
defer rows.Close()
if rows.Next() {
var xp int
rows.Scan(&xp)
return xp, nil
}
return 0, nil
}