Tag: postgresql

使用node-postgres在utc中获取Postgres的“没有时区的时间戳”

我有一些时间戳存储为Postgrestypes的timestamp without time zone 。 我将以2013-12-20 20:45:27时间戳为例。 我打算这代表一个UTC时间戳。 在psql中,如果我运行查询SELECT start_time FROM table_name WHERE id = 1 ,我得到的时间戳string,如预期: 2013-12-20 20:45:27 。 但是,如果在我的Node应用程序中,我使用node-postgres库来运行相同的查询,我会在当地时区取回一个时间戳: Fri Dec 20 2013 20:45:27 GMT-0600 (CST) 。 这是一个Javascriptdate对象,但它已经存储为该时区。 我真正想要的是一个date对象(甚至只是一个string),代表2013-12-20 20:45:27 GMT+0000 。 我已经知道这一次是UTC。 我已经尝试在我的postgresql.conf文件中设置时区参数: timezone = 'UTC' ,结果没有区别。 我究竟做错了什么? 编辑 这个问题似乎是在这个文件中: https : //github.com/brianc/node-postgres/blob/master/lib/types/textParsers.js 如果从Postgres返回的datestring没有指定时区(即Z ,或+06:30 ,那么它只是构build一个JavaScriptdate对象,我相信这只会包括本地时区。更改我的应用程序以在DB中存储时区或覆盖此转换器。

Node.js,PostgreSQL错误:主机没有pg_hba.conf条目

