await knex("inventory").del();
const data = await read(join(__dirname, '..', 'data', 'inventory.csv'), 'utf8');
+ const stats = {
+ created: 0,
+ skipped: 0
+ };
const items: Omit<ShopItem, 'id'>[] = [];
data.split("\r\n").slice(1).forEach(line => {
let pieces = line.split(',');
- if(pieces.length === 17) {
+ if(pieces.length === 17 && pieces[0].length) {
console.log('Adding', pieces[0]);
+ stats.created++;
items.push({
name: pieces[0],
type: pieces[1] as InventoryType,
});
}
else {
- console.log(`Skipped ${line}`);
+ stats.skipped++;
}
});
await knex('shop_items').insert(items);
+ console.log(stats);
};