-
Notifications
You must be signed in to change notification settings - Fork 1
/
conexion_pg.js
110 lines (83 loc) · 2.07 KB
/
conexion_pg.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cors = require('./cors');
//var pg = require('pg').Pool();
//configurar cabeceras http
app.use(cors.permisos);
//body parser
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
const port = process.env.PORT || 4000;
*/
/*
const connectionData = {
user: 'postgres',
host: '193.146.116.148',
database: 'ex_vote_dev',
password: 'postgres',
port: 5432,
}
*/
/*
const client = new Client(connectionData)
//console.log("imprimiendo...")
console.log(client)
var rsclient = client.connect()
console.log(rsclient)
client.query('SELECT * FROM projects')
.then(response => {
console.log(response.rows)
client.end()
})
.catch(err => {
console.log("error")
client.end()
})
*/
const pg = require('pg');
const pool = new pg.Pool({
user: 'postgres',
host: 'localhost',
database: 'ex_vote_dev',
password: 'postgres',
port: '5432'
});
pool.query("DELETE FROM projects where title='OpenReq'", (err, res) => {
console.log(err, res);
});
pool.query("DELETE FROM tickets where project_id=1", (err, res) => {
console.log(err, res);
});
pool.end();
/*
var connectionString = "postgres://postgres:postgres@localhost:5432/ex_vote_dev";
var client = new pg.Client(connectionString);
client.connect();
var query = client.query("SELECT * FROM projects");
//fired after last row is emitted
console.log(query);
*/
/*
app.get('/', function (req, res, next) {
pg.connect(connectionString,function(err,client,done) {
if(err){
console.log("not able to get connection "+ err);
res.status(400).send(err);
}
client.query('SELECT * FROM projects',function(err,result) {
done(); // closing the connection;
if(err){
console.log(err);
res.status(400).send(err);
}
res.status(200).send(result.rows);
});
});
});
*/
/*
app.listen(port, function () {
console.log('Example app listening on port ' + port);
});
*/