一种基于blockly-null注入的自定义数据库方案

我为啥要取一个这么离谱的标题啊

准备材料:

  • Koishi >4.12.8
  • blockly-null 1.2.13

首先,我们要新建一个插件
找到空白块
image
然后摆出下图所示的块
image
空白块填入ctx.database.extend("数据库名",{ key: "string", value: "string", },{ primary: "key" })
此时,编译启用后因该可以在数据库页面中看到了


接下来,就是写入数据了
在写入数据的逻辑中插入空白块,写入ctx.database.upsert('数据库名',[{key:'你的键',value:'你的值'}],['key'])

发现问题了吗?
没错,他现在只能写入固定的值。至于怎么办,我不知道,问大佬去我们也可以在空白块中写入变量啊
例如


空白块代码为

ctx.database.upsert('数据库名',[{key:局部变量1,value:局部变量2}],['key'])
3 个赞
示例代码 一楼的

插件名称: 测试
导出时间: 2024/9/22 15:28:03
-=-=-=-=–=-=-=-=- BEGIN KOISHI BLOCKLY BLOCK V1 -=-=–=-=-=–=-=–=-=-=-
H4sIAAAAAAAAA91YaW/aTBD+LVGzogkGbHyDUIrBpJQQcpDzC1rwAgZf8QGmH/rb
u2sb7ABpaRW9Sl/JScbrmZ1nnpmdsQNEBZTLC+R6um1hqcJQ+LdjBBPdGmSW8Q9T
LBcZFgtUZGFptutFj3gF8E2yOLS1VbQSbTo07NHcS+8NaE0COEH36a409VoP7xSp
+isHJV4TKNBxjFXiW9eSZxeAV8cnP8LSZfUW2/bW9vzsmv3CJdohUZajsCJwvBTt
YTmBnwG33j+LPb3N4LECw2C2gYgXJRqIjYdpn3tsPUGhYtty/luiNdaRoWVcXda7
amI38sOiBn04hB4qotDHpH4GfIN4RKYTS1RkRe9ec7SqECnS8nxXtyZri33qC2gE
6LcGYnOPP8fVTehmvGHXsZA1PCH3YjN7UTv0jWzThJa2TWDNq7orYaGITbMLKx5i
1IunbP4EeZO/MhPJmC0X3vrQRymzDnShiXyUrcsIxW4SLKy4rusyGyPfWxcjf30C
flMY+AE0BhoaGRgFMRp4BJ2JLH872kF7icG1aycXBePTZeGB6Y+eGvlEayswjIxt
mIEPYxx0aBqWV4vZn/q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=-=–=-=-=–=-=–=-=-=-

样例1 将聊天记录存入temp数据表

插件名称: 测试2
导出时间: 2024/9/22 16:01:52
-=-=-=-=–=-=-=-=- BEGIN KOISHI BLOCKLY BLOCK V1 -=-=–=-=-=–=-=–=-=-=-
H4sIAAAAAAAAA11SUW+bMBD+LdNkQSZAkMZQ2FNQMk3aqNSpWrenyuBbwmIbhu2m
7KG/fcahxatlW3fnu/u+uzPKSrReP8Ig204YqUgCc/dMH1rx4JjNSaJ1lFwZIbAR
gnaDtE+4RHg3GeuOjtZik9asa05y0RkRB00O8H3JGgf/+5lM1lWNPcyovKWUwZkM
MCO3dH7Zfvv9LuZx/uHL38/43lAgZ7+7m72ebC2JBbCckji10aLXyiHVEMZq0pze
0F5Uh4rQjCVvWcS3hvX+ffX8o6w+fv3zsLt9Hn/2s9evFhh10G621X6Oa9RTRIki
NZEQ6V7CoHxPAe+94NKGE4yFf9dyiCYrIwp8bzQrrKqQGvT4eCw4L6T0AgFno+8m
F78i6hgNnRbUd8wrI6ymFTwSpqHwJchpCFHTCQVCrVC2s0PEpWeAPSObkPVkdTee
7uWDhBwUWaqjIJuh7dXyZeY2NB3nRCyNuOQwtTNwmpM4U+mY5sLxd/cUKwh/mQra
p6jE6LpE+2u0/YRy/AKr9euUNvWa4g3kYYYxDjdZXod1CldhAjTLN2maJ018qfcf
dUfomREDAAA=
-=-=–=-=-=–=-=-=-=- END KOISHI BLOCKLY BLOCK V1 -=-=–=-=-=–=-=–=-=-=-

3 个赞

:partying_face: :partying_face: :partying_face: :partying_face:
好厉害

想要研究的可以参考这个

3 个赞

哈哈,可惜我网络访问不了koishi.chat

2 个赞