question about partial query for joins

I am running a query for 'table1', and have an inner join for the user related to 'table1' by userId, but I wanted to limit the columns for user, becuase as my query stands now, I am leaking password hashes and that's obv unsafe. Can someone point me in the right direction? It's late and I have been digging in the docs for something to alleviate this but I am trying not to resolve to using raw sql template. Here is my query as it stands:
const result = await db
.select()
.from(candidateProfileTable)
.where(eq(candidateProfileTable.id, candidateId))
.innerJoin(userTable, eq(candidateProfileTable.userId, userTable.id))
.innerJoin(disciplineTable, eq(candidateProfileTable.disciplineId, disciplineTable.id))
.innerJoin(regionTable, eq(candidateProfileTable.regionId, regionTable.id))
.leftJoin(subRegionTable, eq(regionTable.id, subRegionTable.regionId));
const result = await db
.select()
.from(candidateProfileTable)
.where(eq(candidateProfileTable.id, candidateId))
.innerJoin(userTable, eq(candidateProfileTable.userId, userTable.id))
.innerJoin(disciplineTable, eq(candidateProfileTable.disciplineId, disciplineTable.id))
.innerJoin(regionTable, eq(candidateProfileTable.regionId, regionTable.id))
.leftJoin(subRegionTable, eq(regionTable.id, subRegionTable.regionId));
2 Replies
Rich Prins
Rich PrinsOP•7mo ago
I think I figured it our with object mapping in the select, crazy what a little rest will do 😅
Mykhailo
Mykhailo•7mo ago
Hey @Richard Prins. Happy to hear that you solved your issue. We have guide for including/excluding columns in query, so it might be useful in future. https://orm.drizzle.team/learn/guides/include-or-exclude-columns By the way, could you please tell what are you building with Drizzle?
Drizzle ORM - Include or Exclude Columns in Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server