Instead of using separate update/insert calls, can you use a single insert with CONFLICT_REPLACE?