ORM-16: Add dirty tracking, save() and refresh() #16
Labels
No labels
area:core
area:database
area:migrations
area:model
area:relations
area:schema
area:tests
breaking-change
size:M
size:S
tracking
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
NoctisWolfshadow/tessera-orm#16
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Depends on: #15
Context
Laravel-style persistence: change fields on a loaded model, ask whether it changed, and
save()writes only what changed. The comparison isinsert_values()against the snapshot held inModelState.Tasks
is_persisted(),is_dirty()(never-persisted models are dirty),is_clean(),dirty_columns() -> Vec<&'static str>andis_dirty_on(Column<Self, V>).save(&mut self) -> Result<()>: not persisted means insert,set_idand snapshot; persisted and dirty means UPDATE of only the dirty columns, then snapshot; clean means no write.refresh(&mut self) -> Result<()>: reload by PK and replace the fields and state.Error::NotFoundif the row is gone,Error::NotPersistedfor a new model.NaNfloats never compare equal and will always read as dirty.Example
Black-box proof that only dirty columns are written, without needing SQL tracing:
Acceptance criteria
saveit is clean with its id set.namegivesdirty_columns() == ["name"].refreshpicks up an external change and returnsNotFound/NotPersistedin the documented cases.