diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-27 19:35:34 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-27 19:35:34 +0200 |
| commit | 2ded7d512470b2e9faabf2f61a0a97eef95a6f89 (patch) | |
| tree | ed03124918c87c6746f3540cb5b16c72746f4c94 /src | |
| parent | e14717b2e7853705469275d64023bb902b195ebb (diff) | |
chore: seed script for dev data (30 items, 6 categories)
Diffstat (limited to 'src')
| -rw-r--r-- | src/scripts/seed.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/scripts/seed.ts b/src/scripts/seed.ts new file mode 100644 index 0000000..ace763d --- /dev/null +++ b/src/scripts/seed.ts @@ -0,0 +1,53 @@ +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(); |
