Javascript 你看起来怎么样?您正在传递给res.json的那一个?@Odinn check edit请在使用wait@MarcinDomorozkido console.log(别名)后输出结果,然后查看它在@MarcinDomorozki之后打印了什么await@S
Javascript 你看起来怎么样?您正在传递给res.json的那一个?@Odinn check edit请在使用wait@MarcinDomorozkido console.log(别名)后输出结果,然后查看它在@MarcinDomorozki之后打印了什么await@S,javascript,mysql,node.js,typescript,express,Javascript,Mysql,Node.js,Typescript,Express,你看起来怎么样?您正在传递给res.json的那一个?@Odinn check edit请在使用wait@MarcinDomorozkido console.log(别名)后输出结果,然后查看它在@MarcinDomorozki之后打印了什么await@Shubh在“There is console.log of alias.”下,这个outputresults在“Query”类型上不存在,我只是举了一个例子,您可能需要选择其他内容,而不是盲目复制我的代码示例:)查看有关如何使用用于查询的库的示
你看起来怎么样?您正在传递给res.json的那一个?@Odinn check edit请在使用wait@MarcinDomorozkido console.log(别名)后输出结果,然后查看它在@MarcinDomorozki之后打印了什么await@Shubh在“There is console.log of alias.”下,这个outputresults在“Query”类型上不存在,我只是举了一个例子,您可能需要选择其他内容,而不是盲目复制我的代码示例:)查看有关如何使用用于查询的库的示例,可能是
.values
在您的情况下未定义,但请尝试找出需要从查询函数的返回中提取什么以传递到渲染,我们已经知道,不是整个返回值results不存在于“Query”类型上,我只是举了一个例子,您可能需要选择其他内容,而不是盲目复制我的代码示例:)看看如何使用您用来查询的库的示例,可能是.values
在我们的例子中是未定义的,但是试着找出需要从查询函数的返回中提取什么来传递到渲染,我们已经知道它不是整个返回值
public async aliasesList(req: Request, res: Response): Promise<void> {
const aliases = await pool.query('SELECT * FROM aliases');
res.json(aliases);
}
(node:20996) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Query'
| property '_timer' -> object with constructor 'Timer'
--- property '_object' closes the circle
at JSON.stringify (<anonymous>)
at C:\Users\rad\Desktop\Projekty\inv\backend\app\controllers\aliasesController.ts:27:14
at Generator.next (<anonymous>)
at C:\Users\rad\Desktop\Projekty\inv\backend\app\controllers\aliasesController.ts:8:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\rad\Desktop\Projekty\inv\backend\app\controllers\aliasesController.ts:4:12)
at aliasesList (C:\Users\rad\Desktop\Projekty\inv\backend\app\controllers\aliasesController.ts:35:16)
at Layer.handle [as handle_request] (C:\Users\rad\Desktop\Projekty\inv\backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\rad\Desktop\Projekty\inv\backend\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\rad\Desktop\Projekty\inv\backend\node_modules\express\lib\router\route.js:112:3)
(node:20996) 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:20996) [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.
Query {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_callback: undefined,
_callSite: Error:
at Pool.query (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\mysql\lib\Pool.js:199:23)
at C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:29:36
at Generator.next (<anonymous>)
at C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:8:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:4:12)
at aliasesList (C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:39:16)
at Layer.handle [as handle_request] (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\express\lib\router\route.js:112:3),
_ended: false,
_timeout: undefined,
_timer: Timer { _object: [Circular], _timeout: null },
sql: 'SELECT * FROM aliases',
values: undefined,
typeCast: true,
nestTables: false,
_resultSet: null,
_results: [],
_fields: [],
_index: 0,
_loadError: null
}
(node:32140) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Query'
| property '_timer' -> object with constructor 'Timer'
--- property '_object' closes the circle
at JSON.stringify (<anonymous>)
at stringify (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\express\lib\response.js:1123:12)
at ServerResponse.json (C:\Users\rad\Desktop\Projects\inv\backend\node_modules\express\lib\response.js:260:14)
at C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:30:25
at Generator.next (<anonymous>)
at fulfilled (C:\Users\rad\Desktop\Projects\inv\backend\app\controllers\aliasesController.ts:5:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:32140) 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:32140) [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.
public async aliasesList(req: Request, res: Response): Promise<void> {
const aliases = await pool.query('SELECT * FROM aliases');
res.json(aliases._results);
}