I don't understand this; If I want to insert somet...
# orm-help
i
I don't understand this; If I want to insert something I do not have an ID and the
where
clause only contains an
id
property. How can I use the same query for inserting and for updating data?
h
If there is no id, it executes
create
if you provide id then is
update
executed
i
Ah! alright
I can't seem to leave out the ID from the object that I pass to the variables option of the query
h
Ye, it should work like this
you can have something like data = {...data, id: ""}
i
ok
@huv1k Still this means that I can not upsert things by other where clauses then the ID. Why is this? Why can't I use other properties (that together make the document unique)?
I am importin the data from an external source and it doesn't include ID's. So Every time I restart my service (and every 24 hours) I have the same data, without id's with maybe updated properties ..
So if I upsert that data I get new entries instead of updated ones
h
So do you have some unique constrain from your data already?
Because without unique constrain you can't decide what data changed or what data to update.
i
It's just an exchange (binance) for bitcoin data. it's api exposes a list of markets. That JSOn response does not contain id's but does have e.g.
{ base: 'BTC', quote: 'ETH', active: true }
I just want that data in my DB
So I will make a
findMarket(where: { base: $base, quote: $quote})
and then do a
updateMarket()
or
createMarket()
basically implement the upsert myself with a different where clause on the find 🙂
h
so maybe use timestamp like unique constrain?
i
So my question is: Why can't the upsert Where clause include all properties instead of only ID?
h
yea, for example 🙂
i
my Prisma server says I can only put "id" in the "where"
I don't understand why
It's the
MarketWhereUniqueInput
Maybe I can add a feature request for that.
a
@Industrial: What does your datamodel look like?
where
assumes that you are filtering on a unique field (in the table). It is not the same as
WHERE
in SQL (which can filter on non-unique column values)