Skip to content

Commit

Permalink
test connection to Azure hosted PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Nov 17, 2023
1 parent 0b6c37f commit b96a31c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/test-pg-azure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const pg = require("pg");
require("dotenv").config();

const config = JSON.parse(process.env.azure);
const client = new pg.Client(config);

client.connect((err) => {
if (err) throw err;
else {
queryDatabase();
}
});

function 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);
DROP TABLE IF EXISTS inventory;
`;

client
.query(query)
.then(() => {
console.log("Table created successfully!");
client.end(console.log("Closed client connection"));
})
.catch((err) => console.log(err))
.then(() => {
console.log("Finished execution, exiting now");
process.exit();
});
}

0 comments on commit b96a31c

Please sign in to comment.