Entity / Expressions

Three interpreters, one answer

examples/entity runs five queries across SQLite, evaluate, and Judge:

output
NotEditedBy: posts not edited by an author
  FROM Post
  WHERE not (Post.editor = $editor)
  ORDER BY Post.title ASC
  given {"editor":"a2"}, asked by a visitor
  reads its own row's editor, title
  SQLite ran: select "id", "headline" from "posts" where not ("posts"."editor_id" = ?) order by "posts"."headline" collate binary asc, "posts"."id" collate binary asc limit ? ["a2",101]
  SQLite: p3
  evaluate, every post: p3
  Judge, every row held: p3
  Judge, a page holding Ada and one comment: p1 out, p2 out, p3 in, p4 out
ByAuthorName: posts by an author's name
  FROM Post
  WHERE contains(Post.author.name, $name)
  ORDER BY Post.title ASC
  given {"name":"ada"}, asked by a visitor
  reads its own row's title, and other rows through Post.author.name
  SQLite ran: select "id", "headline" from "posts" where lower((select "authors"."name" from "authors" where "authors"."id" = "posts"."author_id")) like lower(?) escape '\' order by "posts"."headline" collate binary asc, "posts"."id" collate binary asc limit ? ["%ada%",101]
  SQLite: p2, p1
  evaluate, every post: refused, it does not run path
  Judge, every row held: p2, p1
  Judge, a page holding Ada and one comment: p1 in, p2 in, p3 unknown (Author a2 is not held), p4 unknown (Author a3 is not held)

Notice three behaviors in that trace:

  • Identical IDs and ordering: Posts p1 and p4 have editor: null, so null = 'a2' and not (null = 'a2') are both unknown, leaving only p3 in SQLite, evaluate, and Judge.
  • Binding details stay in the binding: The SQL compiler maps title to the "headline" column, compiles relations to subqueries, and appends "id" for deterministic pagination.
  • Refusals over guesses: evaluate handles a single table and refuses ByAuthorName because it crosses a path relation. Judge answers for posts whose author (a1) it holds and returns Unknown naming the missing author for p3 and p4.

Shared conformance tests in foldkit-entity/conformance verify mixed-case text, nulls, %/_ wildcards, accents, and stored date formats across SQLite, Postgres, evaluate, and Judge. For write parity, Law.check in foldkit-remote/testing verifies client predictions against server commits; see Checking the prediction against the server.