我如何从Prisma类获取所有领域?
我在Prisma模式中有这两个表:
model Accounts {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
description String? @db.VarChar(255)
timeZone Int @default(0)
tableBusinessApplication AccountsBusinessApplications[]
}
model AccountsBusinessApplications {
id Int @id @default(autoincrement())
account Accounts @relation(fields: [accountId], references: [id])
accountId Int
name String @db.VarChar(100)
identification String @db.VarChar(100)
secretKey String @db.VarChar(32)
}
我有关注的代码:
const name = 'Accounts'
prisma[name].findFirst({
where: { id: 1}
}).then(result => { console.log(result) })
结果我有:
{
id: 1,
name: 'test',
description: 'test description',
timeZone: 0
}
但是我看不到' tablebusinessapplication '内部。如果我只知道头等舱名称“ 帐户”,并且我不能在查询中使用' include ',我该如何获取所有数据?
我尝试找到如何使用Prisma类获取字段列表,但似乎没有。
I have these two tables in Prisma schema:
model Accounts {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
description String? @db.VarChar(255)
timeZone Int @default(0)
tableBusinessApplication AccountsBusinessApplications[]
}
model AccountsBusinessApplications {
id Int @id @default(autoincrement())
account Accounts @relation(fields: [accountId], references: [id])
accountId Int
name String @db.VarChar(100)
identification String @db.VarChar(100)
secretKey String @db.VarChar(32)
}
I have the follow piece of code:
const name = 'Accounts'
prisma[name].findFirst({
where: { id: 1}
}).then(result => { console.log(result) })
and as a result I have:
{
id: 1,
name: 'test',
description: 'test description',
timeZone: 0
}
but I don't see 'tableBusinessApplication' inside. How can I get all data if I know only first class name "Accounts" and I can't use 'Include' in Query?
I try to find how to get a list of fields using prisma class, but it seems like there is nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 Prisma 4 开始:
As of Prisma 4:
从Prisma 5开始:
As of Prisma 5:
您可以使用 Prisma 的 DMMF 属性来获取模型字段的名称。
以下是输出。
请注意,
DMMF
是内部 API,在未来版本中可能会有更改。You can use Prisma's
DMMF
property to get the name of the fields of a model.Here's the output
Please note that
DMMF
is an internal API and may have changes in future versions.提供的解决方案已过时用于Prisma v5.6.0。以下是我不完整但功能上的代码,用于从Prisma架构中读取并生成JSON,我将其用于Hygen的模板生成。
The provided solutions are outdated for Prisma v5.6.0. Below is my incomplete but functional code for reading from a Prisma schema and generating JSON, which I use for template generation with Hygen.