Open mpellegrini opened 1 month ago
const doWork = (..., tx: Transaction = db) {}
By doing this a given function can either be a standalone database operation or can be part of a higher up defined transaction
Here is one way to define the types
export type DB = typeof db; export type TX = Parameters<Parameters<DB['transaction']>[0]>[0]; export type DbOrTx = DB | TX;
and here is another
export type Transaction = | typeof db | Parameters<Parameters<typeof db.transaction>[0]>[0];
By doing this a given function can either be a standalone database operation or can be part of a higher up defined transaction
Here is one way to define the types
and here is another