Page MenuHomePhabricator

[report-service] Implement DB row item type
ClosedPublic

Authored by bartek on Aug 25 2023, 1:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 25, 2:12 AM
Unknown Object (File)
Fri, Nov 22, 5:54 AM
Unknown Object (File)
Oct 27 2024, 3:48 PM
Unknown Object (File)
Oct 27 2024, 3:48 PM
Unknown Object (File)
Oct 27 2024, 3:48 PM
Unknown Object (File)
Oct 27 2024, 3:42 PM
Unknown Object (File)
Oct 13 2024, 2:51 PM
Unknown Object (File)
Oct 6 2024, 4:28 PM
Subscribers

Details

Summary

This diff implements a struct that represents a row in the database. Also implemented conversions from/to attribute maps and other helper traits.

Depends on D8938

Test Plan

Tested later in the stack.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Aug 25 2023, 1:48 AM
jon added inline comments.
services/reports/src/database/item.rs
99

Might be nice to bring https://github.com/CommE2E/comm/blob/3bdda747deaf98f5d286ef586e5b2262d3481f95/services/identity/src/error.rs#L103 into comm-service-lib, then this would just be what's in the suggestion.

However, this would be some additional effort. I guess make a ticket if you feel that it would be worthwhile.

This revision is now accepted and ready to land.Aug 25 2023, 4:28 PM
services/reports/src/database/item.rs
99

Thanks for reminding me this! I think we can improve your helpers even further:

pub trait AttributeExtractor {
  fn get_attr<T: TryFromAttribute>(
    &mut self,
    attribute_name: impl Into<String>,
  ) -> Result<T, DBItemError>;
}
impl AttributeExtractor for AttributeMap {
  fn get_attr<T: TryFromAttribute>(
    &mut self,
    attribute_name: impl Into<String>,
  ) -> Result<T, DBItemError> {
    let attribute_name = attribute_name.into();
    T::try_from_attr(&attribute_name, self.remove(&attribute_name))
  }
}

And now we can get any type that we implemented TryFromAttribute for:

let some_string: String = value.get_attr("name")?;
let boolean: bool = value.get_attr("boolAttribute")?;
let nested_map: AttributeMap = value.get_attr("myMap")?;

It's much better this way, thanks! I'll do it when having a while :gri