-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
35 lines (28 loc) · 757 Bytes
/
Copy pathdatabase.js
File metadata and controls
35 lines (28 loc) · 757 Bytes
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
import mysql from "mysql2"
const pool = mysql.createPool({
host: '127.0.0.1',
user: "root",
password: "password",
database: "KitchenWorks"
}).promise() // promise helps use the promise api feature a.k.a async await
export async function getItems(){
const result = await pool.query("SELECT * FROM Items")
const rows = result[0]
return rows
}
export async function getItem(id){
const [rows] = await pool.query(`
SELECT *
FROM Items
WHERE id = ?
`, [id])
return rows[0]
}
export async function createItem(food, date){
const [result] = await pool.query(`
INSERT INTO items (item, expiry_date)
VALUES (?,?)
`, [food, date])
const newId = result.insertId
return getItem(newId)
}