© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
peterzainzinger

Relational Query - how to call mapRelationalRow

I am trying to integrate drizzle orm with electric sql. I got pretty much everything working (with some hacks), the last remaining thing is live queries with relational queries. So my approach is the following:

type RunLiveResult<T extends SQLiteRelationalQuery<any, any>> =
T extends SQLiteRelationalQuery<any, infer R> ? R : never;

function useDrizzleRelationalLive<
const T extends SQLiteRelationalQuery<any, any>
>(
db: {
liveRaw(sql: Statement): LiveResultContext<any>;
},
rawQuery: T
): RunLiveResult<T> | undefined {
const selectQuery = useMemo(() => rawQuery.toSQL(), [rawQuery]);
const { results } = useLiveQuery(
db.liveRaw({
sql: selectQuery.sql,
args: selectQuery.params as any,
})
);

const unwrapped = Array.isArray(results)
? results.map(unwrapJsonValue)
: results;
return unwrapped as any;
}

So basically electric-sql gives me a useLiveQuery hook where I pass the raw sql + params of the relational query. This works fine, but the return type is not correct. I did read the drizzle source code, there I found "mapRelationalRow" https://github.com/drizzle-team/drizzle-orm/blob/d535e0b667bec3aad6d238a71cebc23de30c455f/drizzle-orm/src/relations.ts#L659 - the first 3 arguments are clear what to provide, but what about "buildQueryResultSelection" and "mapColumnValue" - are these properties on anything (exposed or not)
GitHub
drizzle-orm/drizzle-orm/src/relations.ts at d535e0b667bec3aad6d238a...
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - drizzle-team/drizzle-orm
drizzle-orm/drizzle-orm/src/relations.ts at d535e0b667bec3aad6d238a...
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to derive type from relational query?
Drizzle TeamDTDrizzle Team / help
3y ago
Nullable relational query?
Drizzle TeamDTDrizzle Team / help
3y ago
Relational query problem
Drizzle TeamDTDrizzle Team / help
3y ago
Unable to sort relational query
Drizzle TeamDTDrizzle Team / help
15mo ago