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 insertCategory = db.prepare(` INSERT INTO categories (name, icon) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM categories WHERE name = ?) `); const seedCategories = db.transaction(() => { for (const category of categories) { insertCategory.run(category[0], category[1], category[0]); } }); seedCategories(); const insertProduct = db.prepare(` INSERT INTO products (name, category_id) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM products WHERE name = ?) `); const seedProducts = db.transaction(() => { for(const product of products){ insertProduct.run(product[0], product[1], product[0]); } }); seedProducts(); console.log("Seed voltooid.");