szeth
szeth
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
(im on mobile so excuse the formatting and typos)
8 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
i personally prefer option 1 since getting it from the params seems a bit janky
8 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
i had this same problem today, solved it this way
8 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
type DB = NodePgDatabase<Schema>;

// option 1. extract it from the db object itself
type ExtractTQuery<T> = T extends PgDatabase<infer TQueryResult, infer Schema>
? [TQueryResult, Schema] : never;
type Transaction<T> = PgTransaction<ExtractTQuery<T>[0], ExtractTQuery<T>[1],
ExtractTablesWithRelations<ExtractTQuery<T>[1]>>;

type TX = Transaction<App.DB>;

// option 2 (extract it from the transaction method)
type TX = Parameters<DB[' transaction']>[0] extends (tx: infer T) => Promise<unknown>
? T: never
type DB = NodePgDatabase<Schema>;

// option 1. extract it from the db object itself
type ExtractTQuery<T> = T extends PgDatabase<infer TQueryResult, infer Schema>
? [TQueryResult, Schema] : never;
type Transaction<T> = PgTransaction<ExtractTQuery<T>[0], ExtractTQuery<T>[1],
ExtractTablesWithRelations<ExtractTQuery<T>[1]>>;

type TX = Transaction<App.DB>;

// option 2 (extract it from the transaction method)
type TX = Parameters<DB[' transaction']>[0] extends (tx: infer T) => Promise<unknown>
? T: never
8 replies