Permalink
Browse files

Back out of undocumented $inc operation for now.

  • Loading branch information...
1 parent 511953c commit 9f18660b588e0170992a9a10417a7e2ac3bff485 @mmcgrana committed Jul 8, 2010
Showing with 9 additions and 29 deletions.
  1. +1 −11 src/clj/fleetdb/core.clj
  2. +2 −11 src/clj/fleetdb/lint.clj
  3. +6 −0 src/clj/fleetdb/util.clj
  4. +0 −7 test/fleetdb/core_test.clj
View
12 src/clj/fleetdb/core.clj
@@ -541,20 +541,10 @@
[(rmap-insert int-rmap record)
(imap-insert int-imap record)])))
-(defn update-merge [m1 m2]
- (reduce
- (fn [m-int [k v]]
- (cond
- (nil? v) (dissoc m-int k)
- (= "$inc" k) (let [[attr by] (first v)]
- (update m-int attr #(+ by %)))
- :new-val (assoc m-int k v)))
- m1 m2))
-
(defmethod query* "update" [db [_ coll with opts]]
(db-apply db coll (find-records db coll opts)
(fn [[int-rmap int-imap] old-record]
- (let [new-record (update-merge old-record with)]
+ (let [new-record (merge-compact old-record with)]
[(rmap-update int-rmap old-record new-record)
(imap-update int-imap old-record new-record)]))))
View
13 src/clj/fleetdb/lint.clj
@@ -40,15 +40,6 @@
(lint map? r "record not a map")
(domap lint-prop r))
-(defn- lint-update-spec [us]
- (lint map? us "update spec not a map")
- (doseq [[attr val :as prop] us]
- (if (= "$inc" attr)
- (let [[on-attr by-param] (first val)]
- (lint-attr on-attr)
- (lint number? by-param "inc amount was not a number"))
- (lint-prop prop))))
-
(defn- lint-pos-int [i type]
(lint #(and (integer? %) (pos? %)) i
(str type " not a positive integer")))
@@ -192,9 +183,9 @@
(defn- lint-update [q]
(lint-num-args q #{2 3})
- (let [[_ coll update-spec find-opts] q]
+ (let [[_ coll up-map find-opts] q]
(lint-coll coll)
- (lint-update-spec update-spec)
+ (lint-record up-map)
(lint-find-opts find-opts false)))
(defn- lint-delete [q]
View
6 src/clj/fleetdb/util.clj
@@ -55,6 +55,12 @@
(defn update [m k f & args]
(assoc m k (apply f (get m k) args)))
+(defn merge-compact [m1 m2]
+ (reduce
+ (fn [m-int [k v]]
+ (if (nil? v) (dissoc m-int k) (assoc m-int k v)))
+ m1 m2))
+
(defn uniq [coll]
(lazy-seq
(when-let [s (seq coll)]
View
7 test/fleetdb/core_test.clj
@@ -289,13 +289,6 @@
(let [[db2-1 _] (core/query db2 ["insert" "elems" {"id" 7}])]
(core/query db2-1 ["update" "elems" {"lt" "f"} {"where" ["=" "id" 7]}])))
-(deftest "update: inc"
- (let [[db1-1 c] (core/query db1
- ["update" "elems" {"$inc" {"num" 1}} {"where" ["=" "id" 1]}])]
- (assert= 1 c)
- (assert= [2] (core/query db1-1
- ["select" "elems" {"where" ["=" "id" 1] "only" "num"}]))))
-
(deftest "delete"
(let [[db1-1 c] (core/query db1 ["delete" "elems" {"where" ["in" "id" [2 4]]}])]
(assert= 2 c)

0 comments on commit 9f18660

Please sign in to comment.