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

26 lines
680 B
Go

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