书架和knex初始化错误

时间:2015-10-30 20:46:35

标签: bookshelf.js knex.js

我正在尝试使用bookshelf和knex在节点js中设置mysql连接。这是我的设置:

var knex = require('knex')({
client: 'mysql',
  connection: {
    host     : '127.0.0.1',
    user     : 'my_user',
    password : 'my_password',
    database : 'my_db',
    charset  : 'utf8'
  }
});
var DB = require('bookshelf')(knex);
module.exports.DB = DB;

我收到以下错误:

Error: [object KnexClient] is not a valid Knex client, did you misspell it?
    at new Knex (/Users/arenduchintala/Projects/MacaronicWebApp/node_modules/bookshelf/node_modules/knex/knex.js:48:17)
    at new Bookshelf (/Users/arenduchintala/Projects/MacaronicWebApp/node_modules/bookshelf/bookshelf.js:43:14)
    at Bookshelf (/Users/arenduchintala/Projects/MacaronicWebApp/node_modules/bookshelf/bookshelf.js:37:14)
    at Object.<anonymous> (/Users/arenduchintala/Projects/MacaronicWebApp/db.js:11:37)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/arenduchintala/Projects/MacaronicWebApp/model.js:1:72)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

看起来这一行:require('bookshelf')(knex)会引发错误。

2 个答案:

答案 0 :(得分:1)

我有一个旧版本的书架,我在Node* head = NULL; Node* createNode() { Node* node = malloc(sizeof(*node)); node->value = 0; node->next = NULL; return node; } int main() { head = createNode(); ... } 中更改了: package.json"bookshelf" : "0.5",它似乎现在有效。

答案 1 :(得分:0)

运行 npm i --s mysql 它需要这个包裹