sqlite - Android Room Persistence Library: Upsert -
android's room persistence library graciously includes @insert , @update annotations work objects or collections. have use case (push notifications containing model) require upsert data may or may not exist in database.
sqlite doesn't have upsert natively, , workarounds described in so question. given solutions there, how 1 apply them room?
to more specific, how can implement insert or update in room not break foreign key constraints? using insert onconflict=replace cause ondelete foreign key row called. in case ondelete causes cascade, , reinserting row cause rows in other tables foreign key deleted. not intended behavior.
use @insert(onconflict = onconflictstrategy.replace)
implement insert or replace
, shown in the accepted answer on linked-to question.
Comments
Post a Comment