Mj
Mj
TTCTheo's Typesafe Cult
Created by Mj on 8/5/2023 in #questions
help with prisma planetscale schema
Hello everyone, im trying to implement nested comments on my post object, this is currently my implementation without comments..
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
likes Like[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])

}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
likes Like[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])

}
i tried implementing it like this with the help of chatGPT
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
author Like @relation(fields: [authorId], references: [id])
likes Like[]
comments Comment[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}

model Comment {
id String @id @default(cuid())
content String
authorId String
postId String
parentId String?
createdAt DateTime @default(now())
author Post @relation(fields: [authorId], references: [id])
post Post @relation(fields: [postId], references: [id])
parent Comment? @relation("CommentToComment", fields: [parentId])
children Comment[] @relation("CommentToComment")

@@relation("CommentToComment", onDelete: NoAction, onUpdate: NoAction)
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
author Like @relation(fields: [authorId], references: [id])
likes Like[]
comments Comment[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}

model Comment {
id String @id @default(cuid())
content String
authorId String
postId String
parentId String?
createdAt DateTime @default(now())
author Post @relation(fields: [authorId], references: [id])
post Post @relation(fields: [postId], references: [id])
parent Comment? @relation("CommentToComment", fields: [parentId])
children Comment[] @relation("CommentToComment")

@@relation("CommentToComment", onDelete: NoAction, onUpdate: NoAction)
}
can someone help with the correct schema to model the relationship between posts and comments please?
3 replies
TTCTheo's Typesafe Cult
Created by Mj on 7/31/2023 in #questions
Help me not to give up on t3.
4 replies
TTCTheo's Typesafe Cult
Created by Mj on 7/26/2023 in #questions
How do i fetch data from a TRPC endpoint in getStaticProps and getServerSideProps?
currently trying to do it like this
export async function getServerSideProps(context: any) {
const { params, req, res } = context;
const slug = params.slug;
console.log("parandsfjknvedikv", slug);
const { data } = api.profile.getUserByUsername.useQuery({
username: "0xdead",
});
console.log("data", data);

return {
props: {
hello: data,
},
};
}
export async function getServerSideProps(context: any) {
const { params, req, res } = context;
const slug = params.slug;
console.log("parandsfjknvedikv", slug);
const { data } = api.profile.getUserByUsername.useQuery({
username: "0xdead",
});
console.log("data", data);

return {
props: {
hello: data,
},
};
}
throwing an error about how i cant use the useQuery hook in getServerSideProps which makes sense yeah? so how do i do that?
101 replies
TTCTheo's Typesafe Cult
Created by Mj on 7/25/2023 in #questions
Following theo's Tutorial. After creating the private routes i'm getting this error
❌ tRPC failed on <no-path>: You need to use "authMiddleware" (or the deprecated "withClerkMiddleware") in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
❌ tRPC failed on <no-path>: You need to use "authMiddleware" (or the deprecated "withClerkMiddleware") in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
I've tried to debug and the solution where people say to change the matcher jsut doesnt work anymore. here's my middleware.ts file
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware();

export const config = {
matcher: ["/(.*?trpc.*?|(?!static|.*\\..*|_next|favicon.ico).*)", "/"],
};
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware();

export const config = {
matcher: ["/(.*?trpc.*?|(?!static|.*\\..*|_next|favicon.ico).*)", "/"],
};
I now realise its because clerk has changed a lot but i really wanna finish the tutorial and not dump it halfway so help please? @jamesperkins (tagging you because i saw on google how youve greatly helped others, i apologized if i shouldn't have)
4 replies