SpacetimeDB
SpacetimeDB copied to clipboard
Feature request: upsert
Something like this:
// Pseudocode
func upsert(ctx, primary_key_value, value):
if ctx.primary_key_column.try_find(primary_key_value):
// Row with a matching primary key column exists
ctx.primary_key_column.delete(primary_key_value)
ctx.primary_key_column.insert(primary_key_value, value)
In order to upsert on a column it needs to have a unique constraint on it.
This can probably be implemented for now in module bindings as "try-update, insert on row-doesn't-exist" so that we don't have to add this in the host. If it turns out that this needs to be highly optimized we can add an ABI for it later on.
Reopening, as the linked PR does not include C# support, and is currently marked unstable.
If I may, perhaps the name "InsertOrUpdate" or similar would be better. Yes, it's longer, but there is then no ambiguity on first glance about what the function does.
If I may, perhaps the name "InsertOrUpdate" or similar would be better. Yes, it's longer, but there is then no ambiguity on first glance about what the function does.
@sunkin351 We did indeed settle on insert_or_update in the unstable Rust implementation, #2678 .