KHRM
KHRM
Explore posts from servers
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I read some where recently you can write mysql functions in JavaScript now so thats pretty cool
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
true sometimes wonder if that would be more ideal than doing it at the server level
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
couldnt figure out a good solution so I opted for having an earliestDate flag
const initialEvents = await db.event.findMany({
include: {
eventDates: {
orderBy: { date: "asc" },
},
},
orderBy: { earliestDate: "asc" },
take: TAKE_EVENTS_LIMIT,
});
const initialEvents = await db.event.findMany({
include: {
eventDates: {
orderBy: { date: "asc" },
},
},
orderBy: { earliestDate: "asc" },
take: TAKE_EVENTS_LIMIT,
});
I just have to now make sure that whenever an eventDate is delete I keep it in sync i.e. make sure earliestDate is updated for the event if needed
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I do have access to postgres but here I am trying to expand xD wanted to try out Turso
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I tried the typed SQL was pretty damn cool I might made a video on it But with sqlite it's gonna be hard to aggregate eegate the dates without turning them into strings
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
Yeah it doesn't allow it
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
newer models
model TempEvent {
eventId String @id @default(cuid()) @map("event_id")
title String

eventDates TempEventDate[]

@@map("temp_events")
}

model TempEventDate {
dateId Int @id @default(autoincrement()) @map("date_id")

date DateTime

event TempEvent @relation(fields: [eventId], references: [eventId])
eventId String @map("event_id")

@@map("temp_event_dates")
}
model TempEvent {
eventId String @id @default(cuid()) @map("event_id")
title String

eventDates TempEventDate[]

@@map("temp_events")
}

model TempEventDate {
dateId Int @id @default(autoincrement()) @map("date_id")

date DateTime

event TempEvent @relation(fields: [eventId], references: [eventId])
eventId String @map("event_id")

@@map("temp_event_dates")
}
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
No description
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I just reduced it from 3 tables to two tables xD but prisma still doesn't let you sort by relations just count for some reason
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
yeah I might refactor to something like that, will look more into that jsonb thing as well It'll also make the queries overall simpler Thanks for the tips felt nice to talk about code with someone been a lonely journey haha
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
Well give or take the years, events would usually be within a year or so in practice and then they'd be deleted as needed
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
But I don't know if that has any real benefit
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
there's only 365 dates in a year so this way only 365 rows would be the max for the dates table
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
it's more like I want to practice the real purpose of all 3 tables was to reuse dates but honestly I don't think it's worth it Should just have 2 or even 1 table for this type of thing and just aggregate on the dates
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
thanks I'll check it out for learning purposes But it might be easier in my case to add a field to my events table called earliestDate
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
view sounds interesting I think I'd like to explore any pointers on how to get started on that
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
note I don't want to have the sortedEvents function, yes it works when I want all the events but if I want pagination then it doesn't work the way that is expected
38 replies