Connecting Postgres Heroku with Knex does not work

We had difficulty setting up the Heroku / Postgres database, where Knex runs our queries. We created our heroku / postgres db file and created our tables, but it’s hard for us to contact it with Knex. Worse, there is almost no documentation on connecting Heroku / Postgres with Knex or ORM, so trying to understand this stuff was a real pain.

These are the connection models I tried.

var knex = require('knex')({ client: 'pg', connection: { user: username, password: password, host: host, port: port, database: database, ssl: true } } }); 

And ... Please note that ssl true was switched and deleted all together to no avail.

  var knex = require('knex')({ client: 'pg', connection: HEROKU_POSTGRESQL_COLOR_URL, ssl: true } }); 

We also tried this template:

 var pg = require('knex')({ client: 'pg', connection: HEROKU_POSTGRESQL_COLOR_URL }); 

We haven't pulled a copy of our localdb yet, so every run we run is basically a git commit. We mainly test the request to insert a GET request into our root page (index.html). Therefore, upon any receipt of a request to the main page, he should insert something into our water table. If I switch it from the insert to select, it returns an object, but you cannot see any data in the object.

The inserts we are trying to use are:

 knex.select('*').from('waterrates').then(function(rows){ return rows; }); knex('waterrates').insert({name: 'pleeeaseee work'}, {rate: 100}).then(function(rows){ console.log(rows); }) knex.select(). 

In fact, we are not sure where the error may be due to an attempt to connect, does not give any errors. This is probably something stupid, but we have no idea where and how this can be eliminated. Any help would be greatly appreciated!

Thank you in

+6
source share
1 answer

I had an old version of PG installed that was causing the problem. We modified our package.json file to use the latest version of PG. Heroku updated it and it worked!

As a side note, if someone looks at this in the future, the hero requires an SSL connection. Keep this in mind when working. The connection string above should work for all of you.

IN

+5
source

Source: https://habr.com/ru/post/976035/


All Articles