koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.37k stars 239 forks source link

Bug: @koishijs/plugin-database-mysql 升级后出现 Every derived table must have its own alias #1259

Closed shumyun closed 10 months ago

shumyun commented 10 months ago

Describe the bug

使用4.15.0版本时不会出现问题,这次升级4.15.4 时就出现问题: 源代码为 const count = await this.ctx.database.select('platform').where({ pid: 1, publish: { $ne: 1 }, }).execute((row) => $.count(row.id)); 提示错误: 2023-11-08 20:05:34 [W] mysql > SELECT count(distinct id) AS value FROM (SELECT id, pid, mid, publish, time, data FROM ‘platform’ zgkjgyjb WHERE pid = 1 AND publish != 1) 2023-11-08 20:05:34 [W] ESV.upload uploading BD : Error: ER_DERIVED_MUST_HAVE_ALIAS: Every derived table must have its own alias 为什么会出现这个 zgkjgyjb 这个乱码

Steps to reproduce

Expected behavior

Screenshots

No response

Versions

Additional context

No response

shumyun commented 10 months ago

忘记说了。现在用的 @koishijs/plugin-database-mysql 的版本是 5.5.5 之前用的版本不记得,是4.15.0 自带安装的。 目前解决的方案是 const _data = await this.ctx.database.select('platform').where({ pid: 1, publish: { $ne: 1 },}).execute(); 获取所有数据后,再使用 _data.length ;这样没问题!

shigma commented 10 months ago

Fixed by https://github.com/shigma/minato/commit/9208ce5b41fa9c5f2688ab991d1b6d5a7f481dc3