Skip to content

Commit

Permalink
Merge pull request #223 from SeaQL/active-value-api
Browse files Browse the repository at this point in the history
`ActiveValue::take()` & `ActiveValue::into_value()` without `unwrap()`
  • Loading branch information
tyt2y3 authored Oct 12, 2021
2 parents 664afa4 + 35b8eb9 commit edc2e65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,23 @@ where
matches!(self.state, ActiveValueState::Unset)
}

pub fn take(&mut self) -> V {
pub fn take(&mut self) -> Option<V> {
self.state = ActiveValueState::Unset;
self.value.take().unwrap()
self.value.take()
}

pub fn unwrap(self) -> V {
self.value.unwrap()
}

pub fn into_value(self) -> Value {
self.value.unwrap().into()
pub fn into_value(self) -> Option<Value> {
self.value.map(Into::into)
}

pub fn into_wrapped_value(self) -> ActiveValue<Value> {
match self.state {
ActiveValueState::Set => ActiveValue::set(self.into_value()),
ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value()),
ActiveValueState::Set => ActiveValue::set(self.into_value().unwrap()),
ActiveValueState::Unchanged => ActiveValue::unchanged(self.into_value().unwrap()),
ActiveValueState::Unset => ActiveValue::unset(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ where
}
if av_has_val {
columns.push(col);
values.push(av.into_value());
values.push(av.into_value().unwrap());
}
}
self.query.columns(columns);
Expand Down

0 comments on commit edc2e65

Please sign in to comment.