divby0
divby0
Explore posts from servers
DTDrizzle Team
Created by divby0 on 10/3/2023 in #help
Get Raw query string of a relational query in drizzle
I need the raw query string of a relational query to perform an explain command. The docs only explain this process for the non-relational queries :/
7 replies
DTDrizzle Team
Created by divby0 on 5/9/2023 in #help
Many-to-Many joins results in weird values
Hey, I am new to Prisma, switching here from prisma so I can use a typesafe orm with D1 properly. I am trying to return a many-to-many joined result:
const teamedUser = await db.select().from(usersToTeams)
.where(eq(usersToTeams.user, user.id))
.innerJoin(users, eq(usersToTeams.user, users.id))
.innerJoin(teams, eq(usersToTeams.team, teams.id))
.all();
const teamedUser = await db.select().from(usersToTeams)
.where(eq(usersToTeams.user, user.id))
.innerJoin(users, eq(usersToTeams.user, users.id))
.innerJoin(teams, eq(usersToTeams.team, teams.id))
.all();
This already returns a correct structure:
[
{
usersToTeams: { user: 4, team: 2 },
users: {
id: 2,
email: '<email>',
password: '<password-hash>',
name: '<this field is undefined, but weirdly it puts in the users email>'
},
teams: { id: undefined, name: undefined }
}
]
[
{
usersToTeams: { user: 4, team: 2 },
users: {
id: 2,
email: '<email>',
password: '<password-hash>',
name: '<this field is undefined, but weirdly it puts in the users email>'
},
teams: { id: undefined, name: undefined }
}
]
The weird things are: - the name field of the user is not set (it's undefined in reality, if I use sqlite to look at the row), but my (maybe wrong) query fills it with the user's email?? - the teams object has only undefined values in it even though id as well as name are set - I'd like to not select the password field of the user, how can I do that? I tried looking up partial selects in combination with joined fields, but nothing that I tried worked I'd really appreciate help 🙂 drizzle really looks cool, I just have to learn a few more things, I guess. PS: if that matters, I am using the sqlite / D1 variant of drizzle 🙂
23 replies