Spaces:
Sleeping
Sleeping
File size: 949 Bytes
ac25f89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import { getDb } from './src/db';
async function testDelete() {
try {
const db = await getDb();
console.log('Inserting test loan...');
await db.run(
'INSERT INTO loans (person, type, amount, currency, date) VALUES (?, ?, ?, ?, ?)',
['Test Person', 'loaned', 500, 'USD', new Date().toISOString()]
);
let loans = await db.all('SELECT * FROM loans');
console.log(`Loans before delete: ${loans.length}`);
console.log('Deleting all loans...');
await db.run('DELETE FROM loans');
loans = await db.all('SELECT * FROM loans');
console.log(`Loans after delete: ${loans.length}`);
if (loans.length === 0) {
console.log('SUCCESS: Delete from loans works.');
} else {
console.log('FAILURE: Delete from loans did not work.');
}
process.exit(0);
} catch (error) {
console.error('Test failed:', error);
process.exit(1);
}
}
testDelete();
|