【发布时间】:2014-09-20 06:01:21
【问题描述】:
我正在尝试将我的 AngularJS 应用程序连接到 heroku 数据库。我在这里遵循本指南(http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/),我走到了最后,它甚至显示了我使用代码“client.query(INSERT INTO ...)”创建的所有数据,但我的问题是,它在我的实际目录中的什么位置存储我的数据?即使我通过我的 heroku 数据库的用户、密码、数据库等进行了连接,它也没有显示在我连接的 heroku 数据库中,但是它存储在某个地方。
我在 index.js 中的代码
var pg = require('pg');
var client = new pg.Client({
user: "herokudatabaseusername",
password: "herokudatabasepassword",
database: "herokudatabasebasename",
port: 0000,
host: "hostname",
ssl: true
});
client.connect();
client.query('CREATE TABLE IF NOT EXISTS table(id integer, name varchar(64), description varchar(1024), type varchar(128), ...etc');
client.query('INSERT INTO table(id, name, description, type, ...etc) values($1, $2, $3, ...etc)', [ 1, 'someinfo', 'moreinfo', ...etc]);
var query = client.query('SELECT id, name, description, type, ...etc, FROM table ORDER BY name');
query.on('row', function (row, result) {
result.addRow(row);
});
query.on('end', function (result) {
console.log(JSON.stringify(result.rows, null, ' '));
client.end();
});
在终端中运行我的“node index.js”命令两次后的示例输出
[
{
"id": 1,
"name": "...",
"description": "...",
"ect": "...",
"ect": "...",
...
...
...
},
{
"id": 1,
"name": "...",
"description": "...",
"ect": "...",
"ect": "...",
...
...
...
}
]
所以看起来数据持续存在,我只是不确定在哪里。
【问题讨论】:
标签: node.js angularjs postgresql heroku