Skip to content

Add safe_update_row and safe_delete_row functions. #113

@jamesaoverton

Description

@jamesaoverton

To better support collaborative editing, and prevent one user from accidentally overwriting changes by another user, we should add an API function that accepts a "before" state for the row and ensures that the current state of the row is identical to the "before" state. If they are not identical, then presumably some other user has recently made a change. In this case we will return an Err result with a helpful message. Otherwise we make the change, like any other update_row() call.

pub async fn safe_update_row(
        &self,
        table_name: &str,
        row_number: &u32,
        before_row: &JsonRow,
        after_row: &JsonRow,
    ) -> Result<ValveRow> {
   ...
}

Keep in mind that updates cascade, and can change multiple tables. At least for now, we will not fall down the rabbit hole of locking everything down. Our use cases do not call for high loads of simultaneous changes.

I think we should do the same thing for delete_row(). I don't think we need to do anything for insert_row().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions