ORM-15: Add insert, update, delete, create, find and all to Model #15
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#15
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: #14
Context
The Eloquent-style surface:
User::insert(&user),User::find(1),User::create(..). The write methods take&self/&mut self, so the call formUser::insert(&user)and the method formuser.insert()both work.Tasks
insert(&self) -> Result<i64>: plain INSERT. Doc warning: it does not set the id or mark the model clean, soinsertfollowed bysaveinserts twice.update(&self) -> Result<usize>: UPDATE of all non-PK columnsWHERE pk = ?, returning rows affected.delete(&mut self) -> Result<usize>: DELETE by PK and clear the snapshot so the model counts as not persisted. Static form:User::delete(&mut user).create(model: Self) -> Result<Self>: insert,set_id, snapshot, return the model.find(id: i64) -> Result<Option<Self>>andall() -> Result<Vec<Self>>.insert_on(&Connection),update_onanddelete_onfor an explicit connection.Example
The footgun the docs must call out:
Acceptance criteria
findof a missing id returnsNone.updatetouches only its own row.deleteremoves the row andis_persisted()becomes false.createreturns a model with a real id and a clean state.save()andrefresh()#16