猫史档案馆


【box3】代码

用户:AbnormalLOGAbnormalLOG查看: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
`
}


回复

上一页1 页 / 共 1下一页
ZNS_哪吒ZNS_哪吒

沙发

点赞0


评论


浮生awa浮生awa

板凳

点赞0


评论