macro_rules! impl_session_query_shape_methods {
() => {
#[must_use]
pub fn by_id(mut self, id: Id<E>) -> Self {
self.inner = self.inner.by_id(id);
self
}
#[must_use]
pub fn by_ids<I>(mut self, ids: I) -> Self
where
I: IntoIterator<Item = Id<E>>,
{
self.inner = self.inner.by_ids(ids);
self
}
#[must_use]
pub fn filter(mut self, predicate: Predicate) -> Self {
self.inner = self.inner.filter(predicate);
self
}
pub fn filter_expr(mut self, expr: FilterExpr) -> Result<Self, Error> {
let core_expr = expr.lower::<E>()?;
self.inner = self.inner.filter_expr(core_expr)?;
Ok(self)
}
pub fn sort_expr(mut self, expr: SortExpr) -> Result<Self, Error> {
let core_expr = expr.lower();
self.inner = self.inner.sort_expr(core_expr)?;
Ok(self)
}
#[must_use]
pub fn order_by(mut self, field: impl AsRef<str>) -> Self {
self.inner = self.inner.order_by(field);
self
}
#[must_use]
pub fn order_by_desc(mut self, field: impl AsRef<str>) -> Self {
self.inner = self.inner.order_by_desc(field);
self
}
#[must_use]
pub fn limit(mut self, limit: u32) -> Self {
self.inner = self.inner.limit(limit);
self
}
};
}
macro_rules! impl_session_materialization_methods {
() => {
pub fn execute(&self) -> Result<Response<E>, Error>
where
E: EntityValue,
{
Ok(Response::from_core(self.inner.execute()?))
}
pub fn is_empty(&self) -> Result<bool, Error>
where
E: EntityValue,
{
Ok(self.inner.is_empty()?)
}
pub fn count(&self) -> Result<u32, Error>
where
E: EntityValue,
{
Ok(self.inner.count()?)
}
pub fn require_one(&self) -> Result<(), Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::require_one(&self.inner.execute()?)
.map_err(Into::into)
}
pub fn require_some(&self) -> Result<(), Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::require_some(&self.inner.execute()?)
.map_err(Into::into)
}
pub fn row(&self) -> Result<Row<E>, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::row(self.inner.execute()?).map_err(Into::into)
}
pub fn try_row(&self) -> Result<Option<Row<E>>, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::try_row(self.inner.execute()?)
.map_err(Into::into)
}
pub fn rows(&self) -> Result<Vec<Row<E>>, Error>
where
E: EntityValue,
{
Ok(self.inner.execute()?.rows())
}
pub fn id(&self) -> Result<Option<Id<E>>, Error>
where
E: EntityValue,
{
Ok(self.inner.execute()?.iter().next().map(|row| row.id()))
}
pub fn require_id(&self) -> Result<Id<E>, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::require_id(self.inner.execute()?)
.map_err(Into::into)
}
pub fn try_id(&self) -> Result<Option<Id<E>>, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::try_row(self.inner.execute()?)
.map(|row| row.map(|entry| entry.id()))
.map_err(Into::into)
}
pub fn ids(&self) -> Result<Vec<Id<E>>, Error>
where
E: EntityValue,
{
Ok(self.inner.execute()?.ids().collect())
}
pub fn contains_id(&self, id: &Id<E>) -> Result<bool, Error>
where
E: EntityValue,
{
Ok(self.inner.execute()?.contains_id(id))
}
pub fn entity(&self) -> Result<E, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::entity(self.inner.execute()?)
.map_err(Into::into)
}
pub fn try_entity(&self) -> Result<Option<E>, Error>
where
E: EntityValue,
{
icydb_core::db::ResponseCardinalityExt::try_entity(self.inner.execute()?)
.map_err(Into::into)
}
pub fn entities(&self) -> Result<Vec<E>, Error>
where
E: EntityValue,
{
Ok(self.inner.execute()?.entities())
}
};
}
pub(crate) use impl_session_materialization_methods;
pub(crate) use impl_session_query_shape_methods;