Review comment: check that Datalog vars don't have a namespace.
And fix the only test that uses syntax-quote, which namespace-qualifies bare symbols.
This commit is contained in:
parent
0f399eafb0
commit
495e5a737e
2 changed files with 17 additions and 13 deletions
|
@ -30,21 +30,25 @@
|
||||||
~expr
|
~expr
|
||||||
(cond-let ~@rest)))))
|
(cond-let ~@rest)))))
|
||||||
|
|
||||||
|
(defn ensure-datalog-var [x]
|
||||||
|
(or (and (symbol? x)
|
||||||
|
(nil? (namespace x))
|
||||||
|
(str/starts-with? (name x) "?"))
|
||||||
|
(throw (ex-info (str x " is not a Datalog var.") {}))))
|
||||||
|
|
||||||
(defn var->sql-type-var
|
(defn var->sql-type-var
|
||||||
"Turns '?xyz into :_xyz_type_tag."
|
"Turns '?xyz into :_xyz_type_tag."
|
||||||
[x]
|
[x]
|
||||||
(if (and (symbol? x)
|
(and
|
||||||
(str/starts-with? (name x) "?"))
|
(ensure-datalog-var x)
|
||||||
(keyword (str "_" (subs (name x) 1) "_type_tag"))
|
(keyword (str "_" (subs (name x) 1) "_type_tag"))))
|
||||||
(throw (ex-info (str x " is not a Datalog var.") {}))))
|
|
||||||
|
|
||||||
(defn var->sql-var
|
(defn var->sql-var
|
||||||
"Turns '?xyz into :xyz."
|
"Turns '?xyz into :xyz."
|
||||||
[x]
|
[x]
|
||||||
(if (and (symbol? x)
|
(and
|
||||||
(str/starts-with? (name x) "?"))
|
(ensure-datalog-var x)
|
||||||
(keyword (subs (name x) 1))
|
(keyword (subs (name x) 1))))
|
||||||
(throw (ex-info (str x " is not a Datalog var.") {}))))
|
|
||||||
|
|
||||||
(defn aggregate->sql-var
|
(defn aggregate->sql-var
|
||||||
"Turns (:max 'column) into :%max.column."
|
"Turns (:max 'column) into :%max.column."
|
||||||
|
|
|
@ -46,10 +46,10 @@
|
||||||
(let [{tx1 :tx} (<? (d/<transact! conn [{:db/id 101 :x 505}]))]
|
(let [{tx1 :tx} (<? (d/<transact! conn [{:db/id 101 :x 505}]))]
|
||||||
|
|
||||||
(is (= (<? (d/<q (d/db conn)
|
(is (= (<? (d/<q (d/db conn)
|
||||||
`[:find ?e ?a ?v ?tx :in $ :where
|
[:find '?e '?a '?v '?tx :in '$ :where
|
||||||
[?e ?a ?v ?tx]
|
'[?e ?a ?v ?tx]
|
||||||
[(> ?tx ~tx0)]
|
[(list '> '?tx tx0)]
|
||||||
[(!= ?a ~(d/entid (d/db conn) :db/txInstant))] ;; TODO: map ident->entid for values.
|
[(list '!= '?a (d/entid (d/db conn) :db/txInstant))] ;; TODO: map ident->entid for values.
|
||||||
] {}))
|
] {}))
|
||||||
[[101 (d/entid (d/db conn) :x) 505 tx1]]))) ;; TODO: map entid->ident on egress.
|
[[101 (d/entid (d/db conn) :x) 505 tx1]]))) ;; TODO: map entid->ident on egress.
|
||||||
(finally
|
(finally
|
||||||
|
|
Loading…
Reference in a new issue