-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
37 lines (30 loc) · 932 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
import mysql from 'mysql2';
import dotenv from '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
}).promise();
export async function getUsername(username) {
const [rows] = await pool.query(`
SELECT username FROM account WHERE username = ?
`, [username]);
if (rows.length > 0) {
return rows[0].username;
}
return null;
}
export async function getPassword(username) {
const [rows] = await pool.query(`
SELECT password FROM account WHERE username = ?
`, [username]);
if (rows.length > 0) {
return rows[0].password;
}
return null;
}
export async function createUser(username, password) {
await pool.query('INSERT INTO account (username, password) VALUES (?, ?)', [username, password]);
}