MoltenFuzzy
MoltenFuzzy
Explore posts from servers
TTCTheo's Typesafe Cult
Created by MoltenFuzzy on 5/31/2023 in #questions
N Nested Relations
Hi im having trouble dealing with nested includes. I have a Comment and reply structure and replies are type Comments. Each Comment can have N replies and each reply(Comment type) can also have N replies. Prisma currently does not include support for this and I have N levels so I can't nest includes an unknown number of times. Right now I am trying a raw query but I suck at SQL and this is as far as i got.
WITH RECURSIVE comment_replies AS (
SELECT "Comment".id, "Comment".content
FROM "Post"
JOIN "Comment" ON "Post".id = "Comment"."postId"
WHERE "Post".id = ${input.postId}

UNION
--- recursive query (note it adds to the partial table "x")
SELECT c.id, c.content
FROM "Comment" c
INNER JOIN comment_replies cr ON c."parentCommentId" = cr.id
)
SELECT * FROM comment_replies;
WITH RECURSIVE comment_replies AS (
SELECT "Comment".id, "Comment".content
FROM "Post"
JOIN "Comment" ON "Post".id = "Comment"."postId"
WHERE "Post".id = ${input.postId}

UNION
--- recursive query (note it adds to the partial table "x")
SELECT c.id, c.content
FROM "Comment" c
INNER JOIN comment_replies cr ON c."parentCommentId" = cr.id
)
SELECT * FROM comment_replies;
I want my data returned like this but im not sure how to fix my query to do that.
[
{
id: "cli3zi32t0008hp6wf8vp0mdw",
content: "test",
replies: [
{ id: "cli3zi32t0008hp6wf8vp0mdx", content: "test", replies: [] },
{ id: "cli3zi32t0008hp6wf8vp0mda", content: "test", replies: [] },
],
},
{
id: "cli3zi32t0008hp6wf8vp0mdw",
content: "test",
replies: [
{ id: "cli3zi32t0008hp6wf8vp0mdx", content: "test", replies: [] },
{ id: "cli3zi32t0008hp6wf8vp0mda", content: "test", replies: [] },
],
},
]
[
{
id: "cli3zi32t0008hp6wf8vp0mdw",
content: "test",
replies: [
{ id: "cli3zi32t0008hp6wf8vp0mdx", content: "test", replies: [] },
{ id: "cli3zi32t0008hp6wf8vp0mda", content: "test", replies: [] },
],
},
{
id: "cli3zi32t0008hp6wf8vp0mdw",
content: "test",
replies: [
{ id: "cli3zi32t0008hp6wf8vp0mdx", content: "test", replies: [] },
{ id: "cli3zi32t0008hp6wf8vp0mda", content: "test", replies: [] },
],
},
]
THANK YOU!!!
9 replies
TTCTheo's Typesafe Cult
Created by MoltenFuzzy on 3/6/2023 in #questions
| undefined on tRPC procedures
40 replies
TTCTheo's Typesafe Cult
Created by MoltenFuzzy on 2/23/2023 in #questions
How to set up a development and production database with Prisma
I'm trying to set up two databases with prisma but there isn't much info available. I am trying to use a local postgres db for my dev db and supabase for my prod db.
datasource db {
provider = "postgresql"
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}

datasource development {
provider = "postgresql"
url = env("DEV_DATABASE_URL")
}
datasource db {
provider = "postgresql"
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}

datasource development {
provider = "postgresql"
url = env("DEV_DATABASE_URL")
}
This is giving me an error in the schema file so im not sure how to go about doing this.
7 replies
TTCTheo's Typesafe Cult
Created by MoltenFuzzy on 2/22/2023 in #questions
Vercel Deployment Invalid Env Variables
17 replies