Pre: Take more general raise
from DataScript.
This commit is contained in:
parent
d695554123
commit
2b705019a7
5 changed files with 27 additions and 17 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
(ns datomish.query
|
(ns datomish.query
|
||||||
(:require
|
(:require
|
||||||
[datomish.util :as util :refer [raise var->sql-var]]
|
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
||||||
[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]])]
|
||||||
|
@ -157,7 +157,7 @@
|
||||||
(raise "Unable to :find non-variables."))
|
(raise "Unable to :find non-variables."))
|
||||||
(map (fn [elem]
|
(map (fn [elem]
|
||||||
(let [var (:symbol elem)]
|
(let [var (:symbol elem)]
|
||||||
[(lookup-variable context var) (var->sql-var var)]))
|
[(lookup-variable context var) (util/var->sql-var var)]))
|
||||||
elements)))
|
elements)))
|
||||||
|
|
||||||
(defn row-pair-transducer [context projection]
|
(defn row-pair-transducer [context projection]
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
[datomish.pair-chan :refer [go-pair <?]]
|
[datomish.pair-chan :refer [go-pair <?]]
|
||||||
[cljs.core.async.macros :refer [go]]))
|
[cljs.core.async.macros :refer [go]]))
|
||||||
(:require
|
(:require
|
||||||
[datomish.util :as util :refer [raise]]
|
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
||||||
[datomish.sqlite :as s]
|
[datomish.sqlite :as s]
|
||||||
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
||||||
[clojure.core.async :refer [go <! >!]]])
|
[clojure.core.async :refer [go <! >!]]])
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
{:pre [(> from-version 0)]} ;; Or we'd create-current-version instead.
|
{:pre [(> from-version 0)]} ;; Or we'd create-current-version instead.
|
||||||
{:pre [(< from-version current-version)]} ;; Or we wouldn't need to update-from-version.
|
{:pre [(< from-version current-version)]} ;; Or we wouldn't need to update-from-version.
|
||||||
(go-pair
|
(go-pair
|
||||||
(raise "No migrations yet defioned!")
|
(raise "No migrations yet defined!")
|
||||||
(<? (s/set-user-version db current-version))
|
(<? (s/set-user-version db current-version))
|
||||||
(<? (s/get-user-version db))))
|
(<? (s/get-user-version db))))
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,22 @@
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
(ns datomish.util
|
(ns datomish.util
|
||||||
|
#?(:cljs (:require-macros datomish.util))
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(defn raise [s]
|
#?(:clj
|
||||||
#?(:clj (throw (Exception. s)))
|
(defmacro raise [& fragments]
|
||||||
#?(:cljs (throw (js/Error s))))
|
(let [msgs (butlast fragments)
|
||||||
|
data (last fragments)]
|
||||||
|
`(throw (ex-info (str ~@(map (fn [m#] (if (string? m#) m# (list 'pr-str m#))) msgs)) ~data)))))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(defmacro cond-let [& clauses]
|
||||||
|
(when-let [[test expr & rest] clauses]
|
||||||
|
`(~(if (vector? test) 'if-let 'if) ~test
|
||||||
|
~expr
|
||||||
|
(cond-let ~@rest)))))
|
||||||
|
|
||||||
(defn var->sql-var
|
(defn var->sql-var
|
||||||
"Turns '?xyz into :xyz."
|
"Turns '?xyz into :xyz."
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
[datomish.node-tempfile-macros :refer [with-tempfile]]
|
[datomish.node-tempfile-macros :refer [with-tempfile]]
|
||||||
[cljs.core.async.macros :as a :refer [go]]))
|
[cljs.core.async.macros :as a :refer [go]]))
|
||||||
(:require
|
(:require
|
||||||
[datomish.util :as util :refer [raise]]
|
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
||||||
[datomish.sqlite :as s]
|
[datomish.sqlite :as s]
|
||||||
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
||||||
[tempfile.core :refer [tempfile with-tempfile]]
|
[tempfile.core :refer [tempfile with-tempfile]]
|
||||||
|
|
|
@ -17,4 +17,4 @@
|
||||||
(util/raise "succeed")
|
(util/raise "succeed")
|
||||||
"fail")
|
"fail")
|
||||||
(catch :default e e))]
|
(catch :default e e))]
|
||||||
(is (= "succeed" (aget caught "message"))))))
|
(is (= "succeed" (aget caught "data"))))))
|
||||||
|
|
Loading…
Reference in a new issue