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
|
||||
(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
|
||||
"Turns '?xyz into :_xyz_type_tag."
|
||||
[x]
|
||||
(if (and (symbol? x)
|
||||
(str/starts-with? (name x) "?"))
|
||||
(keyword (str "_" (subs (name x) 1) "_type_tag"))
|
||||
(throw (ex-info (str x " is not a Datalog var.") {}))))
|
||||
(and
|
||||
(ensure-datalog-var x)
|
||||
(keyword (str "_" (subs (name x) 1) "_type_tag"))))
|
||||
|
||||
(defn var->sql-var
|
||||
"Turns '?xyz into :xyz."
|
||||
[x]
|
||||
(if (and (symbol? x)
|
||||
(str/starts-with? (name x) "?"))
|
||||
(keyword (subs (name x) 1))
|
||||
(throw (ex-info (str x " is not a Datalog var.") {}))))
|
||||
(and
|
||||
(ensure-datalog-var x)
|
||||
(keyword (subs (name x) 1))))
|
||||
|
||||
(defn aggregate->sql-var
|
||||
"Turns (:max 'column) into :%max.column."
|
||||
|
|
|
@ -46,11 +46,11 @@
|
|||
(let [{tx1 :tx} (<? (d/<transact! conn [{:db/id 101 :x 505}]))]
|
||||
|
||||
(is (= (<? (d/<q (d/db conn)
|
||||
`[:find ?e ?a ?v ?tx :in $ :where
|
||||
[?e ?a ?v ?tx]
|
||||
[(> ?tx ~tx0)]
|
||||
[(!= ?a ~(d/entid (d/db conn) :db/txInstant))] ;; TODO: map ident->entid for values.
|
||||
] {}))
|
||||
[:find '?e '?a '?v '?tx :in '$ :where
|
||||
'[?e ?a ?v ?tx]
|
||||
[(list '> '?tx tx0)]
|
||||
[(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.
|
||||
(finally
|
||||
(<? (d/<close conn)))))))
|
||||
|
|
Loading…
Reference in a new issue