Pre: Take more general raise from DataScript.

This commit is contained in:
Nick Alexander 2016-07-14 11:09:42 -07:00
parent d695554123
commit 2b705019a7
5 changed files with 27 additions and 17 deletions

View file

@ -4,7 +4,7 @@
(ns datomish.query
(: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]
[datascript.parser :as dp
#?@(:cljs [:refer [Pattern DefaultSrc Variable Constant Placeholder]])]
@ -157,7 +157,7 @@
(raise "Unable to :find non-variables."))
(map (fn [elem]
(let [var (:symbol elem)]
[(lookup-variable context var) (var->sql-var var)]))
[(lookup-variable context var) (util/var->sql-var var)]))
elements)))
(defn row-pair-transducer [context projection]

View file

@ -8,7 +8,7 @@
[datomish.pair-chan :refer [go-pair <?]]
[cljs.core.async.macros :refer [go]]))
(:require
[datomish.util :as util :refer [raise]]
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
[datomish.sqlite :as s]
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
[clojure.core.async :refer [go <! >!]]])
@ -42,7 +42,7 @@
{: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.
(go-pair
(raise "No migrations yet defioned!")
(raise "No migrations yet defined!")
(<? (s/set-user-version db current-version))
(<? (s/get-user-version db))))

View file

@ -3,12 +3,22 @@
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
(ns datomish.util
#?(:cljs (:require-macros datomish.util))
(:require
[clojure.string :as str]))
(defn raise [s]
#?(:clj (throw (Exception. s)))
#?(:cljs (throw (js/Error s))))
#?(:clj
(defmacro raise [& fragments]
(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
"Turns '?xyz into :xyz."

View file

@ -9,7 +9,7 @@
[datomish.node-tempfile-macros :refer [with-tempfile]]
[cljs.core.async.macros :as a :refer [go]]))
(:require
[datomish.util :as util :refer [raise]]
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
[datomish.sqlite :as s]
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
[tempfile.core :refer [tempfile with-tempfile]]

View file

@ -17,4 +17,4 @@
(util/raise "succeed")
"fail")
(catch :default e e))]
(is (= "succeed" (aget caught "message"))))))
(is (= "succeed" (aget caught "data"))))))