-
Notifications
You must be signed in to change notification settings - Fork 16
Examples PostgreSQL Connection
Michael Anderson edited this page Dec 12, 2017
·
1 revision
The PostgreSQL driver connects to a local or remote PostgreSQL server over an IP connection. The PostgreSQL driver supports transactions.
postgres://[[username]:[password]@]host[:port]/database
const Connection = require('database-js2').Connection;
var connection = new Connection('postgres://user:password@localhost/data');
var Connection = require('database-js2').Connection;
(async function() {
let connection, statement, rows;
connection = new Connection('postgres://my_secret_username:my_secret_password@localhost:5432/my_top_secret_database');
try {
statement = await connection.prepareStatement("SELECT * FROM tablea WHERE user_name = ?");
rows = await statement.query('not_so_secret_user');
console.log(rows);
} catch (error) {
console.log(error);
} finally {
await connection.close();
}
})();