I'm attempting to populate a postgresql db based off of a remote Api's response every xx min.
The script would be calling the Api on a determined interval, iterating over the response from the Api, upserting the data into the database for the relevant record.
This is the code that I've been starting with just to try to get the where statement functioning.
let world = await prisma.world.findFirst({
where: {
Uuid: some_variable.WorldId, //UUID4 string
}
})
but it's giving me the below error
Type '{ Uuid: string; }' is not assignable to type 'WorldWhereInput'. Object literal may only specify known properties, and 'Uuid' does not exist in type 'WorldWhereInput'.
Given the below schema, is it possible to query by the Uuid field, or even upsert using the Uuid, and is it better to create an Int based Id when storing the remote data, instead of relying on the Uuid from the remote Api, as shown in the schema.
There are going to be relationships, to other models that haven't been defined, yet that also if that matters?
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)
}
example response
CodePudding user response:
So as I understand you don't want to create UUID's yourself but use the external ones?
If that assumption is correct I think you don't need @db.Uuid, as it indicates that prisma should rely on your database to create Uuids:
Check their documentation about it.
Your where looks correct to me, what is the type of some_variable.WorldId ? Is it really string?
Another problem I could think of is that you forgot to migrate, after adding the Uuid field to the database.
