© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•11mo ago
Drew

Proper type for relational query

How can I generically type for the result of a relational query? Am I supposed to be able to use SQLiteRelationalQuery? I'm having trouble getting types to work if so.

interface RelationalQueryFn<?> {
  (ids: string[]): SQLiteRelationalQuery<?>
}

function getData<Query extends SQLiteSelect, ?>(baseQuery: Query, relationalQueryFn: RelationalQueryFn<?>) {
  const { rowCount, data } = await paginatedQuery(baseQuery);
  const relatedData = await relatedQueryFn(data.map(({id}) => id))
  // cominbe and return result
}
interface RelationalQueryFn<?> {
  (ids: string[]): SQLiteRelationalQuery<?>
}

function getData<Query extends SQLiteSelect, ?>(baseQuery: Query, relationalQueryFn: RelationalQueryFn<?>) {
  const { rowCount, data } = await paginatedQuery(baseQuery);
  const relatedData = await relatedQueryFn(data.map(({id}) => id))
  // cominbe and return result
}

Also curious about the type for a relational query itself, not wrapped in a function, and perhaps one using
prepare()
prepare()
, but I'm using a function because sql.placeholder doesn't work with arrays.

Also, am using the beta with relational queries V2.
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

Infer type for relational query
Drizzle TeamDTDrizzle Team / help
3y ago
Infer return type for relational query with pagination
Drizzle TeamDTDrizzle Team / help
3y ago
Getting Type Error With Drizzle Relational Query
Drizzle TeamDTDrizzle Team / help
2mo ago
How to derive type from relational query?
Drizzle TeamDTDrizzle Team / help
3y ago