-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
39 lines (33 loc) · 802 Bytes
/
db.js
File metadata and controls
39 lines (33 loc) · 802 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
35
36
37
38
39
const Database = require("better-sqlite3");
function saveTyresToDb(data) {
const db = new Database("tyres.db");
db.exec(`
CREATE TABLE IF NOT EXISTS tyres (
id INTEGER PRIMARY KEY AUTOINCREMENT,
website TEXT,
brand TEXT,
size TEXT,
aspect_ratio TEXT,
radius TEXT,
price TEXT,
season TEXT
);
`);
const insert = db.prepare(`
INSERT INTO tyres (website, brand, size, aspect_ratio, radius, price, season)
VALUES (?, ?, ?, ?, ?, ?, ?)
`);
for (const tyre of data) {
insert.run(
tyre.website,
tyre.brend,
tyre.size,
tyre.aspect_ratio,
tyre.radius,
tyre.price,
tyre.season
);
}
console.log("Data successfully saved to tyres.db database");
}
module.exports = saveTyresToDb;