-
In the upsert documentation, there is this note
I wanted to ask about the exception case if the attribute in question is a composite of the table’s primary partition or sort keys. Since those keys can't be updated, I would expect that the exception doesn't apply, and ElectroDB would apply an if_not_exists condition for those attributes that are composites of the table’s primary partition or sort keys if they are marked as readOnly. While trying to figure that out, I don't think that https://github.com/tywalch/electrodb/blob/master/src/entity.js#L2466-L2506 has an exception for attributes that are composites of the table’s primary partition or sort keys if they are marked as readOnly. Is there a good example of how I could add if_not_exists conditions for attributes that are composites of the table’s primary partition or sort keys during an upsert? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I believe the reason for this is because the primary PK and SK are also the item's identifiers. So if the item was found with the composite values provided (i.e. falling into the "update" scenario of the "upsert") the composite value on the stored can be expected to match the one provided. ElectroDB has strict constraints to keep keys and their composites in sync (failure to do so would be a serious bug), so the attribute values should always match the indexes value. As such, this operation (without if_not_exists()) is safe at best and auto healing at worst; ideally not worst though 😅 Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
I have a similar question about ensuring read only semantics during an upsert for attributes that are composites of partition or sort keys for secondary indexes. From what I can see, it's maybe not possible to do so right now using upsert, but I'm unsure if this is true or not. |
Beta Was this translation helpful? Give feedback.
I believe the reason for this is because the primary PK and SK are also the item's identifiers. So if the item was found with the composite values provided (i.e. falling into the "update" scenario of the "upsert") the composite value on the stored can be expected to match the one provided.
ElectroDB has strict constraints to keep keys and their composites in sync (failure to do so would be a serious bug), so the attribute values should always match the indexes value. As such, this operation (without if_not_exists()) is safe at best and auto healing at worst; ideally not worst though 😅
Hope this helps!