Versie module 1 van 26-7
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
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.");
|
||||
Reference in New Issue
Block a user