-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
41 lines (34 loc) · 892 Bytes
/
database.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
const mysql = require("mysql2/promise");
const dotenv = require("dotenv");
dotenv.config();
const pool = mysql.createPool({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE,
});
exports.getUsers = async () => {
const [rows] = await pool.query("SELECT * FROM users");
return rows;
};
/* 예시코드 */
/* export async function getNotes() {
const [rows] = await pool.query("SELECT * FROM notes");
return rows;
}
export async function getNote(id) {
const [rows] = await pool.query(`SELECT * FROM notes WHERE id = ?`, [id]);
return rows[0];
}
export async function createNote(title, contents) {
const [result] = await pool.query(
`
INSERT INTO notes (title, contents)
VALUES (?, ?)
`,
[title, contents]
);
const id = result.insertId;
return getNote(id);
}
*/