wallets-api / server /scripts /test-db.ts
z1amez's picture
v.2
ac25f89
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();