Dbagent upsert

These patches adds a feature called upsert (insert or update if exists).