I'm trying to get pg-promise working in NodeJS to allow me to connect to my PostgreSQL database. Both node and postgre are running in a codeanywhere node box running Ubuntu.
Here's the relevant code:
var pgp = require('pg-promise')();
var bot = new TelegramBot(token, { polling: true });
var db = pgp({
host: 'localhost',
port: 5432,
database: 'users',
user: 'postgres',
password: '(pass here)'
});
db.any("select * from users")
.then(function (data) {
console.log(data);
})
.catch(function (error) {
console.log(error);
});
Running node bot.js
prints the following:
{ [error: relation "users" does not exist]
name: 'error',
length: 96,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '15',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '984',
routine: 'parserOpenTable' }
And prints the following to /var/log/postgresql/postgresql-9.3-main.log
:
2016-09-29 23:09:29 EDT ERROR: relation "users" does not exist at character 15
What did I do wrong? I guess it should be something with db.any(), as the following code does work:
//db.any("select * from users")
db.connect()
.then(function (data) {
console.log(data);
})
.catch(function (error) {
console.log(error);
});
The output is a return of something that looks approximately like the db
object, but that's not what I need...
I've seen other stackoverflow questions mentioning capitalization as an issue. Specifically, they say that postgresql will make your input all lowercase without double quotes. To dispell any such notion of relevance:
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------+-------+----------
public | users | table | postgres
(1 row)
The relation certainly does exist.
What am I missing?