KiKo
KiKo
Explore posts from servers
DTDrizzle Team
Created by KiKo on 11/26/2023 in #help
How can I do a join query for the sole purpose of filtering?
Essentially my question is how can I do this better in drizzle.
const myTeams = await ctx.db
.select()
.from(teams)
.innerJoin(
members,
and(eq(members.teamId, teams.id), eq(members.userId, ctx.user.id)),
);

return myTeams.map((t) => t.team);
const myTeams = await ctx.db
.select()
.from(teams)
.innerJoin(
members,
and(eq(members.teamId, teams.id), eq(members.userId, ctx.user.id)),
);

return myTeams.map((t) => t.team);
I really want to just write
SELECT T.*
FROM teams T, members M
WHERE T.id = M.teamId
AND M.userId = ?
SELECT T.*
FROM teams T, members M
WHERE T.id = M.teamId
AND M.userId = ?
23 replies
TTCTheo's Typesafe Cult
Created by KiKo on 6/8/2023 in #questions
Revalidate using App Dir tRPC
I am wondering how to trigger a revalidation to occur after a mutation is made
export const pressButton = publicProcedure.mutation(async ({ ctx }) => {
const added = ctx.db.insert(presses).values({});
// revalidatePath("/"); this doesn't work
return added;
});
export const pressButton = publicProcedure.mutation(async ({ ctx }) => {
const added = ctx.db.insert(presses).values({});
// revalidatePath("/"); this doesn't work
return added;
});
page.tsx
import { createPress } from "~/app/actions";
import { api } from "~/trpc/server";
import { Button } from "~/ui/button";

export default async function Home() {
const latestPress = await api.press.getLatest.query();

return (
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 ">
<div className="flex flex-col items-center gap-2">
<p className="text-2xl text-white">
{latestPress ? latestPress.id : "Loading tRPC query..."}
</p>
</div>
</div>

<form className="flex flex-col gap-2">
<Button formAction={createPress} type="submit">Press the button</Button>
</form>
</main>
);
}
import { createPress } from "~/app/actions";
import { api } from "~/trpc/server";
import { Button } from "~/ui/button";

export default async function Home() {
const latestPress = await api.press.getLatest.query();

return (
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 ">
<div className="flex flex-col items-center gap-2">
<p className="text-2xl text-white">
{latestPress ? latestPress.id : "Loading tRPC query..."}
</p>
</div>
</div>

<form className="flex flex-col gap-2">
<Button formAction={createPress} type="submit">Press the button</Button>
</form>
</main>
);
}
8 replies
TTCTheo's Typesafe Cult
Created by KiKo on 5/10/2023 in #questions
How to actually use useOptimistic?
3 replies
TTCTheo's Typesafe Cult
Created by KiKo on 5/9/2023 in #questions
Edge Server Actions
How can they be configured in server actions?
"use server";

import { revalidatePath } from "next/cache";
import { db } from "~/db";
import { presses } from "~/db/schema";

export const increment = async () => {
console.log("yo");
await db.insert(presses).values({});
revalidatePath("/");
};

export const config = {
runtime: "edge",
regions: ["iad1"],
};
"use server";

import { revalidatePath } from "next/cache";
import { db } from "~/db";
import { presses } from "~/db/schema";

export const increment = async () => {
console.log("yo");
await db.insert(presses).values({});
revalidatePath("/");
};

export const config = {
runtime: "edge",
regions: ["iad1"],
};
I tried this but I get the following error in vercel deployment...
Error:
x Only async functions are allowed to be exported in a "use server" file.
,-[/vercel/path0/src/app/action.ts:10:1]
10 | revalidatePath("/");
11 | };
12 |
13 | ,-> export const config = {
14 | | runtime: "edge",
15 | | regions: ["iad1"],
16 | `-> };
`----
Error:
x Only async functions are allowed to be exported in a "use server" file.
,-[/vercel/path0/src/app/action.ts:10:1]
10 | revalidatePath("/");
11 | };
12 |
13 | ,-> export const config = {
14 | | runtime: "edge",
15 | | regions: ["iad1"],
16 | `-> };
`----
2 replies