clockworklabs / SpacetimeDB

Multiplayer at the speed of light
https://spacetimedb.com
Other
4.41k stars 110 forks source link

Make `update_by_field` only insert if it deleted a row. #1947

Open bfops opened 2 weeks ago

bfops commented 2 weeks ago

Currently, bindings::query::update_by_field does a delete, ignores its result, then unconditionally calls insert, again ignoring its result. Consider what behavior we want and what is least surprising to users. My (pgoldman 2024-05-20) theory is that it should only call insert if a delete happened, and then should return the return value of insert.

Alter bindings::query::update_by_field to only call Table::insert if it actually deleted a row. It should also return the inserted row, as autoinc columns may still be updated within it.

Also consider making it an error to do update_by_{col} and supply a role which has a non-matching value in the col, like Foo::update_by_foo(&0, Foo { foo: 1, ..Default::default() }).