-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (36 loc) · 1.04 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var pg = require('pg');
const pgClient = require('pg').Client;
//var conString = ":zhp@521224//myself:zhp@[email protected]:26000/postgres";
var cn = {
host: '124.70.46.225', // server name or IP address;
port: 26000,
database: 'postgres',
user: 'myself',
password: 'zhp@521224'
};
//var client = new pgClient(conString);
var client = new pgClient(cn);
client.connect(err => {
if (err) throw err;
else {
createDatabase();
client.end(console.log('close client connection'));
}
});
function createDatabase(){
const command = `
DROP TABLE IF EXISTS inventory;
CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);
`;
client
.query(command)
.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();
});
}