-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-transaction-v2.ts
More file actions
34 lines (27 loc) · 951 Bytes
/
query-transaction-v2.ts
File metadata and controls
34 lines (27 loc) · 951 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
31
32
33
34
import knex from 'knex';
const db = knex({
client: 'better-sqlite3',
connection: {
filename: './data.sqlite'
},
useNullAsDefault: true
});
async function findTransaction() {
try {
console.log('--- Buscando todas as transações de valor 100 ---');
const transactions = await db('transactions')
.select('transactions.*', 'accounts.name as account_name')
.join('accounts', 'transactions.account_id', 'accounts.id')
.whereRaw('ABS(amount - 100) < 0.01');
console.log('Transações encontradas:', JSON.stringify(transactions, null, 2));
const goals = await db('goals').select('*');
console.log('Metas:', JSON.stringify(goals, null, 2));
const accounts = await db('accounts').select('*');
console.log('Contas:', JSON.stringify(accounts, null, 2));
} catch (error) {
console.error('Erro ao consultar banco:', error);
} finally {
await db.destroy();
}
}
findTransaction();