Support upsert
Currently, if we want to make insert or update – based on if given row already exists or not – we use something like this:
$row = $this->table->find(SomePrimaryKey::from($id));
if ($row !== null) {
$modifications = $this->table->edit($row);
// modifications...
} else {
$modifications = $this->table->new(...$params);
}
$this->table->save($modifications);
That is good enough for most cases, but it can hit performance limitations quite quickly when e.g. the insert/update is made on each request.
Postgres supports upsert query using ON CONFLICT
clause, so it makes sense to support it in this lib as well.