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 #3 from Security2431/fix/upgrade-t3-stack-since-06…
…-25-2024 fix: revert prisma orm with mongodb database
- Loading branch information
Showing
22 changed files
with
9,422 additions
and
10,771 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; |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "mongodb" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Post { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
title String | ||
content String | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} | ||
|
||
// NextAuth.js Models | ||
// NOTE: When using postgresql, mysql or sqlserver, | ||
// uncomment the @db.Text annotations below | ||
// @see https://next-auth.js.org/schemas/models | ||
model Account { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
userId String @db.ObjectId | ||
type String | ||
provider String | ||
providerAccountId String | ||
refresh_token String? | ||
access_token String? | ||
expires_at Int? | ||
token_type String? | ||
scope String? | ||
id_token String? | ||
session_state String? | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
@@unique([provider, providerAccountId]) | ||
} | ||
|
||
model Session { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
sessionToken String @unique | ||
userId String @db.ObjectId | ||
expires DateTime | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
} | ||
|
||
model User { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
name String? | ||
email String? @unique | ||
emailVerified DateTime? | ||
image String? | ||
accounts Account[] | ||
sessions Session[] | ||
} | ||
|
||
model VerificationToken { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
identifier String | ||
token String @unique | ||
expires DateTime | ||
@@unique([identifier, token]) | ||
} |
Oops, something went wrong.
c179a87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
create-t3-turbo-with-prisma – ./
create-t3-turbo-with-prisma-artem-shcherbakovs-projects.vercel.app
create-t3-turbo-with-pri-git-e92494-artem-shcherbakovs-projects.vercel.app
create-t3-turbo-with-prisma-nextjs.vercel.app