package main import ( "github.com/bwmarrin/discordgo" ) func rewardShard(dg *discordgo.Session, discordID string) { tx, err := db.Begin() if err != nil { logError(dg, "rewardShard", "begin", discordID, err) return } _, err = tx.Exec("INSERT INTO shard(id, shard) VALUES(?, 1) ON CONFLICT(id) DO UPDATE SET shard = shard+1;", discordID) if err != nil { logError(dg, "rewardShard", "insert", discordID, err) tx.Rollback() return } err = tx.Commit() if err != nil { logError(dg, "rewardShard", "commit", discordID, err) return } } func getShard(dg *discordgo.Session, discordID string) int { rows, err := db.Query("SELECT shard FROM shard WHERE id=?", discordID) if err != nil { logError(dg, "getShard", "select", discordID, err) return 0 } defer rows.Close() if rows.Next() { var shard int rows.Scan(&shard) return shard } return 0 }