0

I wish to have connected more than 1 users at the same time, as follows:

// in node-postgres

const { Pool } = require('pg');

const pool_1 = new Pool({
    user: 'dbuser_1',
    host: 'database.server.com',
    database: 'mydb',
    password: 'secretpassword_1',
    port: 3211,
});

const pool_2 = new Pool({
    user: 'dbuser_2',
    host: 'database.server.com',
    database: 'mydb',
    password: 'secretpassword_2',
    port: 3211,
});

// in pg-promise

const initOptions = { ... };
const pgp = require('pg-promise')(initOptions);

const cn_1 = 'postgres://username_1:password_1@host:port/database';
const cn_2 = 'postgres://username_2:password_2@host:port/database';

const db_1 = pgp(cn_1);
const db_2 = pgp(cn_2);

dbuser_1 and dbuser_2 obviously have different privileges.

username_1 and username_2 obviously have different privileges, too.

Since I do not find any resource/info, (I suspect that all web projects in this tiny world use only single-user connection and multi-users connection apps, for some reason, are "strictly forbidden") I would like to ask if there are any known drawbacks?

Tia

PS: I apologize for combining the two projects in one question but I cannot wait for passing 90 minutes... Einstein and the limit of the universe! Βirdie hurts, then cut birdie! 30' minutes more... Tic, tac, tic, tac, tic tac... Fortunately, I am an engineer. Next time that I shall construct a car, I shall install an immobilizer, so as the driver to use it once every 90 minutes. Ha ha ha... Viva masturtyping!!! I am the inventor of the verb (masturtype) to describe the modern world and its derivatives (masturtyper, masturtypement, etc)! And for your encyclopedic information, I used them for first time in w3schools.com. I politely asked a question in the forum and I got a very impolite answer! Unfortunately, after this message the smart folks in SO will cancel my account, so I suspect it will take a long time to read from me again!!! Hasta la vista!

SONewbiee
  • 363
  • 2
  • 15
  • Check this out: https://github.com/dmfay/massive-js/issues/381. P.S. Try to avoid flooding in your question, please. – vitaly-t Jul 16 '18 at 17:58

1 Answers1

1

Your side-by-side code snippets for node-postgres and pg-promise are both valid, and the pg-promise example will produce the same logic underneath as your node-postgres code, creating two separate pools.

You can access each pool from your db_1 and db_2 objects, via property $pool.

There is nothing forbidden in this approach, it's quite a regular implementation.

vitaly-t
  • 24,279
  • 15
  • 116
  • 138