szeth
szeth
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
option 1 should, since i’m just creating the PgTransaction type the same way it’s done internally in drizzle
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
option 2 will, it just takes the return type. it’s just ugly
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
and i dont work for drizzle so idk if it’s planned
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
that’s why i had to use these helpers but yeah not ideal
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
i completely agree, i looked through the source code to see if such a type was exposed but nopes
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
(im on mobile so excuse the formatting and typos)
16 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
16 replies
DTDrizzle Team
Created by Jakesdoc on 10/8/2024 in #help
Transaction Type
i had this same problem today, solved it this way
16 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
16 replies