I'm trying to create a detailed Prisma schema for a product database that includes nested properties and an array of strings for image content. The structure I'm aiming for looks like this:
interface Product {
id: number;
name: string;
description: string;
price: number;
rating: number;
category: string;
retailer: string;
location: {
name: string;
coordinates: {
longitude: number;
latitude: number;
};
};
images: {
thumbnail: string;
content: string[];
};
createdAt: Date;
updatedAt: Date;
}
I am particularly struggling with how to model the images property in my Prisma schema, where content is an array of strings.
Here's what I've tried so far:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model Product {
id Int @id @default(autoincrement())
name String
description String
price Float
rating Float
category String
retailer String
location Location[]
images Images[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Images {
id Int @id @default(autoincrement())
thumbnail String
content String
productId Int @unique
product Product @relation(fields: [productId], references: [id])
}
model Location {
id Int @id @default(autoincrement())
longitude Float
latitude Float
address String
productId Int @unique
product Product @relation(fields: [productId], references: [id])
}
However, this schema generates an error regarding lists of primitive types not being supported, and though it is close enough, it isn't quite right.
How can I accurately represent this intricate structure in my Prisma schema while ensuring compatibility with a SQL Server database? Any insights or recommendations would be highly appreciated. Thank you!