[Database] Added an upsert() function to perform/emulate ON DUPLICATE KEY UPDATE.

Change-Id: Id7fc6652268a439af0457309a678677351867f37