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
//! THE COMPANION SHAPE — the vocabulary a `sortable` collection's term joins, and the two facts
//! that come apart in it.
//!
//! A suite of its own beside [`super::tests`], for the reason the frame's own shadow suite gives:
//! what is asserted here is ONE subject kind's effect on the shape vocabulary — the shape a term
//! answers, the wrapping it does not take, and the projection it does — and holding that apart from
//! the expansion's per-polarity tests is what keeps a change to either visible.
//!
//! The claim underneath every assertion is one sentence: **a companion column is a NAME the row
//! does not carry**, which is a combination the two-member vocabulary could not spell and the
//! three-member one can. What the page does with the answer is `query::sql::find`'s own shadow
//! suite; this half is that the answer is the TERM's and that nothing wraps it.

#![cfg(feature = "sqlite")]

use super::{OrderSubjects, SubjectShape, SubjectSlot, TermColumns};
use crate::{
  FieldName, OrderDirection, OrderTerm, TermName, TermSubject,
  comparison::{At, sql::tests::ROW},
};

/// The companion column's own name, under the synthesized-column law.
const COMPANION: &FieldName = FieldName::new("__ig_tags_sort__");

/// A term over a collection this backend mirrors into a companion column.
fn shadow() -> OrderTerm {
  OrderTerm::shadow(TermName::new("tags"), COMPANION, OrderDirection::Asc)
}

/// The subject `terms[0]` is written into a slot of `shape` as.
fn written(terms: &[OrderTerm], shape: SubjectShape) -> String {
  let mut qb = sqlx::QueryBuilder::<sqlx::Sqlite>::default();
  TermColumns.push_subject(SubjectSlot::new(&mut qb, shape), At::new(&ROW), terms, 0);
  qb.into_string()
}

/// **THE DEFAULT READS THE TERM.** Which shape a subject takes is decided by the storage form the
/// declaration minted onto the term, so nothing here re-decides it — and a party that answered
/// `Column` for every term would project no companion and page at a boundary nothing wrote.
#[test]
fn the_shape_is_read_off_the_terms_own_subject() {
  let value = OrderTerm::new(
    TermName::new("title"),
    FieldName::new("title"),
    OrderDirection::Asc,
  );
  let array = OrderTerm::array(
    TermName::new("tags"),
    FieldName::new("tags"),
    OrderDirection::Asc,
  );
  let edge = OrderTerm::edge(
    TermName::new("tags"),
    FieldName::new("tags"),
    OrderDirection::Asc,
  );

  assert_eq!(
    OrderSubjects::<sqlx::Sqlite>::shape(&TermColumns, &[shadow()], 0),
    SubjectShape::Companion,
    "the one subject whose value is not on the row and whose subject is a name"
  );
  for term in [value, array, edge] {
    assert_eq!(
      OrderSubjects::<sqlx::Sqlite>::shape(&TermColumns, &[term], 0),
      SubjectShape::Column
    );
  }
}

/// **A COMPANION IS A BARE NAME.** It renders exactly as a column of the row does — the two shapes
/// differ in where the VALUE comes back from and in nothing the statement can see — where a
/// sub-select is the one shape that brings a pair of parentheses with it.
#[test]
fn a_companion_takes_the_column_wrapping_and_a_sub_select_takes_its_own() {
  let terms = [shadow()];
  let bare = written(&terms, SubjectShape::Companion);

  assert_eq!(bare, r#""__ig_tags_sort__""#);
  assert_eq!(
    bare,
    written(&terms, SubjectShape::Column),
    "nothing about the wrapping distinguishes the two"
  );
  assert_eq!(
    written(&terms, SubjectShape::SubSelect),
    r#"("__ig_tags_sort__")"#,
    "the parentheses are the SUB-SELECT's alone, and the slot is where they are spelled"
  );
}

/// **The rendered name is the COMPANION's and the identity is the FIELD's**, which is what one
/// written order fingerprinting alike across two storage forms rests on — asserted here because
/// this suite's every rendering reads the first and the page's refusals read the second.
#[test]
fn the_subject_renders_the_companion_under_the_fields_identity() {
  let term = shadow();

  assert_eq!(term.subject(), TermSubject::Shadow);
  assert_eq!(term.identity(), TermName::new("tags"));
  assert_eq!(term.column(), COMPANION);
  assert_eq!(
    term.width(),
    1,
    "a companion is ONE column whatever it holds"
  );
}