107 lines
1018 B
JavaScript
107 lines
1018 B
JavaScript
require("dotenv").config();
|
|
|
|
const db = require("../config/database");
|
|
|
|
|
|
const categories = [
|
|
|
|
["Groente", "🥬"],
|
|
|
|
["Fruit", "🍎"],
|
|
|
|
["Zuivel", "🥛"],
|
|
|
|
["Brood", "🍞"],
|
|
|
|
["Dranken", "🥤"],
|
|
|
|
["Huishouden", "🧻"]
|
|
|
|
];
|
|
|
|
const products = [
|
|
|
|
[
|
|
"Melk",
|
|
3
|
|
],
|
|
|
|
[
|
|
"Bananen",
|
|
2
|
|
],
|
|
|
|
[
|
|
"Brood",
|
|
4
|
|
],
|
|
|
|
[
|
|
"Koffie",
|
|
5
|
|
],
|
|
|
|
[
|
|
"WC papier",
|
|
6
|
|
]
|
|
|
|
];
|
|
|
|
|
|
const insertProduct = db.prepare(`
|
|
|
|
INSERT OR IGNORE INTO products
|
|
|
|
(
|
|
name,
|
|
category_id
|
|
)
|
|
|
|
VALUES (?,?)
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
const seedProducts = db.transaction(() => {
|
|
|
|
|
|
for(const product of products){
|
|
|
|
insertProduct.run(product);
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
seedProducts();
|
|
|
|
const insert = db.prepare(`
|
|
|
|
INSERT OR IGNORE INTO categories
|
|
(name, icon)
|
|
|
|
VALUES (?,?)
|
|
|
|
`);
|
|
|
|
|
|
const seed = db.transaction(() => {
|
|
|
|
for (const category of categories) {
|
|
|
|
insert.run(category);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
seed();
|
|
|
|
|
|
console.log("Seed voltooid."); |