问题描述
我正在尝试使用knex和pg npm模块连接我的postgresql数据库。
如果我使用console.log(db.select('*').table('users'))
,那么效果很好,但是当我使用诸如
db.select('*').table('users').then(result => {
console.log(result);
})
然后返回类型错误。
完整代码->
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex');
const db = knex({
client: 'pg',connection: {
host: 'localhost',database: 'smart-brain'
}
});
db.select('*').table('users').then(result => {
console.log(result);
})
返回->
internal/crypto/hash.js:88
throw new ERR_INVALID_ARG_TYPE('key',^
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be one of type string,TypedArray,or DataView. Received type object at new Hmac (internal/crypto/hash.js:88:11)
at Object.createHmac (crypto.js:133:10)
at createHMAC (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg\lib\sasl.js:133:17)
at Hi (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg\lib\sasl.js:137:13)
at Object.continueSession (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg\lib\sasl.js:32:24) at Client._handleAuthSASLContinue (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg\lib\client.js:248:10)
at Connection.emit (events.js:198:13)
at parse (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg\lib\connection.js:109:12)
at Parser.parse (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg-protocol\dist\parser.js:40:17)
at Socket.stream.on (E:\Web Development\React\Smart Brain Project\smart-brain-api\node_modules\pg-protocol\dist\index.js:8:42)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)