forked from t3-oss/create-t3-turbo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Security2431/fix/upgrade-t3-stack-since-09…
…-18-2024 fix: upgrade t3 stack since 09-18-2024
- Loading branch information
Showing
22 changed files
with
316 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
import type { TRPCRouterRecord } from "@trpc/server"; | ||
import { z } from "zod"; | ||
|
||
import { desc, eq } from "@acme/db"; | ||
import { CreatePostSchema, Post } from "@acme/db/schema"; | ||
import { CreatePostSchema } from "@acme/validators"; | ||
|
||
import { protectedProcedure, publicProcedure } from "../trpc"; | ||
|
||
export const postRouter = { | ||
all: publicProcedure.query(({ ctx }) => { | ||
// return ctx.db.select().from(schema.post).orderBy(desc(schema.post.id)); | ||
return ctx.db.query.Post.findMany({ | ||
orderBy: desc(Post.id), | ||
limit: 10, | ||
}); | ||
return ctx.db.post.findMany({ orderBy: { id: "desc" } }); | ||
}), | ||
|
||
byId: publicProcedure | ||
.input(z.object({ id: z.string() })) | ||
.query(({ ctx, input }) => { | ||
// return ctx.db | ||
// .select() | ||
// .from(schema.post) | ||
// .where(eq(schema.post.id, input.id)); | ||
|
||
return ctx.db.query.Post.findFirst({ | ||
where: eq(Post.id, input.id), | ||
}); | ||
return ctx.db.post.findFirst({ where: { id: input.id } }); | ||
}), | ||
|
||
create: protectedProcedure | ||
.input(CreatePostSchema) | ||
.mutation(({ ctx, input }) => { | ||
return ctx.db.insert(Post).values(input); | ||
return ctx.db.post.create({ data: input }); | ||
}), | ||
|
||
delete: protectedProcedure.input(z.string()).mutation(({ ctx, input }) => { | ||
return ctx.db.delete(Post).where(eq(Post.id, input)); | ||
return ctx.db.post.delete({ where: { id: input } }); | ||
}), | ||
} satisfies TRPCRouterRecord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
export * from "drizzle-orm/sql"; | ||
export { alias } from "drizzle-orm/pg-core"; | ||
/* eslint-disable no-restricted-properties */ | ||
|
||
// Solution for prisma edge: @link https://github.com/prisma/prisma/issues/22050#issuecomment-1821208388 | ||
// import { PrismaClient } from "@prisma/client/edge"; | ||
// import { withAccelerate } from "@prisma/extension-accelerate"; | ||
|
||
import { PrismaClient } from "@prisma/client"; | ||
|
||
export * from "@prisma/client"; | ||
|
||
// Learn more about instantiating PrismaClient in Next.js here: https://www.prisma.io/docs/data-platform/accelerate/getting-started | ||
const prismaClientSingleton = () => { | ||
return new PrismaClient({ | ||
log: | ||
process.env.NODE_ENV === "development" | ||
? ["query", "error", "warn"] | ||
: ["error"], | ||
}); | ||
}; | ||
|
||
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>; | ||
|
||
const globalForPrisma = globalThis as unknown as { | ||
prisma: PrismaClientSingleton | undefined; | ||
}; | ||
|
||
export const db = globalForPrisma.prisma ?? prismaClientSingleton(); | ||
|
||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = db; |
Oops, something went wrong.