import { createClient } from '@libsql/client'; const client = createClient({ url: 'file:./data.db' }); const categories = { Boissons: ['café', 'thé', "jus d'orange", 'lait', 'eau gazeuse'], Crèmerie: ['fromage', 'yaourt', 'beurre', 'crème fraîche', 'oeufs'], 'Fruits & Légumes': [ 'pommes', 'bananes', 'tomates', 'salade', 'carottes', 'oignons', ], Epicerie: [ 'pâtes', 'riz', "huile d'olive", 'sel', 'poivre', 'farine', 'sucre', ], 'Viande & Poisson': ['poulet', 'saumon', 'boeuf haché', 'jambon'], Surgelés: ['pizza', 'glace', 'petits pois', 'frites'], }; for (const [catName, items] of Object.entries(categories)) { await client.execute({ sql: 'INSERT OR IGNORE INTO categories (name) VALUES (?)', args: [catName], }); const row = await client.execute({ sql: 'SELECT id FROM categories WHERE name = ?', args: [catName], }); const catId = Number(row.rows[0].id); for (const itemName of items) { await client.execute({ sql: `INSERT OR IGNORE INTO groceries (name, checked, created_at, category_id) VALUES (?, 0, datetime('now'), ?)`, args: [itemName, catId], }); } } const count = await client.execute('SELECT COUNT(*) as c FROM groceries'); console.log( `Done. ${count.rows[0].c} items in ${Object.keys(categories).length} categories.`, ); client.close();