Skip to content

Commit

Permalink
Slowly moving towards 1.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarbp committed May 5, 2014
1 parent fb9638b commit f027d1f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,5 @@ pom.xml.asc
.lein-plugins
.lein-repl-history
.nrepl-port
rethinkdb.proto
src/bitemyapp/revise/testing.clj
6 changes: 5 additions & 1 deletion changelog.md
@@ -1,3 +1,8 @@
# 0.1.0
* Revise supports Rethinkdb 1.12.4 (The Wizard of Oz)
* Removed dependency on lein-protobuf. Moved protocol buffers to their own jar.
* Added the following queries: group, sum, avg, min, max

# 0.0.6
* Fix missing clojure.walk require in query ns

Expand All @@ -12,7 +17,6 @@ and throws when it times out or the agent dies. It now takes an optional timeout
which defaults to 10000 (ms)

# 0.0.3

* Fixed a bug where `(group-by .. {:avg :smthing})` would return the error:
`"Cannot divide by 0"`
* On the same note `(group-by .. {:sum :smthing}` no longer returns 0
Expand Down
4 changes: 2 additions & 2 deletions project.clj
@@ -1,4 +1,4 @@
(defproject revise "0.0.7-SNAPSHOT"
(defproject revise "0.1.0-SNAPSHOT"
:description "RethinkDB client for Clojure"
:url "github.com/bitemyapp/revise/"
:license {:name "Eclipse Public License"
Expand All @@ -12,4 +12,4 @@
:dependencies [[org.clojure/clojure "1.5.1"]
[robert/bruce "0.7.1"]
[revise/protobuf "0.8.3"]
[revise/rethinkdb "1.0.0"]])
[revise/rethinkdb "1.0.2"]])
11 changes: 10 additions & 1 deletion src/bitemyapp/revise/connection.clj
Expand Up @@ -34,7 +34,9 @@
[^DataOutputStream out]
;; fking cant figure out how to get these out of the damn protobuffer
(let [v1 1063369270
v2 1915781601]
v2 1915781601
;v3 1601562686 ;; Not implemented yet in rdb 1.12
]
(send-number out v2)))

(defn send-auth-key
Expand All @@ -43,6 +45,13 @@
(send-number out c)
(.writeChars out auth-key)))

(defn send-protocol-number
"Not implemented yet as of rdb 1.12"
[^DataOutputStream out]
(let [protobuf 656407617
json 2120839367]
(send-number out protobuf)))

(defn read-init-response
[^DataInputStream in]
(let [s (StringBuilder.)
Expand Down
28 changes: 27 additions & 1 deletion src/bitemyapp/revise/query.clj
Expand Up @@ -4,7 +4,8 @@
not + - * / mod contains? keys
merge reduce map filter mapcat
distinct count empty? nth
group-by type replace time or and])
group-by type replace time or and
min max])
(:require [bitemyapp.revise.utils.case :refer [snake-case-keys
uppercase-keys]]
clojure.walk))
Expand Down Expand Up @@ -137,6 +138,11 @@ such as the maps returned by lambdas passed as arguments to update."

(def implicit-var (query :IMPLICIT_VAR))

(defn random
[from to & [float?]]
(let [float? (boolean float?)])
(query :RANDOM [from to] {:float float?}))

;;; -- Data Operators --
(defn db
[db-name]
Expand Down Expand Up @@ -312,6 +318,26 @@ or map that over a sequence"
(query :LITERAL [json]))

;;; -- Sequence Ops --
(defn group
[sq k]
(query :GROUP [sq k]))

(defn sum
[sq]
(query :SUM [sq]))

(defn avg
[sq]
(query :AVG [sq]))

(defn min
[sq]
(query :MIN [sq]))

(defn max
[sq]
(query :MAX [sq]))

(defn between
"Get all elements of a sequence between two values"
([stream-selection lower upper]
Expand Down
6 changes: 5 additions & 1 deletion src/bitemyapp/revise/response.clj
Expand Up @@ -69,6 +69,11 @@
{:token (:token pb)
:response (response (:response pb))})

(defmethod initial :success-partial
[pb]
{:token (:token pb)
:response (response (:response pb))})

(defmethod initial :client-error
[pb]
{:error :client-error
Expand All @@ -90,7 +95,6 @@
:response (response (:response pb))
:backtrace (:backtrace pb)})


(defn inflate
"Deserialize the response protobuffer"
[pb]
Expand Down
16 changes: 9 additions & 7 deletions test/bitemyapp/revise/core_test.clj
Expand Up @@ -459,7 +459,8 @@
:gender "m" :name "aa"
:posts ["a" "aa" "aaa"]
:permission 1}
(count (rr get-all)) 2
;; TODO - Sneaky extra nesting?
(count (first (rr get-all))) 2
(count (rr between)) 3
(count (rr filter-test)) 2
(first (rr create-permissions)) {:created 1}
Expand All @@ -479,12 +480,13 @@
(count (rr with-fields)) 6
(set (rr mapcatted)) #{"aa" "bb" "ee" "aaa"
"a" "b" "c" "e" "eeeee"}
(:age (first (rr ordered-desc))) 23
(:age (first (rr ordered-asc))) 21
(count (rr ordered)) 6
(count (rr skip)) 4
(count (rr limit)) 2
(count (rr slice)) 2
;; TODO - more sneaky extra nesting
(:age (ffirst (rr ordered-desc))) 23
(:age (ffirst (rr ordered-asc))) 21
(count (first (rr ordered))) 6
(count (first (rr skip))) 4
(count (first (rr limit))) 2
(count (first (rr slice))) 2
(:age (first (rr nth-item))) 21
(first (rr indexes-of)) [0 2 4]
(rr empty-array) [true]
Expand Down

0 comments on commit f027d1f

Please sign in to comment.