-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (38 loc) · 990 Bytes
/
Copy pathserver.js
File metadata and controls
46 lines (38 loc) · 990 Bytes
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
42
43
44
45
46
const pg = require('pg');
// const client = new pg.Client('postgresql://maxim:qvez21@localhost:5434/node_postgres_demo');
const client = new pg.Client(process.env.DATABASE_URL);
const seed = () => {
const qry = `
DROP TABLE IF EXISTS products;
CREATE TABLE products (
id SERIAL primary key,
name text
);
insert into products (name) values ('mizz') returning id
`;
client.query(qry, (err, result) => {
if(err){
console.log(err);
}
})
}
const connect = () => {
client.connect((err) => {
if(!err){
if(process.env.SEED){
seed();
}
}
// client.connect((err) => {
// if(!err){
// client.query('select * from foos', (err, result) => {
// if(err){
// console.log(err);
// }else {
// console.log(result);
// }
// })
// }
});
};
connect();