How to inspect generated query?

Hi I have the following:
const _results = await this.getDBContext()
.select()
.from(payouts)
.leftJoin(
userBankingAccounts,
eq(userBankingAccounts.id, payouts.bankAccountId),
)
.where(eq(userBankingAccounts.userId, affiliate.userId))
.where(and(...timeQuery))
.offset(pagination.offset)
.limit(pagination.limit)
.orderBy(orderQuery);
const _results = await this.getDBContext()
.select()
.from(payouts)
.leftJoin(
userBankingAccounts,
eq(userBankingAccounts.id, payouts.bankAccountId),
)
.where(eq(userBankingAccounts.userId, affiliate.userId))
.where(and(...timeQuery))
.offset(pagination.offset)
.limit(pagination.limit)
.orderBy(orderQuery);
the _results won't filtered based on affiliate.userId, what do I do wrong? Basically, I want to achieve this raw query:
select p.*, uba.id as uba_id from payouts p left join user_banking_accounts uba on p.bank_account_id = uba.id where uba.user_id = 7;
select p.*, uba.id as uba_id from payouts p left join user_banking_accounts uba on p.bank_account_id = uba.id where uba.user_id = 7;
Where .getDBContext() is returning either PostgresJsDatabase or PostgresJsTransaction.
3 Replies
Angelelz
Angelelz14mo ago
You can't call the .where method twice, the second will override the first onw You can pass all the conditions to an and function And to inspect the generated query, you can pass { logger: true } to drizzle function when you're intiantiating your db object
melodyclue
melodyclue14mo ago
Can the log be coloured according to query or mutation?
Angelelz
Angelelz14mo ago
I don't think drizzle have support for colored logs just yet
Want results from more Discord servers?
Add your server