refactor: Update public key column type from String to PublicKey #29

Manually merged
awiteb merged 6 commits from awiteb/refactor-entities-public-key into master 2024-07-24 00:20:10 +02:00 AGit
Showing only changes of commit 35a7354de1 - Show all commits

View file

@ -44,24 +44,20 @@ impl From<PublicKey> for Value {
impl TryGetable for PublicKey { impl TryGetable for PublicKey {
fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> { fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
<String as TryGetable>::try_get_by(res, idx) <String as TryGetable>::try_get_by(res, idx).and_then(|v| {
.map(|v| { PublicKey::from_str(&v).map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string())))
awiteb marked this conversation as resolved
Review

replace map by and_then and you won't need and_then(|res| res)

<String as TryGetable>::try_get_by(res, idx).and_then(|v| {
    PublicKey::from_str(&v).map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string())))
})
replace `map` by `and_then` and you won't need `and_then(|res| res)` ```rust <String as TryGetable>::try_get_by(res, idx).and_then(|v| { PublicKey::from_str(&v).map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string()))) }) ```
PublicKey::from_str(&v)
.map_err(|err| TryGetError::DbErr(DbErr::Type(err.to_string())))
}) })
.and_then(|res| res)
} }
} }
impl ValueType for PublicKey { impl ValueType for PublicKey {
fn try_from(v: Value) -> Result<Self, ValueTypeErr> { fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
<String as ValueType>::try_from(v) <String as ValueType>::try_from(v)
.map(|v| PublicKey::from_str(&v).map_err(|_| ValueTypeErr)) .and_then(|v| PublicKey::from_str(&v).map_err(|_| ValueTypeErr))
.and_then(|res| res)
} }
fn type_name() -> String { fn type_name() -> String {
awiteb marked this conversation as resolved
Review

same as above, and_then instead of map

same as above, `and_then` instead of `map`
stringify!(PublicKey).to_owned() String::from("PublicKey")
} }
fn array_type() -> ArrayType { fn array_type() -> ArrayType {