-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusersDBC.js
More file actions
59 lines (48 loc) · 1.97 KB
/
Copy pathusersDBC.js
File metadata and controls
59 lines (48 loc) · 1.97 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const mysql = require('mysql2');
const dbConfig = require('./config/database');
// Create the connection pool using the configuration
const pool = mysql.createPool(dbConfig);
const getUsers = async ()=>
{
const promisePool = pool.promise(); // proimise 기반: js 에서 비동기 작업을 위한 패턴, 작업이 완료된 후의 처리를 정의하는 방식
const [rows] = await promisePool.query('SELECT * FROM users ORDER BY Time;');
console.log(rows);
return rows;
};
const Received = async (userId) => {
const promisePool = pool.promise();
const [rows] = await promisePool.query('UPDATE users SET Receipt = 1 WHERE ID = ?', [userId]);
console.log(rows);
return rows;
};
const NotReceived = async (userId) => {
const promisePool = pool.promise();
const [rows] = await promisePool.query('UPDATE users SET Receipt = 0 WHERE ID = ?', [userId]);
console.log(rows);
return rows;
};
const UpdateAlphabet = async (userId, Alphabet) => {
const promisePool = pool.promise();
const [rows] = await promisePool.query('UPDATE users SET Alphabet = ? WHERE ID = ?', [Alphabet, userId]);
console.log(rows);
return rows;
};
// const insertUser = async (values)=>{
// const promisePool = pool.promise();
// const [rows] = await promisePool.query('INSERT INTO users (user_id, user_password, user_name) values (?, ?, ?)', values);
// return rows;
// };
// const deleteUser = async (userId) => {
// const promisePool = pool.promise();
// const [rows] = await promisePool.query('DELETE FROM users WHERE user_id = ?', [userId]);
// return rows;
// };
// const updateUser = async (userId, updatedValues) => {
// const promisePool = pool.promise();
// const [rows] = await promisePool.query('UPDATE users SET user_password = ?, user_name = ? WHERE user_id = ?', [...updatedValues, userId]);
// return rows;
// };
module.exports =
{
getUsers, Received, NotReceived
};