我正在试用Netlify函数,并成功地编写了一个使用Prismaclient从www.example.com数据库获取数据的函数Railway.app。
我还可以使用Heidisql查看数据库,确认order_by列是否存在,然后使用它来选择结果并对结果进行排序
SELECT id, name, order_by
FROM subsection
ORDER BY order_by ASC
我有几个API端点,列出了媒体类型、特许经营、部分,然后是子部分(例如,游戏〉未知〉未知2:小偷之间〉章节列表)
当我使用npx netlify dev
在本地提供应用时,我可以在本地浏览站点并访问netlify函数URL,然后返回数据:http://localhost:8888/.netlify/函数/API?类型=游戏&特许经营=未知&部分=未知%3A+德雷克%27s+财富&资源=子部分
如果我部署该URL并在部署的站点访问它,我会在Netlify函数日志中看到以下错误:
Jan 1, 05:34:43 PM: cabcab16 ERROR PrismaClientValidationError:
Invalid `prisma.section.findMany()` invocation in
/var/task/functions/api.js:38:33
35 type,
36 franchise
37 ) => {
→ 38 return await prisma.section.findMany({
where: {
franchise: {
name: {
equals: 'uncharted'
},
type: {
name: {
equals: 'game'
}
}
}
},
orderBy: [
{
order_by: 'asc'
~~~~~~~~
}
]
})
Unknown arg `order_by` in orderBy.0.order_by for type sectionOrderByWithRelationInput. Available args:
type sectionOrderByWithRelationInput {
id?: SortOrder
franchise_id?: SortOrder
name?: SortOrder
slug?: SortOrder
description?: SortOrder
subsection_name?: SortOrder
subsections?: subsectionOrderByRelationAggregateInput
franchise?: franchiseOrderByWithRelationInput
}
at Document.validate (/var/task/node_modules/@prisma/client/runtime/index.js:32409:20)
at serializationFn (/var/task/node_modules/@prisma/client/runtime/index.js:35993:19)
at runInChildSpan (/var/task/node_modules/@prisma/client/runtime/index.js:25431:12)
at PrismaClient._executeRequest (/var/task/node_modules/@prisma/client/runtime/index.js:36000:31)
at applyQueryExtensions (/var/task/node_modules/@prisma/client/runtime/index.js:34331:19)
at consumer (/var/task/node_modules/@prisma/client/runtime/index.js:35924:18)
at /var/task/node_modules/@prisma/client/runtime/index.js:35929:51
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at /var/task/node_modules/@prisma/client/runtime/index.js:35929:29
at runInChildSpan (/var/task/node_modules/@prisma/client/runtime/index.js:25431:12) {
clientVersion: '4.7.1'
}
两个站点(本地部署和Netlify部署)都使用相同的Railway.app连接字符串,它们都可以选择和查询其他数据,但当我尝试实时使用order_by
字段时,失败了。
这是我的棱镜:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model subsection {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
name String @db.Text
description String? @db.Text
order_by Int @default(0) @db.UnsignedInt
section_id BigInt @default(0) @db.UnsignedBigInt
section section @relation(fields: [section_id], references: [id], map: "fk_subsection_section")
@@index([section_id], map: "fk_subsection_section")
}
model section {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
franchise_id BigInt @default(0) @db.UnsignedBigInt
name String @db.Text
slug String? @db.Text
description String? @db.Text
order_by Int @default(0) @db.UnsignedInt
subsection_name String? @db.Text
subsections subsection[]
franchise franchise @relation(fields: [franchise_id], references: [id], map: "fk_section_franchise")
@@index([franchise_id], map: "fk_section_franchise")
}
model franchise {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
name String @db.Text
slug String? @db.Text
type_id BigInt @default(0) @db.UnsignedBigInt
description String? @db.Text
section_name String? @db.Text
sections section[]
type type @relation(fields: [type_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_franchise_type")
@@index([type_id], map: "fk_series_type")
}
model type {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
name String @db.Text
slug String? @db.Text
subsection_name String? @db.Text
section_name String? @db.Text
has_subsections Boolean? @default(true)
franchises franchise[]
}
这是我第一次使用Prisma和Netlify功能,所以请温柔一点
如果有人能帮助我确定为什么它会在现场失败,或者告诉我如何在现场调试它,我将不胜感激。
我试过这些,但都失败了:
- 将order_by更改为字符串
- 将order_by更改为其他列名
- 添加新列名
奇怪的是,我可以将orderBy替换为“Description”,并且它可以工作,并且一些调用(对于Type和Franchise)已经使用“Name”作为orderBy,并且它可以工作
1条答案
按热度按时间vltsax251#
我已经解决了这个问题,在netlify部署中看不到Prisma.schema更改,直到我使用“清除缓存并部署”。
netlify支持论坛上有一篇文章讨论了lambda处理程序函数之外的东西如何不会在后续调用中重新运行,我猜这包括检查最新的数据库模式。https://answers.netlify.com/t/netlify-function-cache/70452/3