Tag: postgresql

使用node-postgres从SELECT返回结果

无法从node-postgres中的SELECT查询中获取结果。 现在,在代码块的末尾,行是空的。 这个select只是从POSTGRESQL的一个序列中返回下一个值。 我知道你不能从callback中获取结果,但是在这里有没有人使用过node-postgres(或者任何其他数据库模块到节点)来解决这个问题? client.connect(); var query = client.query("SELECT nextval(\'idgenerator\');"); var rows = []; query.on('row', function(row, res) { rows.push(row); }); query.on('end', function(result) { console.log(result.rowCount + ' rows were received'); }); //client.end(); console.log(rows);

Heroku fork – 该附加计划仅适用于select用户

我在Heroku上部署了一个生产阶段的应用程序。 我想分发应用程序来build立一个临时环境。 Input heroku fork –from <app_name>-production –to <app_name>-staging Output Forking <app_name>-production… done. Forked to <app_name>-staging Setting buildpacks… done Adding newrelic:wayne to <app_name>-staging as NEW_RELIC… done Adding deployhooks:http to <app_name>-staging as DEPLOYHOOKS_HTTP… done Adding heroku-postgresql:standard-yanari to <app_name>-staging as HEROKU_POSTGRESQL_MAROON…! That add-on plan is only available to select users. There was an error forking to <app_name>-staging. […]

node.js postgres连接问题

我试图从node.js连接到postgres数据库,但我总是得到一些奇怪的错误 ENOTFOUND, Domain name not found 我使用的node.js模块是'pg'。 在几个例子中我看到了不同的连接string pg://, tcp:// and postgres:// 你能告诉我哪一个是正确的吗? 什么会导致这个问题?

使用Node.js将数据加载到Redshift中

使用node.js将数据插入Amazon Redshift的一些方法是什么? 这应该是非常简单的,但我无法find有效的加载的具体例子。

Sequelize对象不是一个函数

我正在从这个回购工作,并试图将其转换到PostgreSQL这里是我的错误: /home/otis/Developer/Shipwrecked/Hatchway/node_modules/sequelize/lib/sequelize.js:601 this.importCache[path] = defineCall(this, DataTypes); ^ TypeError: object is not a function at Sequelize.import (/home/otis/Developer/Shipwrecked/Hatchway/node_modules/sequelize/lib/sequelize.js:601:30) at db.sequelize (/home/otis/Developer/Shipwrecked/Hatchway/models/index.js:15:37) at Array.forEach (native) at Object.<anonymous> (/home/otis/Developer/Shipwrecked/Hatchway/models/index.js:14:6) 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 Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/otis/Developer/Shipwrecked/Hatchway/app.js:10:12) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) […]

使用node-postgres将文件存储在postgres中

我正在尝试使用node-postgres模块将一个小文件存储到postgres数据库中。 我明白,我应该使用bytea数据types来做到这一点。 我遇到的问题是当我做一些事情时: fs.readFile path, (err, data) -> client.query 'UPDATE file_table SET file = $1 WHERE key = $2', [data, key], (e, result) -> …. 数据库中文件列的内容是:\ x并且不存储任何内容。 如果我更改数据缓冲区为hex即data.toString('hex')文件存储,但所有格式都会丢失,当我读取文件退出。 使用node-postgres模块将文件存储到postgres中的正确方法是什么?

如何在Sequelize中以JSON的forms返回数据

当我做一个Sequelize查询它返回给我一个对象(或数组),我猜是一个Sequelize模型(或模型数组(集合types??)),但没有logging任何地方,所以我只是猜测。 我总是喜欢结果是JSON。 有什么我可以通过查询来强制这个? 如果可能的话,我宁愿不手动按摩每一个结果我回到JSON。 文档显示这个返回一个string: console.log(JSON.stringify(users)) 所以有一些内置的序列化。 现在我正在使用未toJSON()方法执行此操作: query().then(function(result) { if(result.length) { return result.toJSON(); } else { return result.map(function(item) { return item.toJSON(); }); } }); 这很麻烦。

如何设置nodejs的节点path(Ubuntu)

我试图设置nodejs来访问postgres数据库。 我到目前为止所做的是(https://gist.github.com/579814): echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc . ~/.bashrc mkdir ~/local mkdir ~/node-latest-install cd ~/node-latest-install curl http://nodejs.org/dist/node-latest.tar.gz | tar xz –strip-components=1 ./configure –prefix=~/local make install # ok, fine, this step probably takes more than 30 seconds… curl http://npmjs.org/install.sh | sh 然后 git clone git://github.com/isaacs/npm.git make make install 到现在为止还挺好。 但是,当我尝试安装postgres驱动程序 npm install pg 我得到以下内容: node-waf configure […]

续集:连接两次相同的表

背景: 我有一个与Userlang具有一对多关系的Userlang 。 例如: userlang.id userlang.userid userlang.lang +———–+—————+————-+ 1 1 EN 2 1 FR 3 1 IT 4 2 EN 5 2 DE 6 3 IT 我想select至less有一个userlang.lang=EN. 所有用户和他们的userlang userlang.lang=EN. 所以,我不能使用以下查询: Select USERS.id from USERS inner join USERLANG on USERS.ID=USERLANG.USERID where USERLANG.LANG="EN" 因为它只会selectlang="EN"的Userlangs行,而我想select每个用户的所有userlang行,其中至less有一个lang="EN" 我已经可以用SQL以两种方式编写这样的查询: 使用子查询: Select * from USERS inner join USERLANG on USERS.ID=USERLANG.USERID where USERS.ID […]

使用续集ORM连接到node.js上的Amazon RDS Postgres数据库的问题

我目前正在将在Heroku中设置的环境迁移到Amazon Web服务堆栈(RDS PostgreSQL,Elastic Beanstalk)。 尝试通过sequelize.js ORM连接到PostgreSQL时,我遇到了一些问题。 错误信息如下: 未处理的拒绝SequelizeHostNotFoundError:getaddrinfo ENOTFOUND [host]。 我可以通过pgAdmin连接到数据库,所以我知道服务正在工作,并且以下configuration在Heroku上工作: sequelize = new Sequelize(process.env.DATABASE_URI, { dialect: 'postgres', protocol: 'postgres', logging: true, timestamps: false }) DATABASE_URI格式如下: postgres://[db_username]:[db_password]@[hostname]:[port]/[db_name] 任何帮助将不胜感激。 提前致谢!