猫史档案馆


如何从sql升级到pg?

用户:AK亨利佐加DanJamesThomasAK亨利佐加DanJamesThomas查看:6 回复:4 评论:6 创建时间:2023-01-11T18:30:21


如何从sql升级到pg?呵呵,只需要在定义时做点手脚就可以了
代码:

(async () => {
    await db.sql`
        Create table if not exists "PgSQL" (
            "PIN" Text primary key  not null,
            "player" Text not null,
            "exp" INT not null
            "item" TEXT not null
        )`;
})();
world.onPlayerJoin(async function ({ entity }) {
    let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;
    if (fin.length != 0 && fin != null && entity.player.boxId != "") {
        entity.exp = fin[0].exp
    } else {
        entity.exp = 1
    }
    if (fin.length != 0 && fin != null) {
        db.sql`Update "PgSQL" Set "player" = ${entity.player.name} Where "PIN" = ${entity.player.userKey}`;
    }
    // 格式
    if(!entity.player.userKey)return;
    const yield = await db.sql`SELECT * FROM "PgSQL" Where "PIN" = ${entity.player.userKey}`;
    if(yield.length)return;
    
    });
async function Save(entity) {
    if (entity.player.boxId == "") return;//游客
    let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;
    if (!fin || !fin.length || fin == null) {
        await db.sql`
        Insert into "PgSQL" (
            "PIN",
            "player",
            "exp",
            "item"
        ) Values (
            ${entity.player.userKey},
            ${entity.player.name},
            ${entity.exp},
            ${entity.item}
        )`;
    } else {
        await db.sql`Update "PgSQL" Set "exp" = ${(entity.exp)} Where "PIN" = ${entity.player.userKey}`;
        await db.sql`Update "PgSQL" Set "item" = ${(entity.item)} Where "PIN" = ${entity.player.userKey}`;
    }
    return "Save Done!"
}
world.onPlayerLeave(async function({entity}){Save(entity)}) // 保存

非常适合打怪升级类的地图,也非常适合萌新大佬使用

解释代码:

Create table if not exists "PgSQL" entity.player.boxID=="" let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;
if (fin.length != 0 && fin != null && entity.player.boxId != "") {
entity.exp = fin[0].exp
} else {
entity.exp = 1
}

那么、、刑了,拿去代码试试吧,版权归我(亨利佐)BOX3尖头叉子所有


回复

上一页1 页 / 共 1下一页
AK亨利佐加DanJamesThomasAK亨利佐加DanJamesThomas

emm,不是我想要的结果,代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>如何从sql升级到pg?</title>
</head>
<body>
<b>如何从sql升级到pg?呵呵,只需要在定义时做点手脚就可以了</b>
<br />
<h1>代码:</h1>
<pre>
(async () => {
await db.sql`
Create table if not exists "PgSQL" (
"PIN" Text primary key not null,
"player" Text not null,
"exp" INT not null
"item" TEXT not null
)`;
})();
world.onPlayerJoin(async function ({ entity }) {
let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;
if (fin.length != 0 && fin != null && entity.player.boxId != "") {
entity.exp = fin[0].exp
} else {
entity.exp = 1
}
if (fin.length != 0 && fin != null) {
db.sql`Update "PgSQL" Set "player" = ${entity.player.name} Where "PIN" = ${entity.player.userKey}`;
}
// 格式
if(!entity.player.userKey)return;
const yield = await db.sql`SELECT * FROM "PgSQL" Where "PIN" = ${entity.player.userKey}`;
if(yield.length)return;

});
async function Save(entity) {
if (entity.player.boxId == "") return;//游客
let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;
if (!fin || !fin.length || fin == null) {
await db.sql`
Insert into "PgSQL" (
"PIN",
"player",
"exp",
"item"
) Values (
${entity.player.userKey},
${entity.player.name},
${entity.exp},
${entity.item}
)`;
} else {
await db.sql`Update "PgSQL" Set "exp" = ${(entity.exp)} Where "PIN" = ${entity.player.userKey}`;
await db.sql`Update "PgSQL" Set "item" = ${(entity.item)} Where "PIN" = ${entity.player.userKey}`;
}
return "Save Done!"
}
world.onPlayerLeave(async function({entity}){Save(entity)}) // 保存
</pre>
<p>非常适合打怪升级类的地图,也非常适合<del>萌新</del>大佬使用</p>
<p>解释代码:</p>
<abbr title="如果没有PgSQL,那么创建db数据库,再把它升级为Pg">Create table if not exists "PgSQL"</abbr>
<hr>
<abbr title="如果玩家是游客,那没有必要储存,在普通的sql里,常常因为玩家没有boxID,下次游客再来时没有必要读档,毕竟userKey也不同了,0所以不用存档,省得浪费空间,增加卡顿">entity.player.boxID==""</abbr>
<hr>
<abbr title="如果玩家第一次来,那么exp会是null,那么得给它一个值(1)">let fin = await db.sql`Select * from "PgSQL" Where "PIN" = ${entity.player.userKey}`;<br />
if (fin.length != 0 && fin != null && entity.player.boxId != "") {<br />
entity.exp = fin[0].exp<br />
} else {<br />
entity.exp = 1<br />
}<br /></abbr>
<p>那么、、刑了,拿去代码试试吧,版权归<del>我(亨利佐)</del>BOX3尖头叉子所有</p>
</body>
</html>

点赞0


评论


YJH于YYDSYJH于YYDS

?咋用())

点赞0


评论


治愈绾兮治愈绾兮

有没有一种可能,我可以让吉吉帮我升级()不过SQL貌似比pg好

点赞1


评论


萌新大佬萌新大佬

为什么适合我使用?

点赞0


评论