Permalink
Browse files

adds spec for characters

  • Loading branch information...
1 parent a1a74a8 commit db3e3e04bcdd61f68dd2d6a4d8320e04cea6793d @mylesmegyesi mylesmegyesi committed Jan 8, 2013
View
@@ -245,6 +245,7 @@ All hyperion implementations provide built in support for the following types:
* `java.lang.Long`
* `java.lang.Float`
* `java.lang.Double`
+* `java.lang.Character`
* `java.lang.String`
* `clojure.lang.Keyword`
View
@@ -2,7 +2,6 @@
* All queries should be logged and profiled with the debug flag
* All dangerous actions logged with the warn flag
2. Extend the Datastore spec for packing/unpacking/filtering/sorting on the following types. Whatever Java types cannot be natively supported by the Database should have a packer and unpacker included with the Datastore implementation. Documentation on what is natively supported and what is not should be included as well.
- * `java.lang.Character`
* `java.util.Date`
* `null`
3. Improve Redis Datastore
@@ -21,6 +21,9 @@
(defprotocol AsDouble
(->double [this]))
+(defprotocol AsCharacter
+ (->char [this]))
+
(extend-protocol AsBoolean
java.lang.Integer
(->bool [this] (= this 1))
@@ -115,6 +118,9 @@
nil
(->string [this] nil)
+ java.lang.Character
+ (->string [this] (String/valueOf this))
+
)
(extend-protocol AsKeyword
@@ -135,3 +141,16 @@
(->short [this] (Short. this))
)
+
+(extend-protocol AsCharacter
+
+ java.lang.Character
+ (->char [this] this)
+
+ java.lang.String
+ (->char [this] (.charAt this 0))
+
+ nil
+ (->char [this] nil)
+
+ )
@@ -10,25 +10,34 @@
(defn it-behaves-like-a-datastore []
(list
(context "save"
+ (tags :save)
(it-saves))
(context "find-by-kind"
+ (tags :find)
(it-finds-by-kind))
(context "find-by-key"
+ (tags :find)
(it-finds-by-key))
(context "find-all-kinds"
+ (tags :find)
(it-finds-all-kinds))
(context "searching multiple kinds"
+ (tags :find)
(it-searches-multiple-kinds))
(context "count-by-kind"
+ (tags :count)
(it-counts-by-kind))
(context "foreign keys"
(tags :foreign-keys)
(it-handles-foreign-keys))
(context "delete-by-key"
+ (tags :delete)
(it-deletes-by-key))
(context "delete-by-kind"
+ (tags :delete)
(it-deletes-by-kind))
(context "types"
+ (tags :types)
(it-handles-types))
))
@@ -7,23 +7,34 @@
(defn it-handles-types []
(list
(context "booleans"
+ (tags :bool)
(it-handles-booleans))
(context "bytes"
+ (tags :byte)
(it-handles-bytes))
(context "shorts"
(tags :short)
(it-handles-shorts))
(context "integers"
+ (tags :int)
(it-handles-ints))
(context "longs"
+ (tags :long)
(it-handles-longs))
(context "floats"
+ (tags :float)
(it-handles-floats))
(context "doubles"
+ (tags :double)
(it-handles-doubles))
(context "strings"
+ (tags :string)
(it-handles-strings))
+ (context "characters"
+ (tags :char)
+ (it-handles-characters))
(context "kewords"
+ (tags :keyword)
(it-handles-keywords))
))
@@ -80,6 +80,7 @@
(context "find"
(tags :find)
+
(before
(apply save* (map
(fn [value]
@@ -17,3 +17,11 @@
(map type-caster [:a :aa :b :f :g nil :o :x :z])
(type-caster :g))))
+(defn it-handles-characters []
+ (let [type-caster (fn [value] (when value (.charAt (str value) 0)))]
+ (it-finds
+ :chr
+ (build-type-checker Character)
+ (map type-caster ["a" "b" "f" "g" nil "o" "x" "z"])
+ (type-caster "g"))))
+
View
@@ -18,6 +18,7 @@ A Hyperion implementation for the Google App Engine datastore
* `java.lang.Short` (if type is not specified, GAE unpacks `Short`s as `Long`s)
* `java.lang.Integer` (if type is not specified, GAE unpacks `Integer`s as `Long`s)
* `java.lang.Float` (if type is not specified, GAE unpacks `Float`s as `Double`s)
+* `java.lang.Character`
* `clojure.lang.Keyword`
## License
@@ -42,6 +42,7 @@
[flt :type java.lang.Float]
[dbl]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(describe "Google AppEngine Datastore"
@@ -1,6 +1,6 @@
(ns hyperion.gae.types
(:require [chee.coerce :refer [->int ->string ->keyword]]
- [hyperion.coerce :refer [->float ->byte ->biginteger ->short]]
+ [hyperion.coerce :refer [->float ->byte ->biginteger ->short ->char]]
[hyperion.api :refer [pack unpack]])
(:import [com.google.appengine.api.datastore
Key KeyFactory ShortBlob Blob Category Email GeoPt Link
@@ -55,6 +55,12 @@
(defmethod unpack clojure.lang.Keyword [_ value]
(->keyword value))
+(defmethod pack java.lang.Character [_ value]
+ (->string value))
+
+(defmethod unpack java.lang.Character [_ value]
+ (->char value))
+
(defmethod pack Key [_ value]
(cond
(nil? value) nil
View
@@ -63,6 +63,7 @@ Indexes should be added externally since Hyperion doesn't support indexes.
* `java.lang.Byte` (if type is not specified, Mongo will unpack to an `Integer`)
* `java.lang.Short` (if type is not specified, Mongo will unpack to an `Integer`)
* `java.lang.Float` (if type is not specified, Mongo will unpack to a `Double`)
+* `java.lang.Character`
* `clojure.lang.Keyword`
## License
@@ -17,6 +17,7 @@
[flt :type java.lang.Float]
[dbl]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(describe "Mongo Datastore"
@@ -1,7 +1,7 @@
(ns hyperion.mongo.types
(:require [chee.coerce :refer [->keyword ->string]]
[hyperion.api :refer [pack unpack]]
- [hyperion.coerce :refer [->float ->byte ->biginteger ->short]]))
+ [hyperion.coerce :refer [->float ->byte ->biginteger ->short ->char]]))
(defmethod pack Byte [_ value]
(->byte value))
@@ -26,3 +26,9 @@
(defmethod unpack clojure.lang.Keyword [_ value]
(->keyword value))
+
+(defmethod pack java.lang.Character [_ value]
+ (->char value))
+
+(defmethod unpack java.lang.Character [_ value]
+ (->char value))
View
@@ -18,6 +18,7 @@ A Hyperion implementation for MySQL
* `java.lang.Byte` as column type `TINYINT`
* `java.lang.Short` as column type `INTEGER`
* `java.lang.Float` as column type `DOUBLE` (`FLOAT` will truncate)
+* `java.lang.Character` as column type `VARCHAR`
* `clojure.lang.Keyword` same as `java.lang.String`
## License
@@ -63,6 +63,7 @@
flt DOUBLE,
dbl DOUBLE,
str VARCHAR(32),
+ chr VARCHAR(2),
kwd VARCHAR(32),
data VARCHAR(32),
first_name VARCHAR(35),
@@ -82,6 +83,7 @@
[flt :type java.lang.Float]
[dbl]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(def connection-url "jdbc:mysql://localhost:3306/hyperion?user=root")
View
@@ -18,6 +18,7 @@ A Hyperion implementation for PostgreSQL
* `java.lang.Byte` as column type `SMALLINT` (will unpack to an `Integer` by default)
* `java.lang.Short` as column type `INTEGER` (will unpack to a `Long` by default)
* `java.lang.Float` as column type `FLOAT` (will unpack to a `Double` by default)
+* `java.lang.Character` as column type `VARCHAR`
* `clojure.lang.Keyword` same as `java.lang.String`
## License
@@ -56,6 +56,7 @@
flt FLOAT,
dbl FLOAT,
str VARCHAR(35),
+ chr VARCHAR(2),
kwd VARCHAR(35),
data VARCHAR(32),
first_name VARCHAR(35)
@@ -74,6 +75,7 @@
[flt :type java.lang.Float]
[dbl]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(def connection-url "jdbc:postgresql://localhost:5432/hyperion")
View
@@ -38,6 +38,8 @@ Hyperion datastore.
* `java.lang.Long`
* `java.lang.Float`
* `java.lang.Double`
+* `java.lang.Character`
+* `java.lang.String`
* `clojure.lang.Keyword`
## License
@@ -18,6 +18,7 @@
[flt]
[dbl]
[str]
+ [chr]
[kwd])
(describe "Redis Datastore"
View
@@ -97,6 +97,7 @@ For more info: http://lists.basho.com/pipermail/riak-users_lists.basho.com/2011-
### Natively Supported
* `java.lang.Boolean`
+* `java.lang.String`
### Supported by Packer/Unpacker
@@ -106,6 +107,8 @@ For more info: http://lists.basho.com/pipermail/riak-users_lists.basho.com/2011-
* `java.lang.BigInteger`
* `java.lang.Float`
* `java.lang.Double`
+* `java.lang.Character`
+* `clojure.lang.Keyword`
## License
@@ -37,6 +37,7 @@
[flt :type java.lang.Float]
[dbl :type java.lang.Double]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(describe "Riak Datastore"
@@ -1,6 +1,6 @@
(ns hyperion.riak.types
(:require [chee.coerce :refer [->string ->int ->keyword]]
- [hyperion.coerce :refer [->float ->double ->long ->byte ->short]]
+ [hyperion.coerce :refer [->float ->double ->long ->byte ->short ->char]]
[hyperion.api :refer [pack unpack]])
(:import [java.math BigInteger]))
@@ -30,3 +30,9 @@
(defmethod unpack clojure.lang.Keyword [_ value]
(->keyword value))
+
+(defmethod pack java.lang.Character [_ value]
+ (->string value))
+
+(defmethod unpack java.lang.Character [_ value]
+ (->char value))
@@ -1,5 +1,6 @@
(ns hyperion.sql.types
- (:require [hyperion.coerce :refer [->float ->byte ->short]]
+ (:require [hyperion.coerce :refer [->float ->byte ->short ->char]]
+ [chee.coerce :refer [->string]]
[hyperion.api :refer [unpack pack]]))
(defmethod pack java.lang.Byte [_ value]
@@ -19,3 +20,9 @@
(defmethod unpack java.lang.Short [_ value]
(->short value))
+
+(defmethod pack java.lang.Character [_ value]
+ (->string value))
+
+(defmethod unpack java.lang.Character [_ value]
+ (->char value))
View
@@ -18,6 +18,7 @@ A Hyperion implementation for SQLite3
* `java.lang.Short` as column type `INTEGER`
* `java.lang.Long` as column type `BIGINT`
* `java.lang.Float` as column type `DOUBLE` or `FLOAT`
+* `java.lang.Character` as column type `VARCHAR`
* `clojure.lang.Keyword` same as `java.lang.String`
## License
@@ -59,6 +59,7 @@
flt DOUBLE,
dbl DOUBLE,
str VARCHAR(32),
+ chr VARCHAR(2),
kwd VARCHAR(32),
data VARCHAR(32)
)"))
@@ -76,6 +77,7 @@
[flt :type java.lang.Float]
[dbl]
[str]
+ [chr :type java.lang.Character]
[kwd :type clojure.lang.Keyword])
(def all-tables ["testing" "other_testing" "account" "shirt" "types"])

0 comments on commit db3e3e0

Please sign in to comment.