Is there are any standards or conventions on naming methods which add something if it not exist into another something.
For example: Store.instance().addItemIfNotExist(item)
IfNotExist is really ugly part. What workaround may be?
Is there are any standards or conventions on naming methods which add something if it not exist into another something.
For example: Store.instance().addItemIfNotExist(item)
IfNotExist is really ugly part. What workaround may be?
Some databases use the term Upsert
to mean "Update or Insert as needed", but you may not want the Update aspect.
In general, an addItem()
function has an implied, expected failure if the item already exists within the database, so you could use that. Your error handling code after the addItem()
call would make it clear that failure because of already existing was okay.
Finally, you could consider addItemExclusive()
to better indicate that the routine will check for existence prior to adding the item.