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)
Tue, Apr 16, 8:32 AM
Unknown Object (File)
Sat, Apr 13, 8:55 AM
Unknown Object (File)
Sat, Apr 13, 1:09 AM
Unknown Object (File)
Thu, Apr 11, 8:28 AM
Unknown Object (File)
Tue, Apr 9, 4:54 AM
Unknown Object (File)
Sat, Apr 6, 11:58 PM
Unknown Object (File)
Thu, Apr 4, 11:21 PM
Unknown Object (File)
Thu, Apr 4, 1:04 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
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