Tag: postgresql

NodeJS和pg-promise,捕获PostgreSQLexception

我正在运行NodeJS和pg-promise以及PostgreSQL后端。 我创build了自己的TRIGGER,在某些情况下会引发exception。 事情在这方面正常工作。 但是有了pg-promise,我很难捕捉错误的名字。 使用这个代码: … .catch(function(err) { console.log(err); }); 我得到以下输出: [ { success: false, result: { [error: vote_limit_exceeded] name: 'error', length: 80, severity: 'ERROR', code: 'P0001', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'pl_exec.c', line: '3068', routine: 'exec_stmt_raise' […]

从nodejs调用postgres函数或存储过程的最佳/正确方法是什么?

我使用“pg”模块来处理postgresql数据库,如何使用pg调用函数我有疑问, 我正在使用查询方法调用函数, client.query("SELECT * FROM SQSP_IsUserNameExists($1)",[userName], function(err, result) { // some code. }); 这是工作正常,但这是正确的方式来调用postgresql函数。

ORM for postgresql / node.js

Node.js社区非常活跃。 postgresql / ORM至less有几个库。 现在 – 2012年3月 ,我正在寻找一个足够成熟,生产准备好和mongoose类似的产品。 请分享,如果你有任何真实的经验与他们。 是的,我见过这个问题,还有其他十几个人。

连接Postgres Heroku与Knex不工作

用Knex运行我们的查询,我们难以build立一个Heroku / Postgres数据库。 我们已经build立了我们的heroku / postgres数据库并创build了我们的表格,但是我们很难与Knex连接。 更糟糕的是,几乎没有关于将Heroku / Postgres与Knex或任何ORM连接的文档,所以试图找出这些东西是一个真正的痛苦。 这些是我试过的连接模式。 var knex = require('knex')({ client: 'pg', connection: { user: username, password: password, host: host, port: port, database: database, ssl: true } } }); 并且…请注意,ssl真正的切换和删除所有在一起无济于事。 var knex = require('knex')({ client: 'pg', connection: HEROKU_POSTGRESQL_COLOR_URL, ssl: true } }); 我们也尝试了这种模式: var pg = require('knex')({ client: 'pg', connection: HEROKU_POSTGRESQL_COLOR_URL […]

重复计数ORM中的多个计数查询

我想创build查询,它可以在sequelize.js一次在一个月的每一天的logging数不是像: Record.count({ where: { createdAt: { $like: '2015-04-14%' } } }).then(function(c) { console.log("2015-04-14 have been created" + c + "records"); }); Record.count({ where: { createdAt: { $like: '2015-04-15%' } } }).then(function(c) { console.log("2015-04-15 have been created" + c + "records"); }); Record.count({ where: { createdAt: { $like: '2015-04-16%' } } }).then(function(c) { console.log("2015-04-16 have been […]

用node-postgres监听查询超时?

我有一个Postgresql 9.1数据库上的“文章”表和一个通知每个插入通道的触发器。 我想创build一个node.js脚本来捕获这些插入,并使用Socket.io将通知推送到连接的客户端。 到目前为止,我正在使用node-postgres模块侦听通道,但似乎LISTEN查询在大约10-15秒后超时并停止捕获插入。 当超时发生时,我可以查询一个新的监听,但是我不确定如何正确执行延续。 这是我的postgresql通知过程: CREATE FUNCTION article_insert_notify() RETURNS trigger AS $$ BEGIN NOTIFY "article_watcher"; RETURN NULL; END; $$ LANGUAGE plpgsql; 触发: CREATE TRIGGER article_insert_trigger AFTER INSERT ON article FOR EACH ROW EXECUTE PROCEDURE article_insert_notify(); 和node.js代码: var pg = require ('pg'), pgConnection = "postgres://user:pass@localhost/db" pg.connect(pgConnection, function(err, client) { client.query('LISTEN "article_watcher"'); client.on('notification', function(data) { console.log(data.payload); […]

findOrCreate()和upsert()之间的区别

我正在阅读文档 ,它提到了两种做upsert的方法: findOrCreate()或upsert() 。 我阅读了描述,但是我还不清楚它们有什么不同。 upsert()继续说: Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated. 这是否意味着upsert()明确要求我在模型中定义一个id UNIQUE主字段? 即: var Something = sequelize.define("Something", { id: { type: DataTypes.INTEGER, […]

如何在Sequelize Postgres中使用小写函数

我正在尝试使用小写函数在Sequelize中进行stringsearch。 我设法使用ilike来做。 我的问题是如何在这种情况下使用小写函数? findAll使用ilike如下所示: Db.models.Person.findAll(where: {firstName: {$ilike: `somename`}}); 如何将其更改为lower(firstname) = lower('somename');

节点服务器无法连接到postgres数据库

我最近从MySQL切换到postgres作为我的数据库node.js项目。 虽然我能够从我的本地pgAdmin III(OSX)客户端到达远程postgres数据库,但到目前为止,我一直无法通过node.js连接到我的数据库。 我确定我为pgAdmin和我的node.jsinput的凭据是完全相同的。 我试过的另一件事是设置我的本地ipadress信任在我的数据库服务器的pg_hba.conf中的md5。 有什么我做错了吗? 我最喜欢的search引擎提出了一些关于重置我的本地操作系统的令人担忧的命中。 我只是使用了node-postgres的github repo文档中的例子: var pg = require('pg'); var conString = "postgres://myusername:mypassword@hostname:5432/dbname"; var client = new pg.Client(conString); client.connect(function(err) { if(err) { return console.error('could not connect to postgres', err); } client.query('SELECT NOW() AS "theTime"', function(err, result) { if(err) { return console.error('error running query', err); } console.log(result.rows[0].theTime); client.end(); }); }); 这些是我每次尝试启动服务器时遇到的错误: could […]

帆postgresql多对多协会不工作

我试图在两个模型,运营商和组之间build立多对多的关联。 两个模型是: -Operator.js var Operator = { connection:'postgresql', tableName: 'operator', schema:true, attributes: { firstName: { type: 'string', required: true, max: 64, columnName: 'first_name' }, lastName: { type: 'string', required: true, max: 64, columnName: 'last_name' }, birthDate: { type: 'date', columnName: 'birth_date' }, sex: { type: 'string', enum: ['M', 'F', 'NA'], columnName: 'sex' }, email: { […]