refactor: Update public key column type from String
to PublicKey
#29
1 changed files with 5 additions and 9 deletions
|
@ -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
|
|||||||
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
Amjad50
commented
same as above, same as above, `and_then` instead of `map`
|
|||||||
stringify!(PublicKey).to_owned()
|
String::from("PublicKey")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn array_type() -> ArrayType {
|
fn array_type() -> ArrayType {
|
||||||
|
|
Loading…
Reference in a new issue
replace
map
byand_then
and you won't needand_then(|res| res)