EAV prisma schema #2226
-
Beta Was this translation helpful? Give feedback.
Answered by
nikolasburk
Apr 22, 2020
Replies: 1 comment 5 replies
-
Hey @ledniy, thanks a lot for your question! I'm not too familiar with EAV but I tried to model your diagram using the Prisma schema: datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
generator client {
provider = "prisma-client-js"
}
model catalog_product_entity {
entity_id Int @default(autoincrement()) @id
entity_type_id Int @unique
}
model eav_attribute {
attribute_id Int @default(autoincrement()) @id
entity_type_id Int
entity_type catalog_product_entity @relation(fields: [entity_type_id], references: [entity_type_id])
attribute_code String
}
model catalog_product_entity_attribute_varchar {
attribute_id Int @id
attribute eav_attribute @relation(fields: [attribute_id], references: [attribute_id])
value String
} After generating Prisma Client, you'd now be able to query the tables that are described in the schema: import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// A `main` function so that we can use async/await
async function main() {
const products = await prisma.catalog_product_entity.findMany({
where: {
entity_type_id: {
// ...
}
}
})
}
main() Please let me know if that helps and if you have any further questions! |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
ledniy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @ledniy, thanks a lot for your question! I'm not too familiar with EAV but I tried to model your diagram using the Prisma schema: