database
This commit is contained in:
parent
711f4dfdc6
commit
b55d99ccfd
3
.gitignore
vendored
3
.gitignore
vendored
@ -110,5 +110,4 @@ dist
|
||||
credentials.json
|
||||
|
||||
.idea
|
||||
package-lock.json
|
||||
database.js
|
||||
package-lock.json
|
36
database.js
Normal file
36
database.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Postgres
|
||||
const Pool = require('pg').Pool;
|
||||
|
||||
// Postgres config.
|
||||
let postgresConfig = require("./credentials.json").postgres;
|
||||
|
||||
// Postgres initialization
|
||||
const pool = new Pool(postgresConfig);
|
||||
|
||||
async function createUser(userId, userName) {
|
||||
await pool.query('INSERT INTO users (user_id, user_name) VALUES ($1, $2)', [userId, userName]);
|
||||
let res = await pool.query('SELECT * FROM users WHERE user_id = $1', [userId]);
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
async function getUser(userId) {
|
||||
let res = await pool.query('SELECT * FROM users WHERE user_id = $1', [userId]);
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
async function userFinishedTheirThesis(userId, date, rt_date) {
|
||||
let res = await pool.query('UPDATE USERS SET FT_DATE = $1, RT_DATE = $2 WHERE USER_ID = $3', [date, rt_date, userId]);
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
async function reviewDateUpdate(userId, date) {
|
||||
let res = await pool.query('UPDATE USERS SET RT_DATE = $1 WHERE USER_ID = $2', [date, userId]);
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createUser,
|
||||
getUser,
|
||||
userFinishedTheirThesis,
|
||||
reviewDateUpdate
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user