Skip to content
Browse files

:sdb/id -> ::cemerick.rummage/id OR ::sdb/id

  • Loading branch information...
1 parent 2de8f34 commit 5644e4a219f61b8f7adfdffcdce9b2d63d4ca327 @cemerick committed Mar 9, 2011
View
34 src/main/clojure/cemerick/rummage.clj
@@ -82,7 +82,7 @@
(defn- build-attrs
[encode-fn item add-to?]
- (for [[k v] (dissoc item :sdb/id)
+ (for [[k v] (dissoc item ::id)
v (as-collection v)
:let [[name value] (encode-fn k v)]]
(ReplaceableAttribute. name value (if add-to?
@@ -107,7 +107,7 @@
function (usually a set), and when it returns true for a key, values
will be added to the set of values at that key, if any."
[client-config domain item & {:keys [add-to? expecting not-expecting]}]
- (let [id ((:encode-id client-config) (:sdb/id item))
+ (let [id ((:encode-id client-config) (::id item))
attrs (build-attrs (:encode client-config) item add-to?)
update-condition (update-condition (:encode client-config) expecting not-expecting)]
(.putAttributes
@@ -116,7 +116,7 @@
(defn- encode-item
[{:keys [encode encode-id]} add-to? item]
- (ReplaceableItem. (encode-id (:sdb/id item))
+ (ReplaceableItem. (encode-id (::id item))
(build-attrs encode item add-to?)))
(defn batch-put-attrs
@@ -133,7 +133,7 @@
(fn [m ^Attribute a]
(let [[k v] (decode-fn (.getName a) (.getValue a))]
(update-in m [k] #(if % (-> % as-set (conj %2)) %2) v)))
- {:sdb/id item-id}
+ {::id item-id}
attributes))
(defn get-attrs
@@ -206,33 +206,11 @@
(def ^{:private true} escape-encode (escape "`" "'"))
(def ^{:private true} escape-id-encode (escape "'" "'"))
-(defn- split-every
- [maybe-every-expr?]
- (if-not (sequential? maybe-every-expr?)
- [nil maybe-every-expr?]
- (if (not= 'every (-> maybe-every-expr? first strip-symbol-ns))
- (throw (IllegalArgumentException. (str "Invalid query op, was expecting `every`: " maybe-every-expr?)))
- ['every (-> maybe-every-expr? second strip-symbol-ns)])))
-
-(defn- handle-every
- ([encode-fn attr]
- (let [[every? attr] (split-every attr)
- attr (encode-fn attr)]
- (if every?
- (format "every(%s)" attr)
- attr)))
- ([encode-fn attr value]
- (let [[every? attr] (split-every attr)
- [name value :as encoded] (encode-fn attr value)]
- (if every?
- [(format "every(%s)" name) value]
- encoded))))
-
(defn- attribute-clause
[encode-fn encode-id-fn & [attr value :as args]]
(let [value? (= 2 (count args))]
(case (-> attr as-collection first strip-symbol-ns)
- :sdb/id (if value?
+ ::id (if value?
["itemName()" (encode-id-fn value)]
"itemName()")
every (let [[name value] (apply encode-fn (cons (-> attr second strip-symbol-ns) (rest args)))
@@ -339,7 +317,7 @@
(map (fn [^Attribute a]
(decode (.getName a) (.getValue a))))
(into {}))
- :sdb/id (-> item .getName decode-id)))
+ ::id (-> item .getName decode-id)))
(defn query
"Issue a query. When `q` is a string, it is submitted directly without any interpretation.
View
18 src/test/clojure/cemerick/rummage/encoded_query_test.clj
@@ -19,31 +19,31 @@
(is (= (->> dataset
(filter #(> (:year %) 1960))
- (map #(select-keys % [:author :title :sdb/id]))
+ (map #(select-keys % [:author :title ::sdb/id]))
set)
(set (query config `{select [:author :title] from ~*test-domain-name* where (> :year 1960)}))))))
(defsdbtest name-typed-values
- dataset [{:sdb/id (Long. (long 1)) :s/name "Andy" :z/banned false :i/age (Long. (long 44)) :D/joined (java.util.Date.)
(let [config (assoc (enc/name-typed-values-config) :client client :consistent-read? true)
+ dataset [{::sdb/id (Long. (long 1)) :s/name "Andy" :z/banned false :i/age (Long. (long 44)) :D/joined (java.util.Date.)
:f/weight 185.2 :U/link (java.net.URL. "http://aws.amazon.com")}
- {:sdb/id :ns/foo :s/name "Graham" :z/banned true :i/age (Long. (long 17)) :D/joined (java.util.Date. (long 0))
+ {::sdb/id :ns/foo :s/name "Graham" :z/banned true :i/age (Long. (long 17)) :D/joined (java.util.Date. (long 0))
:f/weight 166.0 :U/link (java.net.URL. "http://github.com")}]]
(batch-put-attrs config *test-domain-name* dataset)
(is (= (set dataset) (set (query config `{select * from ~*test-domain-name*}))))
(is (= (->> dataset
(filter #(> (:i/age %) 20))
- (map #(select-keys % [:s/name :sdb/id]))
+ (map #(select-keys % [:s/name ::sdb/id]))
set)
(set (query config `{select [:s/name] from ~*test-domain-name* where (> :i/age 20)}))))))
(defsdbtest fixed-domain-schema
- (let [dataset [{:sdb/id :amy :name "Amy" :birthday (Date. (long 5000)) :weight 145.5
+ (let [dataset [{::sdb/id :amy :name "Amy" :birthday (Date. (long 5000)) :weight 145.5
:homepage (URL. "http://clojure.org") :karma (Integer. 788)}
- {:sdb/id :tremont :name "Tremont" :karma (Integer. 0) :homepage (URL. "http://www.mfa.org")}
- {:sdb/id :newton :name "Newton" :karma (Integer. 88) :birthday (Date. (long 10000))
+ {::sdb/id :tremont :name "Tremont" :karma (Integer. 0) :homepage (URL. "http://www.mfa.org")}
+ {::sdb/id :newton :name "Newton" :karma (Integer. 88) :birthday (Date. (long 10000))
:homepage (map #(URL. %) ["http://apple.com" "http://deviantart.com" "http://www.mfa.org"])}]
encoding (enc/fixed-domain-schema {:name String
:birthday Date
@@ -53,7 +53,7 @@
config (assoc encoding :client client :consistent-read? true)]
(batch-put-attrs config *test-domain-name* dataset)
- (are [expected select] (= (->> expected (map :sdb/id) set)
+ (are [expected select] (= (->> expected (map ::sdb/id) set)
(set (query config select)))
(filter (comp pos? :karma) dataset)
`{select id from ~*test-domain-name* where (> :karma 0)}
@@ -71,7 +71,7 @@
(is (= (->> (filter :birthday dataset)
(sort-by :birthday)
- (map :sdb/id))
+ (map ::sdb/id))
(query config `{select id from ~*test-domain-name* where (not-null :birthday) order-by [:birthday]})))
)
)
View
4 src/test/clojure/cemerick/rummage/query_expansion_test.clj
@@ -43,8 +43,8 @@
"select * from `foo` where not ((`a` < '5') or (`b` > '25'))" `{select * from foo where (not (or (< a 5) (> b 25)))}
; itemName() comparison
- "select * from `foo` where itemName() = '5'" `{select * from foo where (= (:sdb/id) 5)}
- "select * from `foo` where itemName() in ('0', '1', '2', '3', '4')" `{select * from foo where (in (:sdb/id) ~(range 5))}
+ "select * from `foo` where itemName() = '5'" `{select * from foo where (= (::sdb/id) 5)}
+ "select * from `foo` where itemName() in ('0', '1', '2', '3', '4')" `{select * from foo where (in (::sdb/id) ~(range 5))}
))
(deftest ordering+limit
View
34 src/test/clojure/cemerick/rummage/query_test.clj
@@ -7,21 +7,21 @@
(use-fixtures :once test/verify-domain-cleanup)
; dataset pulled from http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelectSampleDataset.html
-(def dataset [{:year 1959 :pages 336 :author "Kurt Vonnegut" :title "The Sirens of Titan" :sdb/id "0385333498"
+(def dataset [{:year 1959 :pages 336 :author "Kurt Vonnegut" :title "The Sirens of Titan" ::sdb/id "0385333498"
:keyword #{:book :paperback}
:rating #{:***** "5 stars" "Excellent"}}
- {:year 1934 :pages 318 :author "Henry Miller" :title "Tropic of Cancer" :sdb/id "0802131786"
+ {:year 1934 :pages 318 :author "Henry Miller" :title "Tropic of Cancer" ::sdb/id "0802131786"
:rating :*****}
- {:year 1979 :pages 304 :author "Tom Wolfe" :title "The Right Stuff" :sdb/id "1579124585"
+ {:year 1979 :pages 304 :author "Tom Wolfe" :title "The Right Stuff" ::sdb/id "1579124585"
:keyword #{:book :hardcover :american}
:rating #{"4 stars" :****}}
- {:year 2006 :author "Paul Van Dyk" :title "In Between" :sdb/id "B000T9886K"
+ {:year 2006 :author "Paul Van Dyk" :title "In Between" ::sdb/id "B000T9886K"
:keyword #{:trance :CD}
:rating #{"4 stars"}}
- {:year 2007 :author "Zack Snyder" :title "300" :sdb/id "B00005JPLW"
+ {:year 2007 :author "Zack Snyder" :title "300" ::sdb/id "B00005JPLW"
:keyword #{"Frank Miller" :action :DVD}
:rating #{:*** "3 stars" "Not bad"}}
- {:year 2002 :author "Thievery Corporation" :title "Heaven's Gonna Burn Your Eyes" :sdb/id "B000SF3NGK"
+ {:year 2002 :author "Thievery Corporation" :title "Heaven's Gonna Burn Your Eyes" ::sdb/id "B000SF3NGK"
:rating :*****}])
(defsdbtest test-special-returns
@@ -31,7 +31,7 @@
; verify that string queries are just passed through
(query config (str "select count(*) from " (#'sdb/escape-encode *test-domain-name*)))))
- (is (= (->> dataset (map :sdb/id) set)
+ (is (= (->> dataset (map ::sdb/id) set)
(set (query config `{select id from ~*test-domain-name*}))
; verify that string queries are just passed through
(set (query config (str "select itemName() from " (#'sdb/escape-encode *test-domain-name*))))))
@@ -44,16 +44,16 @@
(are [expected select] (= (set expected) (set (query config select)))
(->> (filter :keyword dataset)
- (map #(select-keys % [:year :author :title :sdb/id]))
+ (map #(select-keys % [:year :author :title ::sdb/id]))
; testing of all-strings leaking in here
- (map #(into {} (for [[k v] %] [(if (= :sdb/id k) k (str k)) (str v)]))))
+ (map #(into {} (for [[k v] %] [(if (= ::sdb/id k) k (str k)) (str v)]))))
`{select [:year :title :author] from ~*test-domain-name* where (not-null :keyword)})))
(defsdbtest queries
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
(batch-put-attrs config *test-domain-name* dataset)
- (are [expected select] (= (->> expected (map :sdb/id) set)
+ (are [expected select] (= (->> expected (map ::sdb/id) set)
(set (query config select)))
(filter #(< 1975 (:year %) 2005) dataset)
`{select id from ~*test-domain-name* where (between :year 1975 2005)}
@@ -83,15 +83,15 @@
`{select id from ~*test-domain-name* where (or (= :keyword :DVD) (= :keyword :CD))}
; live itemName() query
- (filter #(pos? (compare (:sdb/id %) "1579124585")) dataset)
- `{select id from ~*test-domain-name* where (> (:sdb/id) "1579124585")}
+ (filter #(pos? (compare (::sdb/id %) "1579124585")) dataset)
+ `{select id from ~*test-domain-name* where (> (::sdb/id) "1579124585")}
)))
(defsdbtest ordered-queries
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
(batch-put-attrs config *test-domain-name* dataset)
- (are [expected select] (= (map :sdb/id expected)
+ (are [expected select] (= (map ::sdb/id expected)
(query config select))
(sort-by :year dataset)
@@ -111,14 +111,14 @@
`{select id from ~*test-domain-name* where (> :year 0) order-by [:year "desc"] limit 1}
; itemName()
- (->> (sort-by :sdb/id dataset)
- (filter #(pos? (compare (:sdb/id %) "2")))
+ (->> (sort-by ::sdb/id dataset)
+ (filter #(pos? (compare (::sdb/id %) "2")))
reverse)
- `{select id from ~*test-domain-name* where (> (:sdb/id) "2") order-by [(:sdb/id) desc]})))
+ `{select id from ~*test-domain-name* where (> (::sdb/id) "2") order-by [(::sdb/id) desc]})))
(defsdbtest test-query-all
(let [config (assoc (enc/fixed-domain-schema {:key Integer}) :client client :consistent-read? true)
- dataset (for [x (range 5000)] {:sdb/id x :key x})]
+ dataset (for [x (range 5000)] {::sdb/id x :key x})]
(batch-put-attrs config *test-domain-name* dataset)
(is (= (->> dataset (map :key) (apply +))
View
30 src/test/clojure/cemerick/rummage_test.clj
@@ -90,14 +90,14 @@
(defsdbtest test-put+get
(let [config (assoc enc/all-strings :client client :consistent-read? true)
- item {:sdb/id "foo"
+ item {::sdb/id "foo"
:a 5
:b #{"bar" "baz"}
:c 'j
623.7 [false :kw]}]
(put-attrs config *test-domain-name* item)
- (is (= {:sdb/id "foo"
+ (is (= {::sdb/id "foo"
":a" "5"
":b" #{"bar" "baz"}
":c" "j"
@@ -107,27 +107,27 @@
; selective attribute retrieval
(is (= {":a" "5" ":c" "j"}
(select-keys
- (get-attrs config *test-domain-name* (:sdb/id item) ":a" ":c")
+ (get-attrs config *test-domain-name* (::sdb/id item) ":a" ":c")
[":a" ":c"])))))
(defsdbtest test-conditional-put
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
- (put-attrs config *test-domain-name* {:sdb/id "foo" :a 5})
- (put-attrs config *test-domain-name* {:sdb/id "foo" :b 6} :not-expecting :c)
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :a 5})
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :b 6} :not-expecting :c)
(is (thrown-with-msg? com.amazonaws.AmazonServiceException #".*Conditional check failed.*"
- (put-attrs config *test-domain-name* {:sdb/id "foo" :b 7} :not-expecting :b)))
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :b 7} :not-expecting :b)))
- (put-attrs config *test-domain-name* {:sdb/id "foo" :b 9} :expecting [:b "6"])
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :b 9} :expecting [:b "6"])
(is (= "9" (get (get-attrs config *test-domain-name* "foo" :b) ":b")))
(is (thrown-with-msg? com.amazonaws.AmazonServiceException #".*Conditional check failed.*"
- (put-attrs config *test-domain-name* {:sdb/id "foo" :b 9} :expecting [:b "12"])))))
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :b 9} :expecting [:b "12"])))))
(defsdbtest test-put-replace
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
- (put-attrs config *test-domain-name* {:sdb/id "foo" :a 5})
- (put-attrs config *test-domain-name* {:sdb/id "foo" :a 6} :add-to? #{:a})
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :a 5})
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :a 6} :add-to? #{:a})
(is (= #{"5" "6"}
(get (get-attrs config *test-domain-name* "foo") ":a")))))
@@ -140,7 +140,7 @@
(map str)
(take 100))]
(when id
- (put-attrs config domain-name {:sdb/id id :key id})
+ (put-attrs config domain-name {::sdb/id id :key id})
(if (get-attrs config domain-name id)
(recur keys)
true))))
@@ -149,20 +149,20 @@
(defsdbtest test-consistent-read
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
(doseq [id (map str (range 250))]
- (put-attrs config *test-domain-name* {:sdb/id id :key id})
+ (put-attrs config *test-domain-name* {::sdb/id id :key id})
(when-not (is (get-attrs config *test-domain-name* id))
(throw (IllegalStateException. (str "Consistent read wasn't on item " id)))))))
(defsdbtest test-batch-put
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
(batch-put-attrs config *test-domain-name* (for [x (range 250)]
- {:sdb/id x :key x}))
+ {::sdb/id x :key x}))
(doseq [id (map str (range 250))]
(is (get-attrs config *test-domain-name* id)))))
(defsdbtest test-delete
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
- (put-attrs config *test-domain-name* {:sdb/id "foo" :a 5 :b [5 6 7] :c 7})
+ (put-attrs config *test-domain-name* {::sdb/id "foo" :a 5 :b [5 6 7] :c 7})
(is (thrown-with-msg? com.amazonaws.AmazonServiceException #".*Conditional check failed.*"
(delete-attrs config *test-domain-name* "foo" :attrs {:c 7} :not-expecting :a)))
@@ -185,7 +185,7 @@
(defsdbtest test-batch-delete
(let [config (assoc enc/all-strings :client client :consistent-read? true)]
(batch-put-attrs config *test-domain-name* (for [x (range 235)]
- {:sdb/id x :key x :otherkey (inc x)}))
+ {::sdb/id x :key x :otherkey (inc x)}))
(is (get-attrs config *test-domain-name* "34"))
(batch-delete-attrs config *test-domain-name*

0 comments on commit 5644e4a

Please sign in to comment.
Something went wrong with that request. Please try again.