-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_db.js
More file actions
30 lines (26 loc) · 1020 Bytes
/
debug_db.js
File metadata and controls
30 lines (26 loc) · 1020 Bytes
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
const { app } = require('electron');
const path = require('path');
const Database = require('better-sqlite3');
app.on('ready', () => {
try {
const dbPath = path.join(app.getPath('userData'), 'pos.db');
console.log('DB Path:', dbPath);
const db = new Database(dbPath);
console.log('--- Sales Table Schema ---');
const columns = db.prepare('PRAGMA table_info(sales)').all();
console.log(columns.map(c => c.name).join(', '));
console.log('\n--- Latest Credit Sale ---');
const creditSale = db.prepare(`
SELECT cs.*, s.subtotal as sale_subtotal, s.tax_amount as sale_tax, s.total as sale_total
FROM credit_sales cs
LEFT JOIN sales s ON cs.sale_id = s.id
ORDER BY cs.created_at DESC
LIMIT 1
`).get();
console.log(JSON.stringify(creditSale, null, 2));
process.exit(0);
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
});