是否可以使用 Prisma 通过 Uuid 进行查询?
Is it possible to query by Uuid using Prisma?
我正在尝试每隔 xx 分钟根据远程 Api 的响应填充一个 postgresql 数据库。
脚本将在确定的时间间隔内调用 Api,遍历 Api 的响应,将数据更新到数据库中以获取相关记录。
这是我开始使用的代码,只是为了让 where 语句发挥作用。
let world = await prisma.world.findFirst({
where: {
Uuid: some_variable.WorldId, //UUID4 string
}
})
但它给我以下错误
Type '{ Uuid: string; }' is not assignable to type 'WorldWhereInput'.
Object literal may only specify known properties, and 'Uuid' does not
exist in type 'WorldWhereInput'.
给定以下模式,是否可以通过 Uuid
字段查询,甚至使用 Uuid 更新插入,在存储远程数据时创建基于 Int 的 Id 是否更好,而不是依赖在来自远程 Api 的 Uuid 上,如架构中所示。
将与其他尚未定义的模型建立关系,但如果这很重要的话?
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
model World {
Id Int @id @default(autoincrement())
Uuid String @unique @db.Uuid
Name String
IsSurvival Boolean @default(false)
IsHumanOnly Boolean @default(false)
Fuel100LLBasePrice Int
FuelJetBasePrice Int
JobsBaseBonus Int
JobsMaxBonus Int
ShortName String
EnableEconomicBalance Boolean @default(false)
}
示例响应
据我了解,您不想自己创建 UUID,而是想使用外部的?
如果这个假设是正确的,我认为你不需要 @db.Uuid
,因为它表明 prisma 应该依赖你的数据库来创建 Uuid:
Check their documentation about it.
你的 where
在我看来是正确的,some_variable.WorldId
的类型是什么?真的是字符串吗?
我能想到的另一个问题是你忘记迁移了,把Uuid字段添加到数据库后。
我正在尝试每隔 xx 分钟根据远程 Api 的响应填充一个 postgresql 数据库。
脚本将在确定的时间间隔内调用 Api,遍历 Api 的响应,将数据更新到数据库中以获取相关记录。
这是我开始使用的代码,只是为了让 where 语句发挥作用。
let world = await prisma.world.findFirst({
where: {
Uuid: some_variable.WorldId, //UUID4 string
}
})
但它给我以下错误
Type '{ Uuid: string; }' is not assignable to type 'WorldWhereInput'. Object literal may only specify known properties, and 'Uuid' does not exist in type 'WorldWhereInput'.
给定以下模式,是否可以通过 Uuid
字段查询,甚至使用 Uuid 更新插入,在存储远程数据时创建基于 Int 的 Id 是否更好,而不是依赖在来自远程 Api 的 Uuid 上,如架构中所示。
将与其他尚未定义的模型建立关系,但如果这很重要的话?
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
model World {
Id Int @id @default(autoincrement())
Uuid String @unique @db.Uuid
Name String
IsSurvival Boolean @default(false)
IsHumanOnly Boolean @default(false)
Fuel100LLBasePrice Int
FuelJetBasePrice Int
JobsBaseBonus Int
JobsMaxBonus Int
ShortName String
EnableEconomicBalance Boolean @default(false)
}
示例响应
据我了解,您不想自己创建 UUID,而是想使用外部的?
如果这个假设是正确的,我认为你不需要 @db.Uuid
,因为它表明 prisma 应该依赖你的数据库来创建 Uuid:
Check their documentation about it.
你的 where
在我看来是正确的,some_variable.WorldId
的类型是什么?真的是字符串吗?
我能想到的另一个问题是你忘记迁移了,把Uuid字段添加到数据库后。