Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define generic types for Drizzle Database and Transaction to be able to use them interchangeably #108

Open
mpellegrini opened this issue Aug 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mpellegrini
Copy link
Owner

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];
@mpellegrini mpellegrini added the enhancement New feature or request label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant