Manthan Mallikarjun
03/08/2022, 5:31 AMposts
) with a column called type
and if type
is set to "public"
you join the PublicPosts
table and if it's set to "private"
, it joins another table. I think django has this kind of support. Does Prisma support something like this?Manthan Mallikarjun
03/08/2022, 5:43 AMRSS
, MetaTags
, Scrape
, etc. Based on that enum, different code will run. The problem I'm running into is that for each option there are different configuration options. For example, one example would be for Scrape
, I might have an option called respectRobotsTxt
. That column wouldn't apply to the other two options. I currently have a JSONB, but it's not very typesafe at all. I was wondering if Prisma has an inbuilt way in the query to somehow manipulate the include
? Or maybe should my query include all the different columns and based on the enum value, select the correct table?Manthan Mallikarjun
03/08/2022, 5:45 AMconst websites = prisma.websites.findMany({
include: {
websiteRssSettings: true,
websiteScraperSettings: true,
websiteMetaTagsSettings: true,
}
})
websites.forEach((website) => {
if (website.processor === 'RSS') {
website.websiteRssSettings
// ...
}
if (website.processor === 'Scraper') {
website.websiteScraperSettings
// ...
}
if (website.processor === 'MetaTags') {
website.websiteMetaTagsSettings
// ...
}
})
Manthan Mallikarjun
03/08/2022, 6:15 AMif processor == rss, there must be a row in websiteRssSettings
Ian Ray
03/08/2022, 6:54 AMmodel WebsiteProcessor {
website WebSite @unique
rss Rss?
scraper Scraper?
meta MetaTags?
}
model Website {
...
+ processor WebsiteProcessor
}
you can use this pattern to 1:1 relate a website to a configuration. Then when you do:
prisma.websites.findMany({
include: {
processor: {
include: { rss: true, meta: true, scraper: true }
}
}
});
your resulting websites will each have stored their correct processor content (plus some garbage nulls, but hey) via the inverted processor relationIan Ray
03/08/2022, 6:55 AMedge-db
real quick, as it has an approach that addresses this precise issue, without being a NoSQL database:
https://www.edgedb.com/docs/edgeql/select#polymorphic-queries
https://www.edgedb.com/docs/clients/01_js/select#polymorphism
https://www.edgedb.com/docs/datamodel/inheritanceManthan Mallikarjun
03/08/2022, 6:58 AMWebsiteProcessor
? i.e. why can't I just directly put the rss, scraper, meta
onto websites
itself? Is there some future flexibility I'm missing?Manthan Mallikarjun
03/08/2022, 7:00 AMIan Ray
03/08/2022, 7:00 AMIan Ray
03/08/2022, 7:02 AMwebsite
table.
model website {
...
rss Rss?
scraper Scraper?
meta MetaTags?
}
Manthan Mallikarjun
03/08/2022, 7:10 AMWebsiteProcessor
other than the organization aspect?Ian Ray
03/08/2022, 7:13 AM@relation
annotation, specify some update/delete cascade-termination rules, if memory serves.Ian Ray
03/08/2022, 7:14 AMonDelete/onUpdate
in your @relation
if you go the emedded-on-website route!Manthan Mallikarjun
03/08/2022, 7:17 AMonDelete
cascade so that if the website is deleted, its config is also deleted. Seems like it should be an issue but I can always report back and tag you if I regret my choice! 😛janpio
Ian Ray
03/09/2022, 5:58 PM