我正在尝试从 mongoose 迁移到 Prisma。这是我在猫鼬中定义的模型,其中包含嵌套对象。
const sourceSchema = new Schema(
{
data: {
national: {
oldState: {
type: Array
},
currentState: {
type: Array
}
},
sports: {
oldState: {
type: Array
},
currentState: {
type: Array
}
}
}
}
);
Run Code Online (Sandbox Code Playgroud)
请指导我如何在 Prisma 中为带有嵌套对象的猫鼬模式编写模型。
您正在寻找复合类型来在 Prisma 中存储嵌套对象。
以下是定义模型的方法:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model Source {
id String @id @default(auto()) @map("_id") @db.ObjectId
national stateType
sports stateType
}
type stateType {
oldState oldState
currentState currentState
}
type oldState {
type String[]
}
type currentState {
type String[]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4164 次 |
最近记录: |