2014-12-19 27 views
0

的查詢不確定我試圖通過下面的代碼使用Knex.js上的Node.js:道在Knex.js

var Promise = require("bluebird"); 
var knex = require("knex")({ 
    client: 'pg', 
    user  : 'username', 
    database : 'database', 
    password: "password", 
    migrations: { 
     tableName: 'knex_migrations' 
    }, 
    pool: { 
     min: 0, 
     max: 7 
    } 
}); 

knex.select("*").from("users").then(function(rows){ 
    console.log(rows); 
}); 

但是,它扔約Runner對象的錯誤如下:

/path/to/myapp/node_modules/knex/lib/interface.js:27 
    return new Runner(this).run().then(onFulfilled, onRejected); 
     ^
TypeError: undefined is not a function 
    at QueryBuilder_PG.Target.then (/path/to/myapp/node_modules/knex/lib/interface.js:27:12) 
    at Object.<anonymous> (/path/to/myapp/test.js:14:32) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 
    at startup (node.js:119:16) 
    at node.js:906:3 

當我嘗試使用stream,pipe, exectransaction時,發生相同的錯誤。
請告訴我如何解決這個問題...

回答

1

我真的很粗心配置客戶端。 我錯誤地描述了「連接」。它必須寫成如下:

var Promise = require("bluebird"); 
var knex = require("knex")({ 
    client: 'pg', 
    connection: { 
     host  : '127.0.0.1', 
     user: 'username', 
     database: 'database', 
     password: 'password' 
    }, 
    migrations:{ 
     tableName:"knex_migrations" 
    }, 
    pool: { 
     min: 0, 
     max: 7 
    } 
}); 

knex.select("*").from("users").then(function(rows){ 
    console.log(rows); 
}); 

它工作沒有問題。
謝謝!

相關問題