Review comment: better UUID support.
This commit is contained in:
parent
7d684216f0
commit
0f399eafb0
4 changed files with 38 additions and 1 deletions
|
@ -99,13 +99,22 @@
|
|||
:key k
|
||||
:value v}))))
|
||||
|
||||
#?(:clj
|
||||
(defn uuidish? [x]
|
||||
(instance? java.util.UUID x)))
|
||||
#?(:cljs
|
||||
(let [uuid-re (js/RegExp. "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" "i")]
|
||||
(defn uuidish? [x]
|
||||
(and (string? x)
|
||||
(re-find uuid-re x)))))
|
||||
|
||||
(def value-type-map
|
||||
{:db.type/ref { :valid? entid? }
|
||||
:db.type/keyword { :valid? keyword? }
|
||||
:db.type/string { :valid? string? }
|
||||
:db.type/boolean { :valid? #?(:clj #(instance? Boolean %) :cljs #(= js/Boolean (type %))) }
|
||||
:db.type/long { :valid? integer? }
|
||||
:db.type/uuid { :valid? #?(:clj #(instance? java.util.UUID %) :cljs string?) }
|
||||
:db.type/uuid { :valid? uuidish? }
|
||||
:db.type/instant { :valid? #?(:clj #(instance? java.util.Date %) :cljs #(= js/Date (type %))) }
|
||||
:db.type/uri { :valid? #?(:clj #(instance? java.net.URI %) :cljs string?) }
|
||||
:db.type/double { :valid? #?(:clj float? :cljs number?) }
|
||||
|
|
|
@ -175,6 +175,9 @@
|
|||
java.util.Date
|
||||
(->SQLite [x] (.getTime x))
|
||||
|
||||
java.util.UUID
|
||||
(->SQLite [x] (.toString x)) ; TODO: BLOB storage. Issue #44.
|
||||
|
||||
Float
|
||||
(->SQLite [x] x)
|
||||
|
||||
|
@ -272,4 +275,5 @@
|
|||
:db.type/boolean (not= value 0)
|
||||
:db.type/long value
|
||||
:db.type/instant (<-tagged-SQLite 4 value)
|
||||
:db.type/uuid (<-tagged-SQLite 11 value)
|
||||
:db.type/double value))
|
||||
|
|
22
test/datomish/schema_test.cljc
Normal file
22
test/datomish/schema_test.cljc
Normal file
|
@ -0,0 +1,22 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
(ns datomish.schema-test
|
||||
(:require
|
||||
[datomish.schema :as schema]
|
||||
#?@(:clj [[datomish.test-macros :refer [deftest-async]]
|
||||
[clojure.test :as t :refer [is are deftest testing]]])
|
||||
#?@(:cljs [[datomish.test-macros :refer-macros [deftest-async]]
|
||||
[cljs.test :as t :refer-macros [is are deftest testing async]]])))
|
||||
|
||||
#?(:clj
|
||||
(deftest test-uuid-validation
|
||||
(is (not (schema/uuidish? "123e4567-e89b-12d3-a456-426655440000")))
|
||||
(is (schema/uuidish? (java.util.UUID/fromString "123e4567-e89b-12d3-a456-426655440000")))))
|
||||
|
||||
#?(:cljs
|
||||
(deftest test-uuid-validation
|
||||
;; Case-insensitive.
|
||||
(is (schema/uuidish? "123e4567-e89b-12d3-a456-426655440000"))
|
||||
(is (schema/uuidish? "123E4567-e89b-12d3-a456-426655440000"))))
|
|
@ -6,6 +6,7 @@
|
|||
datomish.promise-sqlite-test
|
||||
datomish.db-test
|
||||
datomish.query-test
|
||||
datomish.schema-test
|
||||
datomish.sqlite-user-version-test
|
||||
datomish.test.util
|
||||
datomish.test.transforms
|
||||
|
@ -17,6 +18,7 @@
|
|||
'datomish.promise-sqlite-test
|
||||
'datomish.db-test
|
||||
'datomish.query-test
|
||||
'datomish.schema-test
|
||||
'datomish.sqlite-user-version-test
|
||||
'datomish.test.util
|
||||
'datomish.test.transforms
|
||||
|
|
Loading…
Reference in a new issue