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)
Sun, Oct 27, 3:48 PM
Unknown Object (File)
Sun, Oct 27, 3:48 PM
Unknown Object (File)
Sun, Oct 27, 3:48 PM
Unknown Object (File)
Sun, Oct 27, 3:42 PM
Unknown Object (File)
Oct 13 2024, 2:51 PM
Unknown Object (File)
Oct 6 2024, 4:28 PM
Unknown Object (File)
Sep 26 2024, 1:52 PM
Unknown Object (File)
Sep 26 2024, 1:25 AM
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
Lint Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #30300)

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 ↗(On Diff #30300)

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