n1xx1
n1xx1
Explore posts from servers
DTDrizzle Team
Created by n1xx1 on 2/5/2024 in #help
one-to-one relations with query, use joined table in where
I have something like this:
export const thingUsers = sqliteTable(...)
export const users = sqliteTable(...)

export const thingUsersRelations = relations(thingUsers, ({ one, many }) => ({
user: one(users, {
fields: [thingUsers.userId],
references: [users.id],
relationName: "user",
}),
thing: one(thing, {
fields: [thingUsers.thingId],
references: [thing.id],
relationName: "thingUser",
}),
}));

await db.query.thingUsers
.findMany({
with: {
user: true,
thing: true,
},
where: eq($.thing.publicId, publicThingId),
});
export const thingUsers = sqliteTable(...)
export const users = sqliteTable(...)

export const thingUsersRelations = relations(thingUsers, ({ one, many }) => ({
user: one(users, {
fields: [thingUsers.userId],
references: [users.id],
relationName: "user",
}),
thing: one(thing, {
fields: [thingUsers.thingId],
references: [thing.id],
relationName: "thingUser",
}),
}));

await db.query.thingUsers
.findMany({
with: {
user: true,
thing: true,
},
where: eq($.thing.publicId, publicThingId),
});
Which obviously doesn't work, because thing is not joined but is instead "requested" via a subquery in the select clause. Is there any plan on implementing this feature or I should just rely on the query builder? Thanks.
1 replies
TTCTheo's Typesafe Cult
Created by n1xx1 on 5/11/2023 in #questions
Typescript Inference for getServerSideProps-like function
So I'm having some issues with type inference on typescript that I cannot wrap my head around. It's something like this: https://tsplay.dev/WzxAQN. How do I make it infer the correct type without manually specifying the return type?
3 replies
TTCTheo's Typesafe Cult
Created by n1xx1 on 5/8/2023 in #questions
upstash-like redis interface
I was looking for a redis interface that used HTTP without requiring me to use upstash exactly. I found this project (https://github.com/nicolasff/webdis) but I'm not sure it's "production ready". Anyone has other options that are maybe more battle tested?
1 replies