sqlite has a nifty feature; “on conflict”, aka “insert or”. You apply it to insert and update operators to tell sqlite what to do if the operation would violate a constraint like unique or not null.
I’m using “insert or ignore” to only insert a row if it doesn’t exist.
insert or ignore into mytable(userid) value (23)
You can also use “insert or replace” to do an upsert
insert or replace into mytable(userid, name) value (23, "Joe")