From 8e1abaef9ea20959b5aa8043e24197b9064d8fa7 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Tue, 23 Apr 2024 19:05:24 +0200 Subject: [PATCH] Fixed js query lookup ref test #462 --- src/datascript/query.cljc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/datascript/query.cljc b/src/datascript/query.cljc index a5bbd422..b08c0953 100644 --- a/src/datascript/query.cljc +++ b/src/datascript/query.cljc @@ -95,7 +95,10 @@ (or (keyword? form) (string? form))) (defn lookup-ref? [form] - (looks-like? [attr? '_] form)) + (and + (or (sequential? form) (da/array? form)) + (= 2 (count form)) + (attr? (first form)))) ;; Relation algebra @@ -666,13 +669,17 @@ (defn resolve-pattern-lookup-refs [source pattern] (if (satisfies? db/IDB source) - (let [[e a v tx] pattern] - (-> - [(if (or (lookup-ref? e) (attr? e)) (db/entid-strict source e) e) - a - (if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v))) (db/entid-strict source v) v) - (if (lookup-ref? tx) (db/entid-strict source tx) tx)] - (subvec 0 (count pattern)))) + (let [[e a v tx] pattern + e' (if (or (lookup-ref? e) (attr? e)) + (db/entid-strict source e) + e) + v' (if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v))) + (db/entid-strict source v) + v) + tx' (if (lookup-ref? tx) + (db/entid-strict source tx) + tx)] + (subvec [e' a v' tx'] 0 (count pattern))) pattern)) (defn dynamic-lookup-attrs [source pattern]