用户:
AbnormalLOG查看:0 回复:2 评论:0 创建时间:2021-10-16T11:59:02
db.sql`CREATE TABLE IF NOT EXISTS playerdata (
score INT NOT NULL,
id CHAR(16) PRIMARY KEY UNIQUE NOT NULL
)`
async function load(e) {
e.score = 0
if (e.player.userKey) {
var data = await db.sql`SELECT * FROM playerdata WHERE id = ${e.player.userKey}`
if (data) {
e.score = data[0].score
} else {
await save(e)
}
}
}
async function save(e) {
return await db.sql`
INSERT INTO playerdata(
score,
id
) VALUES (
${e.score},
${e.player.userKey}
)
ON CONFLICT(id)
DO UPDATE SET
score=excluded.score
`
}