-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
40 lines (36 loc) · 1 KB
/
db.js
File metadata and controls
40 lines (36 loc) · 1 KB
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
const Pool = require('pg').Pool
pool = new Pool({
user: process.env.DB_ROLE,
host: process.env.DB_HOST,
database: process.env.DB_DBNAME,
password: process.env.DB_PWD,
port: process.env.DB_PORT
})
const getUsers = (req, res) => {
pool.query("SELECT * from users", (err, result) => {
if (err)
throw err
res.json({ status: true, response: result.rows })
})
}
const getUser = (req, res) => {
userId = req.params.userId;
pool.query("SELECT * from users where id = " + parseInt(userId) + "", (err, result) => {
if (err)
throw err
res.json({ status: true, response: result.rows })
})
}
const insertUser = (req, res) => {
const { name, email } = req.body
pool.query("insert into users (name,email) values ('" + name + "','" + email + "')", (err, result) => {
if (err)
throw err
res.json({ status: true, count: result.rowCount })
})
}
module.exports = {
getUsers,
getUser,
insertUser
}