© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
7 replies
KingKorai

Querying Best Practices?

Just want to discuss query best practices.
const userAccount = await db.query.accounts.findFirst({
    where: eq(accounts.id, userId),
    with: {
      activeProfile: {
        with: {
          savedShows: {
            where: eq(myShows.id, input.id),
            limit: 1, // Does using limit matter here? It should speed up query right?
          },
        },
      },
    },
  })
const userAccount = await db.query.accounts.findFirst({
    where: eq(accounts.id, userId),
    with: {
      activeProfile: {
        with: {
          savedShows: {
            where: eq(myShows.id, input.id),
            limit: 1, // Does using limit matter here? It should speed up query right?
          },
        },
      },
    },
  })

And since I only need the nested relations
const userAccount = await db.query.accounts.findFirst({
    columns: {}, // Would this matter? Does it speed up queries? It would transfer less data but is that all?
    where: eq(accounts.id, userId),
    with: {
      activeProfile: {
        with: {
          savedShows: {
            where: eq(myShows.id, input.id),
            limit: 1, 
          },
        },
      },
    },
  })
const userAccount = await db.query.accounts.findFirst({
    columns: {}, // Would this matter? Does it speed up queries? It would transfer less data but is that all?
    where: eq(accounts.id, userId),
    with: {
      activeProfile: {
        with: {
          savedShows: {
            where: eq(myShows.id, input.id),
            limit: 1, 
          },
        },
      },
    },
  })
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

testing best practices
Drizzle TeamDTDrizzle Team / help
3y ago
Best practices for complex queries
Drizzle TeamDTDrizzle Team / help
11mo ago
workflow best practices with planetscale
Drizzle TeamDTDrizzle Team / help
3y ago
Best practices for inferring types in queries?
Drizzle TeamDTDrizzle Team / help
12mo ago