implements threadsafe upsert for mysql, postres and sqlite