From 19f35b32123362e5f824b4fd0b376c3ccc7a3bf6 Mon Sep 17 00:00:00 2001 From: salmonumbrella <182032677+salmonumbrella@users.noreply.github.com> Date: Sun, 15 Feb 2026 00:16:15 -0800 Subject: [PATCH] fix: handle leading not clauses in datalog query generation (#138) --- src/utils/fireQuery.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/fireQuery.ts b/src/utils/fireQuery.ts index 5ba742ba..9bd28125 100644 --- a/src/utils/fireQuery.ts +++ b/src/utils/fireQuery.ts @@ -248,16 +248,19 @@ export const getDatalogQuery = ({ ); const find = definedSelections.map((p) => p.pull).join("\n "); const where = whereClauses.map((c) => compileDatalog(c, 1)).join("\n"); + const shouldBindLeadingNotClause = + !!whereClauses.length && + (whereClauses[0].type === "not-clause" || + whereClauses[0].type === "not-join-clause"); + const leadingWhereBinding = shouldBindLeadingNotClause + ? ` [?${returnNode} :block/uid _]\n` + : ""; return { query: `[:find\n ${find}\n${ expectedInputs.length ? ` :in $ ${expectedInputs.map((i) => `?${i}`).join(" ")}\n` : "" - }:where\n${ - whereClauses.length === 1 && whereClauses[0].type === "not-clause" - ? `[?node :block/uid _]` - : "" - }${where}\n]`, + }:where\n${leadingWhereBinding}${where}\n]`, formatResult: (result: unknown[]) => definedSelections .map((c, i) => (prev: QueryResult) => {