BMA*_*MAC 6 javascript postgresql heroku node.js knex.js
我们在使用Knex运行查询时设置Heroku/Postgres数据库时遇到了困难.我们已经设置了我们的heroku/postgres数据库并创建了我们的表,但我们很难通过Knex连接它.更糟糕的是,几乎没有关于将Heroku/Postgres与Knex或任何ORM连接起来的文档,所以试图弄清楚这些东西真的很痛苦.
这些是我尝试过的连接模式.
var knex = require('knex')({
client: 'pg',
connection: {
user: username,
password: password,
host: host,
port: port,
database: database,
ssl: true
}
}
});
Run Code Online (Sandbox Code Playgroud)
并且...注意ssl true是切换并一起删除所有无济于事.
var knex = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL,
ssl: true
}
});
Run Code Online (Sandbox Code Playgroud)
我们也尝试过这种模式:
var pg = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL
});
Run Code Online (Sandbox Code Playgroud)
我们还没有下载localdb的副本,所以我们运行的每个测试基本上都是一个git commit.我们基本上测试对我们的root(index.html)页面的GET请求的插入查询.因此,在对主页面的任何get请求中,它应该在我们的waterrates表中插入一些内容.如果我将它从插入切换到选择,它将返回一个对象,但您实际上无法看到对象中的任何数据.
我们试图使用的插件是:
knex.select('*').from('waterrates').then(function(rows){
return rows;
});
knex('waterrates').insert({name: 'pleeeaseee work'}, {rate: 100}).then(function(rows){
console.log(rows);
})
knex.select().
Run Code Online (Sandbox Code Playgroud)
我们实际上不确定错误的位置,因为尝试连接不会产生任何错误.这可能是愚蠢的,但我们不知道在哪里或如何解决这个问题.任何帮助将不胜感激!
谢谢,B
我安装了旧版本的PG导致了这个问题.我们更改了package.json文件以使用最新的PG.Heroku更新了它,它工作了!
作为旁注,如果将来有人看到这个,heroku需要SSL连接.在你工作的时候记住这一点.我上面提供的连接字符串应该适合所有人.
乙
归档时间: |
|
查看次数: |
3606 次 |
最近记录: |