Replies: 2 comments 1 reply
-
I will try to clarify these points; to put it simply:
Does this answer your questions? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Your answer was very clear. When I first used native_db, it didn't have 'upsert', and inserting an existing item didn’t seem to throw an error. I’ve now upgraded to the latest version. Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question:
I’m trying to clarify the use of update versus insert operations with a practical example, as well as the implications for delete operations, especially when secondary indexes are involved.
For an update operation, I see it as
update(old_item, new_item)
, where I need to retrieve the existing item, modify it, and then update it. For an insert operation, I simply useinsert(item)
. My question is, if I have an entity with a known primary key, and I populate the other fields directly before inserting, will this correctly update the existing record with the same primary key? Additionally, how does this affect any secondary indexes?For the delete operation, I use
delete(item)
. If the struct foritem
has adefault
method, could I simply set the primary key in the default value and pass it to the delete method? Would this correctly delete the record with that primary key, and would it have any issues with secondary indexes?Example:
Suppose I have an entity with the following fields:
id
(Primary Key)name
email
created_at
updated_at
status
category
(Secondary Index)If I have an entity where I know the
id
(primary key), and I setname
,email
, andstatus
before callinginsert(entity)
, will this update the existing record with the same primary key? And, does this have any impact on thecategory
secondary index?For delete, if I create a default entity and only set the
id
field, will callingdelete(entity)
remove the correct record? Would this process have any implications for secondary indexes likecategory
?Beta Was this translation helpful? Give feedback.
All reactions