Spaces:
Sleeping
Sleeping
File size: 1,037 Bytes
2dddd1f ac25f89 2dddd1f ac25f89 2dddd1f | 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 | import { getDb } from '../src/db';
async function test() {
console.log('Testing LibSQL connection...');
try {
const db = await getDb();
console.log('Database initialized.');
const wallets = await db.all('SELECT * FROM wallets');
console.log(`Found ${wallets.length} wallets.`);
if (wallets.length > 0) {
console.log('Testing insert with undefined parameter...');
// Inserting a transaction with undefined for optional fields
await db.run(
'INSERT INTO transactions (type, amount, currency, wallet_id, date, category, note) VALUES (?, ?, ?, ?, ?, ?, ?)',
['income', 100, 'USD', wallets[0].id, new Date().toISOString(), undefined, 'Test with undefined']
);
console.log('Insert with undefined parameter successful.');
}
console.log('SUCCESS: Database connection and parameter sanitization are working.');
process.exit(0);
} catch (error) {
console.error('FAILED: Database connection error:', error);
process.exit(1);
}
}
test();
|