davebanana
davebanana
DTDrizzle Team
Created by davebanana on 12/13/2023 in #help
How to define `PostgresJsTransaction` generic parameter based on schema?
Consider the following schema
import * as countrySchema from './schema/country';
import * as orderSchema from './schema/order';

export type Schema = {
countries: typeof countrySchema.countries;
orders: typeof orderSchema.orders;
orderTopupIds: typeof orderSchema.orderTopupIds;
};
import * as countrySchema from './schema/country';
import * as orderSchema from './schema/order';

export type Schema = {
countries: typeof countrySchema.countries;
orders: typeof orderSchema.orders;
orderTopupIds: typeof orderSchema.orderTopupIds;
};
to parameterize the database instance I can do this:
db: PostgresJsDatabase<Schema>
db: PostgresJsDatabase<Schema>
However how can I parameterize a PostgresJsTransaction based on my schemas?
tx: PostgresJsTransaction<Schema, any>;
tx: PostgresJsTransaction<Schema, any>;
How should I replace the any argument in the generic parameter of `PostgresJsTransaction? Thank you
3 replies
DTDrizzle Team
Created by davebanana on 11/22/2023 in #help
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.
6 replies