neoney
neoney
Explore posts from servers
DTDrizzle Team
Created by neoney on 5/31/2024 in #help
issue with update from select
doing this:
await db
.update(stores)
.set({
discordBotId: db
.select({
id: discordBots.id,
})
.from(discordBots)
.leftJoin(stores, eq(stores.discordBotId, discordBots.id))
.groupBy(discordBots.id)
.orderBy(asc(sql`COUNT(${stores.id})`))
.limit(1),
})
.where(eq(stores.id, store.id));
await db
.update(stores)
.set({
discordBotId: db
.select({
id: discordBots.id,
})
.from(discordBots)
.leftJoin(stores, eq(stores.discordBotId, discordBots.id))
.groupBy(discordBots.id)
.orderBy(asc(sql`COUNT(${stores.id})`))
.limit(1),
})
.where(eq(stores.id, store.id));
causes this:
Type 'Omit<PgSelectBase<"discord_bots", { id: PgColumn<{ name: "id"; tableName: "discord_bots"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; }, ... 5 more ..., { ...; }>, "groupBy" | ... 1 more ... | "lim...' is not assignable to type 'string | SQL<unknown> | null | undefined'.
Type 'Omit<PgSelectBase<"discord_bots", { id: PgColumn<{ name: "id"; tableName: "discord_bots"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; }, ... 5 more ..., { ...; }>, "groupBy" | ... 1 more ... | "lim...' is missing the following properties from type 'SQL<unknown>': queryChunks, shouldInlineParams, append, toQuery, and 5 more.ts(2322)
Type 'Omit<PgSelectBase<"discord_bots", { id: PgColumn<{ name: "id"; tableName: "discord_bots"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; }, ... 5 more ..., { ...; }>, "groupBy" | ... 1 more ... | "lim...' is not assignable to type 'string | SQL<unknown> | null | undefined'.
Type 'Omit<PgSelectBase<"discord_bots", { id: PgColumn<{ name: "id"; tableName: "discord_bots"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; }, ... 5 more ..., { ...; }>, "groupBy" | ... 1 more ... | "lim...' is missing the following properties from type 'SQL<unknown>': queryChunks, shouldInlineParams, append, toQuery, and 5 more.ts(2322)
1 replies
DTDrizzle Team
Created by neoney on 1/14/2024 in #help
Select where one->many relation has at least one matching a condition
I'm having a hard time wrapping my head around Drizzle, coming from Prisma. I'm trying to do something like this:
const games = await prisma.db.game.findMany({
where: {
products: {
some: {
hidden: false,
},
},
},
select: {
id: true,
name: true,
},
});
const games = await prisma.db.game.findMany({
where: {
products: {
some: {
hidden: false,
},
},
},
select: {
id: true,
name: true,
},
});
I can't seem to figure out how to do this in Drizzle. Could anyone give me some directions on getting it done? Thanks
26 replies
TtRPC
Created by neoney on 10/26/2023 in #❓-help
Access procedures with same names and same parameters, but in different routers, generically
My trpc structure looks something like this:
trpc
- router1
- routerX
- proc1
- router2
- routerX
- proc1
trpc
- router1
- routerX
- proc1
- router2
- routerX
- proc1
Basically, I have multiple routers, but they all have pretty much the same signatures - they always have mostly the same parameters, but the return types are different for some. I can't currently do anything like trpc[router].routerX.proc1.useQuery(), because Typescript throws an error - Each member of the union type [...] has signatures, but none of these signatures are compatible with each other. I can kinda work around it like this:
type Params =
| Parameters<typeof trpc.router1.routerX.proc1.useQuery>
| Parameters<typeof trpc.router2.routerX.proc1.useQuery>;

type Returned =
| ReturnType<typeof trpc.router1.routerX.proc1.useQuery>
| ReturnType<typeof trpc.router2.routerX.proc1.useQuery>;

type Fn = (...args: Params) => Returned;

return trpc[router].routerX.proc1.useQuery as Fn;
type Params =
| Parameters<typeof trpc.router1.routerX.proc1.useQuery>
| Parameters<typeof trpc.router2.routerX.proc1.useQuery>;

type Returned =
| ReturnType<typeof trpc.router1.routerX.proc1.useQuery>
| ReturnType<typeof trpc.router2.routerX.proc1.useQuery>;

type Fn = (...args: Params) => Returned;

return trpc[router].routerX.proc1.useQuery as Fn;
But in the returned useQuery hook, the type of data is unknown.
2 replies