© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•15mo ago•
5 replies
mattiskristensen

Passing transaction to functions

Hey everyone. Quite new to the drizzle sphere. Coming from Go, i am quite used to passing db transactions from function to function, to be able to orchestrate a bigger function from smaller ones.

As an example, say i have some music track. each track can have multiple genres, and each genre could be associated with different tracks - a many-to-many relationship.

Essentially, i would love to be able to create this chain of functions:

const getCompleteTrackById(id: number): Promise<CompleteTrack> => {
  await db.transaction(async (tx) => {
    const baseEvent = await getTrackById(tx, id);
    const genres = await getTrackGenres(tx, id);
    return {
      ...baseEvent,
      genres,
    }
})
const getCompleteTrackById(id: number): Promise<CompleteTrack> => {
  await db.transaction(async (tx) => {
    const baseEvent = await getTrackById(tx, id);
    const genres = await getTrackGenres(tx, id);
    return {
      ...baseEvent,
      genres,
    }
})


This, to make me able to use the
getTrackGenres
getTrackGenres
function independently for other types of queries, aswell as make code more readable. Is this possible somehow with TypeScript?

Thanks in advance!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Passing SQL functions to insert
Drizzle TeamDTDrizzle Team / help
3y ago
Versatile functions with transaction support
Drizzle TeamDTDrizzle Team / help
9mo ago
Having CRUD functions and Transaction Support
Drizzle TeamDTDrizzle Team / help
3y ago
Passing column values through custom TypeScript functions ...
Drizzle TeamDTDrizzle Team / help
2y ago