我正在关注这篇文章(( http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/ )。我已经将我的应用程序部署到heroku,并使用express,node.js,尝试连接到我刚安装的Heroku中的PostgresSQL数据库,到达文章的最后,我使用命令 node myfile.js 我得到这个错误 error: no pg_hba.conf entry for host "…", user "…", database "…", … 我该如何去创build一个,并在我的应用程序目录中放置它? 下面是整个错误信息。 我更改了IP地址,用户和数据库的string,但它看起来基本上就像它。 events.js:72 throw er; // Unhandled 'error' event ^ error: no pg_hba.conf entry for host "00.000.000.00", user "username", database "databasename", SSL off at Connection.parseE (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:526:11) at Connection.parseMessage (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:356:17) at Socket.<anonymous> (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:105:22) at Socket.emit (events.js:95:17) at […]

尝试将我的node.js连接到Heroku PostgreSQL数据库。 在Heroku Postgres教程之后

我正在关注这两个Heroku教程: https://devcenter.heroku.com/articles/getting-started-with-nodejs 和 https://devcenter.heroku.com/articles/heroku-postgresql 我有'你好世界'的应用程序工作。 但是当我添加node.js代码连接到postgreSQL时,我收到了一个错误。 我的package.json { "name": "node-example", "version": "0.0.1", "dependencies": { "pg": "2.x", "express": "3.1.x" }, "engines": { "node": "0.10.x", "npm": "1.2.x" } } 我的web.js var express = require("express"); var app = express(); app.use(express.logger()); app.get('/', function(request, response) { response.send('Hello World!'); }); var port = process.env.PORT || 5000; app.listen(port, function() { console.log("Listening on […]

使用NodeJS的PostgreSQL JSONtypes的最佳方式是什么?

我在这里面临一些分析瘫痪。 使用NodeJS编程数据库有太多的select,我有点遗憾。 我正在使用Express来构build一个API服务器,该服务器将与移动设备上的HTML5应用程序通信。 我决定使用PostgreSQL,因为我的数据是“非常关系的”,PostgreSQL的新的JSON数据types将使我的生活变得更加容易。 不幸的是,我找不到任何PostgreSQL的库来利用新的JSON数据types或暴露它。 我想过使用Sequelize和有一个很好的ORM或通过使用原始pgsql模块滚动我自己的东西。 有人可以提供线索吗? 我会问一些NodeJS stackexchange,但我不认为我们有一个具体的这一点。

我如何正确地插入多个行与PG节点postgres?

单行可以像这样插入: client.query("insert into tableName (name, email) values ($1, $2) ", ['john', 'john@gmail.com'], callBack) 这种方法自动评论任何特殊字符。 我如何一次插入多行? 我需要实现这个: "insert into tableName (name, email) values ('john', 'john@gmail.com'), ('jane', 'jane@gmail.com')" 我可以只使用jsstring运算符手动编译这样的行,但是我需要添加特殊字符转义莫名其妙。

如果行存在则返回id,否则返回INSERT

我在node.js中写一个函数来查询一个PostgreSQL表。 如果该行存在,我想返回行中的id列。 如果它不存在,我想插入它并返回id( insert into … returning id )。 我一直在尝试变种的case , if else语句,似乎无法得到它的工作。

续集关联有一个,属于

问题是,我不能得到关系hasOne,它不急于加载状态types的对象。 所有查询都在现有的表上完成。 这里是客户表,最重要的是cst_state_type字段: module.exports = function(sequelize, DataTypes) { return sequelize.define('customer', { customer: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, allowNull: true, validate: { isNumeric: true } }, first_name: { type: DataTypes.STRING(100), validate: { isAlphanumeric: true } }, last_name: DataTypes.STRING(100), identity_code: { type: DataTypes.STRING(20), allowNull: true, validate: { isNumeric: true } }, note: DataTypes.STRING(1000), birth_date: DataTypes.DATE, […]

节点postgres与大量的查询

我刚开始使用node-postgres和node.js一起使用postgres。 我试图做的事情之一是写一个简短的js填充我的数据库,使用约20万条目的文件。 我注意到有一段时间(不到10秒),我开始得到“错误:连接终止”。 我不确定这是否是使用node-postgres的问题,或者是因为我发送了postgres垃圾邮件。 无论如何,这是一个简单的代码,显示了这种行为: var pg = require('pg'); var connectionString = "postgres://xxxx:xxxx@localhost/xxxx"; pg.connect(connectionString, function(err,client,done){ if(err) { return console.error('could not connect to postgres', err); } client.query("DROP TABLE IF EXISTS testDB"); client.query("CREATE TABLE IF NOT EXISTS testDB (id int, first int, second int)"); done(); for (i = 0; i < 1000000; i++){ client.query("INSERT INTO testDB VALUES […]

Postgres方言不工作在续集-m

运行Sequelize -m 在我的config.json "development": { "username": "root", "password": null, "database": "**********", "dialect": "postgres", "protocol": "postgres", "port": 5432, "host": "127.0.0.1" }, 出错: sequelize -m Loaded configuration file "config/config.json". Using environment "development". /usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10 throw new Error("The dialect " + sequelize.getDialect() + " is not support ^ Error: The dialect postgres is not supported. at new module.exports (/usr/local/lib/node_modules/sequelize/lib/transaction-manager.js:10:11) […]

在node.js中导入sql文件并针对PostgreSQL执行

我正在寻找一种有效的方法来获取一个原始的sql文件,并同步执行一个postgres数据库,类似于如果你通过psql运行它。 我有一个创build所有数据库,导入数据等sql文件我需要执行此使用node.js,但无法find任何模块,这会自动执行此操作。 对于node.js应用程序本身,我们使用node-postgres('pg'),knex.js和bookshelf.js。 我认为,尽pipe这是最好的。 我可以想到的另一种方法是读取完整的文件,用分号分隔,用空格replace换行符,修剪任何重复的空格,然后按照连续执行而不是asynchronous的方式逐个提交给pg。 如果这真的是最有效的方法,而且如果还没有图书馆来解决这个问题的话,我有点惊讶。 我有点犹豫,跳入它看到SQL语法本身可能是一个有点具有挑战性,我可能会意外地混搭起来。 事先澄清一下: psql不能使用,因为它没有安装在目标机器上 我select以sql本机forms开发和源代码控制sql语句,因为DBA使用和操作它更容易