Comments (17)
@slgluo 非常感谢你的帮助!subdatabases 为空说明 mysql 没有成功安装。你可以检查一下 koishi-database-mysql 是不是有其他的 koishi-core 作为依赖(简单来说就是看一下 koishi-database-mysql 的 node_modules 有没有 koishi-core)。Koishi 的数据库会采用注入的方式,因此如果 koishi-database-mysql 依赖的 koishi-core 不是你使用的,那么就会注入到错误的数据库中。
from koishi.
首先感谢你的持续支持!mua
这应该确实是 koishi-database-mysql 的 bug,我想下怎么弄,稍后给你回复。
初始化那个 issue 我本来计划自动检查数据库的表和字段然后自动补充的,但是想到 js 中的类型和 sql 中的类型没法做一一对应,所以放弃了这个想法。
from koishi.
刚刚发布了 koishi-database-mysql 1.0.4 版本,你可以检查一下是否能解决你的问题。
from koishi.
刚刚发布了 koishi-database-mysql 1.0.4 版本,你可以检查一下是否能解决你的问题。
那个异常没有出现了,但是抛了两个的新的异常:
- 这个是我在connect之后,调用app.database.getUser(app.selefId)出现的问题:
(node:7132) UnhandledPromiseRejectionWarning: TypeError: app.database.getUser is not a function
at EventEmitter.<anonymous> (F:\WebProject\tool-man\index.js:34:35)
at EventEmitter.emit (events.js:200:13)
at App.start (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:319:23)
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:7132) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7132) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
- 这个是收到消息时抛出的异常:
(node:7132) UnhandledPromiseRejectionWarning: TypeError: this.database.observeGroup is not a function
at Array.App._preprocess (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:134:55)
at next (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:199:103)
at EventEmitter.App._applyMiddlewares (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:206:19)
at EventEmitter.emit (events.js:200:13)
at App.emitEvent (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:348:30)
at HttpServer.dispatchMeta (F:\WebProject\tool-man\node_modules\koishi-core\dist\server.js:162:17)
at IncomingMessage.<anonymous> (F:\WebProject\tool-man\node_modules\koishi-core\dist\server.js:249:22)
at IncomingMessage.emit (events.js:205:15)
at endReadableNT (_stream_readable.js:1137:12)
at processTicksAndRejections (internal/process/task_queues.js:84:9)
(node:7132) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
你这样好调试吗,方便的话我可以把工程和一些必要的信息发给你
from koishi.
我这现在可以正常使用数据库,无法复现你的问题。你额外提供一些信息吧,比如 index.js 的内容。
from koishi.
我这现在可以正常使用数据库,无法复现你的问题。你额外提供一些信息吧,比如 index.js 的内容。
以下是index.js的所有内容:
const { App } = require('koishi')
require('koishi-database-mysql')
const lxPlugin = require('./plugin/liuxing')
const lxOptions = {
watchUser: '';,
watchGroup: '',
lxGroups: [ ]
}
const app = new App({
type: 'http',
port: 8080,
server: 'http://localhost:5700',
database: {
mysql: {
host: '',
port: 3306,
user: 'root',
password: '',
database: 'coolq'
},
}
})
app.user(975394636).command('状态')
.action(({ meta }) => meta.$send('正常'));
app.receiver.on('connect', async () => {
// 获取用户数据
let user = await app.database.getUser(app.selfId)
console.log("user:", user)
})
app.plugin(lxPlugin, lxOptions)
app.start()
其他的代码没有涉及到数据库,lxPlugin
这个插件是接收数据做一些处理,然后转发,其他没了
from koishi.
@slgluo 我这还是没法复现,你那 koishi 是 1.2.0 版本吗?
from koishi.
@slgluo 我这还是没法复现,你那 koishi 是 1.2.0 版本吗?
之前是v1.1.1的,然后我升级到1.2.0,还是还出现同样的问题
from koishi.
@shigma
我在调试过程中发现,database
这个属性就是一个空对象
- new App()时,在构造函数中:
this.options = { ...defaultOptions, ...options };
if (options.database && Object.keys(options.database).length) {
this.database = database_1.createDatabase(options.database);
}
- database_1.createDatabase()方法
function createDatabase(config) {
return new DatabaseManager(config).database;
}
- new DatabaseManager()时,构造函数中:
constructor(config) {
this.config = config;
this.database = {};
this.implicitTables = {};
// 我没有配置$tables属性,这个for方法不走
this.explicitTables = config.$tables || {};
for (const table in this.explicitTables) {
const name = this.explicitTables[table];
if (!config[name])
throw new Error(`database "${name}" not configurated`);
}
// subdatabases也为空,不走
for (const type in subdatabases) {
this.bindSubdatabase(type, config[type]);
}
}
以上,this.database = database_1.createDatabase(options.database)
,这个最终为{}
空对象,所以app.database为{}
。
所以,这个要怎么配置呢,还是我配置错了
from koishi.
@slgluo 非常感谢你的帮助!subdatabases 为空说明 mysql 没有成功安装。你可以检查一下 koishi-database-mysql 是不是有其他的 koishi-core 作为依赖(简单来说就是看一下 koishi-database-mysql 的 node_modules 有没有 koishi-core)。Koishi 的数据库会采用注入的方式,因此如果 koishi-database-mysql 依赖的 koishi-core 不是你使用的,那么就会注入到错误的数据库中。
koishi-database-mysql
有koishi-core
依赖,我重新安装依赖之后,解决了上面的问题。但是又出现以下问题:
(node:5236) UnhandledPromiseRejectionWarning: Error: Handshake inactivity timeout
at Handshake.<anonymous> (F:\WebProject\tool-man\node_modules\mysql\lib\protocol\Protocol.js:160:17)
at Handshake.emit (events.js:200:13)
at Handshake._onTimeout (F:\WebProject\tool-man\node_modules\mysql\lib\protocol\sequences\Sequence.js:124:8)
at Timer._onTimeout (F:\WebProject\tool-man\node_modules\mysql\lib\protocol\Timer.js:32:23)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
--------------------
at Protocol._enqueue (F:\WebProject\tool-man\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (F:\WebProject\tool-man\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (F:\WebProject\tool-man\node_modules\mysql\lib\Connection.js:119:18)
at Pool.getConnection (F:\WebProject\tool-man\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (F:\WebProject\tool-man\node_modules\mysql\lib\Pool.js:202:8)
at F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\database.js:51:27
at new Promise (<anonymous>)
at MysqlDatabase.query (F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\database.js:50:20)
at MysqlDatabase.select (F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\database.js:62:25)
at MysqlDatabase.getGroup (F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\group.js:17:35)
(node:5236) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 13)
o(╯□╰)o
from koishi.
@slgluo 这个是连接都出错了,你尝试着重新运行。同时问一下你的 mysql 版本(我测试用的是 5.x)?
from koishi.
@slgluo 这个是连接都出错了,你尝试着重新运行。同时问一下你的 mysql 版本(我测试用的是 5.x)?
mysql 5.7.28,我连接的远程的mysql,用nvacat可以远程连接,应该没问题,可以连接。我再确认一下,是koishi配置好之后,mysql什么都不用动吗,不需要手动创建数据库和表是吧?
from koishi.
@slgluo 那应该不是这方面的问题,我也是远程连接成功的。Koishi 配置好后,MySQL 是要创建数据库和表的。数据库应该与你 mysql 的配置相符合,表有两个 user 和 group,文档中有它们的细节。如果想详聊的话可以给我邮件,我们交换一下社交账号。
from koishi.
@slgluo 那应该不是这方面的问题,我也是远程连接成功的。Koishi 配置好后,MySQL 是要创建数据库和表的。数据库应该与你 mysql 的配置相符合,表有两个 user 和 group,文档中有它们的细节。如果想详聊的话可以给我邮件,我们交换一下社交账号。
from koishi.
数据库初始化时应当自动检查数据表并创建,而非手动处理
from koishi.
数据库初始化时应当自动检查数据表并创建,而非手动处理
@masnn 你说的对,后面应该会支持的。顺便这可能是另一个 issue 的事情了(
from koishi.
这个 issue 已经长期没有更新,在此期间 koishi 也更新了很多版本,上面的问题很可能已经无法复现了,因此我会把它关掉。如果还有问题可以另开一个 issue。
from koishi.
Related Issues (20)
- Feature: Schema的table列添加对hidden和disabled的支持 HOT 1
- Feature: Schema.number()添加显示成正常文本框的role HOT 3
- Bug: 使用 `yarn pub` 发布包但是失败时仍然显示成功发布
- Bug:failed to chmod data folder bin: chmod HOT 1
- Bug: discord 适配器 `getMessageList` 中获得的消息没有 `quote.id`
- Bug: Telegram 群聊报错 HOT 5
- Bug: Telegram 群聊内点击按钮报错 HOT 3
- Bug: 文档搜索颜色错误
- Bug: sqlite无法更新仅Date类型发生更改的数据 HOT 1
- Bug: mysql数据库使用漂流瓶插件存入图片地址时报错 HOT 2
- Bug: help 会显示没有权限的指令
- Bug: Sqlite 使用 `regexFor` 报错 HOT 2
- Bug: TG answerCallbackQuery bug
- Bug: path类型的配置项没有文件选择器 HOT 4
- Bug: 在控制台重载配置后,插值失效 HOT 1
- Bug: 指令管理command 无法配置option选项权限
- Feature: session.quote提供的信息不足,无法判断回复的消息的发送人是谁, HOT 2
- Bug: 消息元素 `quote` 失效 HOT 3
- Feature: Database Model 添加更多数据类型支持
- Bug: ctx.broadcast 在携带 channels 参数时无法工作 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koishi.