Upsert operations

#54 didn't go far enough in handling upserts.  

This also applies the update operations to the insert model.

Test case provided that demonstrates how the current behaviour is incorrect using duplicate keys.