Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const pg = require('pg');
- const config = {
- host: 'mypgserver-20170401.postgres.database.azure.com',
- user: 'mylogin@mypgserver-20170401',
- password: '<server_admin_password>',
- database: '<name_of_database>',
- port: 5432,
- ssl: true
- };
- const client = new pg.Client(config);
- client.connect(err => {
- if (err) throw err;
- else { queryDatabase(); }
- });
- const queryDatabase = () => {
- const query = `
- DROP TABLE IF EXISTS inventory;
- CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);
- INSERT INTO inventory (name, quantity) VALUES ('banana', 150);
- INSERT INTO inventory (name, quantity) VALUES ('orange', 154);
- INSERT INTO inventory (name, quantity) VALUES ('apple', 100);
- `;
- client.query(query, err => {
- console.log('Connection established');
- if (err) throw err;
- else {
- client.end(err => {
- if (err) throw err;
- // Else closing connection finished without error
- console.log('Closed client connection');
- });
- console.log('Finished execution, exiting now');
- process.exit();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement