Pre: Delete trailing whitespace.
This commit is contained in:
parent
db68a714f6
commit
636b7a7957
1 changed files with 19 additions and 19 deletions
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
(ns datomish.query
|
(ns datomish.query
|
||||||
(:require
|
(:require
|
||||||
[datomish.util :as util :refer [raise var->sql-var]]
|
[datomish.util :as util :refer [raise var->sql-var]]
|
||||||
[datomish.transforms :as transforms]
|
[datomish.transforms :as transforms]
|
||||||
[datascript.parser :as dp
|
[datascript.parser :as dp
|
||||||
#?@(:cljs [:refer [Pattern DefaultSrc Variable Constant Placeholder]])]
|
#?@(:cljs [:refer [Pattern DefaultSrc Variable Constant Placeholder]])]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[honeysql.core :as sql]
|
[honeysql.core :as sql]
|
||||||
)
|
)
|
||||||
#?(:clj (:import [datascript.parser Pattern DefaultSrc Variable Constant Placeholder]))
|
#?(:clj (:import [datascript.parser Pattern DefaultSrc Variable Constant Placeholder]))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Context.
|
;; Context.
|
||||||
;;
|
;;
|
||||||
;; `attribute-transform` is a function from attribute to constant value. Used to
|
;; `attribute-transform` is a function from attribute to constant value. Used to
|
||||||
;; turn, e.g., :p/attribute into an interned integer.
|
;; turn, e.g., :p/attribute into an interned integer.
|
||||||
;; `constant-transform` is a function from constant value to constant value. Used to
|
;; `constant-transform` is a function from constant value to constant value. Used to
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
(->Context [] {} []
|
(->Context [] {} []
|
||||||
transforms/attribute-transform-string
|
transforms/attribute-transform-string
|
||||||
transforms/constant-transform-default))
|
transforms/constant-transform-default))
|
||||||
|
|
||||||
(defn apply-pattern-to-context
|
(defn apply-pattern-to-context
|
||||||
"Transform a DataScript Pattern instance into the parts needed
|
"Transform a DataScript Pattern instance into the parts needed
|
||||||
to build a SQL expression.
|
to build a SQL expression.
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
[:e :a :v :t :added])]
|
[:e :a :v :t :added])]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [context
|
(fn [context
|
||||||
[pattern-part ; ?x, :foo/bar, 42
|
[pattern-part ; ?x, :foo/bar, 42
|
||||||
position]] ; :a
|
position]] ; :a
|
||||||
(let [col (sql/qualify table position)] ; :eavt.a
|
(let [col (sql/qualify table position)] ; :eavt.a
|
||||||
(condp instance? pattern-part
|
(condp instance? pattern-part
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
;; IS NOT NULL, because we don't store nulls in our schema.
|
;; IS NOT NULL, because we don't store nulls in our schema.
|
||||||
Placeholder
|
Placeholder
|
||||||
context
|
context
|
||||||
|
|
||||||
Variable
|
Variable
|
||||||
(bind-column-to-var context pattern-part col)
|
(bind-column-to-var context pattern-part col)
|
||||||
|
|
||||||
|
@ -137,11 +137,11 @@
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
[Variable{:symbol ?foo}, Variable{:symbol ?bar}]
|
[Variable{:symbol ?foo}, Variable{:symbol ?bar}]
|
||||||
|
|
||||||
with bindings in the context:
|
with bindings in the context:
|
||||||
|
|
||||||
{?foo [:eavt12.e :eavt13.v], ?bar [:eavt13.e]}
|
{?foo [:eavt12.e :eavt13.v], ?bar [:eavt13.e]}
|
||||||
|
|
||||||
=>
|
=>
|
||||||
|
|
||||||
[[:eavt12.e :foo] [:eavt13.e :bar]]
|
[[:eavt12.e :foo] [:eavt13.e :bar]]
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
(when-not (and (== 1 (count in))
|
(when-not (and (== 1 (count in))
|
||||||
(= "$" (name (-> in first :variable :symbol))))
|
(= "$" (name (-> in first :variable :symbol))))
|
||||||
(raise (str "Complex `in` not supported: " (print-str in)))))
|
(raise (str "Complex `in` not supported: " (print-str in)))))
|
||||||
|
|
||||||
(defn find->sql-clause
|
(defn find->sql-clause
|
||||||
"Take a parsed `find` expression and turn it into a structured SQL
|
"Take a parsed `find` expression and turn it into a structured SQL
|
||||||
expression that can be formatted by honeysql."
|
expression that can be formatted by honeysql."
|
||||||
|
@ -207,10 +207,10 @@
|
||||||
(datomish.query/find->sql-string
|
(datomish.query/find->sql-string
|
||||||
(datomish.query/parse
|
(datomish.query/parse
|
||||||
'[:find ?timestampMicros ?page
|
'[:find ?timestampMicros ?page
|
||||||
:in $
|
:in $
|
||||||
:where
|
:where
|
||||||
[?page :page/starred true ?t]
|
[?page :page/starred true ?t]
|
||||||
[?t :db/txInstant ?timestampMicros]])))
|
[?t :db/txInstant ?timestampMicros]])))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(pattern->sql
|
(pattern->sql
|
||||||
|
|
Loading…
Reference in a new issue