Skip to content

feat: remove 'db' from the tRPC 'ctx' for a massive typescript speed increase #2143

@anthnykr

Description

@anthnykr

Is your feature request related to a problem? Please describe.

I've worked with tRPC in large production codebases - having the db returned here in src/server/api/trpc slows down the typescript server massively.

export const createTRPCContext = async (opts: { headers: Headers }) => {
  const session = await auth();

  return {
    db,
    session,
    ...opts,
  };
}

Describe the solution you'd like to see

Remove db from the return and import db in tRPC routes instead. For example, await db.user.findUnique instead of await ctx.db.user.findUnique. This speeds it up significantly.

Describe alternate solutions

N/A

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions