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
2 Replies
davebanana
davebananaOP12mo ago
I found a way to use ExtractTablesWithRelation
export type SchemaWithRelations = ExtractTablesWithRelations<Schema>
export type SchemaWithRelations = ExtractTablesWithRelations<Schema>
Now that my PostgresJsTransction is defined as follow:
public tx: PostgresJsTransaction<Schema, SchemaWithRelations> | null;
public tx: PostgresJsTransaction<Schema, SchemaWithRelations> | null;
However when using .findMany() without specifying the columns, I get improper hinting.
davebanana
davebananaOP12mo ago
No description
Want results from more Discord servers?
Add your server