ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::{SqlTextComparison, push_slots};
use crate::comparison::{
  At, Backend, ComplexComparison, TextMatch,
  sql::{Carrier, like_pattern, not_wrapped, push_column},
};

/// One impl per dialect, because what differs is the LEAF below rather than the walk above:
/// `push_slots` is this kind's one slot walk and every dialect calls it, so the impls cannot come to
/// disagree about which operators render or in what order.
impl<V> ComplexComparison<sqlx::Postgres> for SqlTextComparison<V, sqlx::Postgres>
where
  V: Carrier<sqlx::Postgres> + AsRef<str>,
{
  #[inline]
  fn conjuncts(&self) -> usize {
    Self::conjuncts(self)
  }

  fn apply<'q>(
    &'q self,
    at: At<'_>,
    mut builder: <sqlx::Postgres as Backend>::Builder<'q>,
  ) -> Result<<sqlx::Postgres as Backend>::Builder<'q>, <sqlx::Postgres as Backend>::Error> {
    push_slots(self, at, &mut builder, push_text_match);
    Ok(builder)
  }
}

/// Postgres's substring / affix leaf. The operand does NOT bind through its own [`Carrier`] row:
/// what binds is a PATTERN derived from its text, which is a new value and has to be typed as
/// text.
fn push_text_match<V>(
  qb: &mut sqlx::QueryBuilder<sqlx::Postgres>,
  at: At<'_>,
  kind: TextMatch,
  operand: &V,
  negated: bool,
  nocase: bool,
) where
  V: Carrier<sqlx::Postgres> + AsRef<str>,
{
  let pattern = like_pattern(operand.as_ref(), kind);
  not_wrapped(qb, negated, |qb| {
    push_column(qb, at);
    qb.push(if nocase { " ILIKE " } else { " LIKE " });
    qb.push_bind(pattern);
    qb.push(" ESCAPE '\\'");
  });
}