Skip to content

Commit

Permalink
Add new arity to uuid to allow passing strings
Browse files Browse the repository at this point in the history
RethinkDB 2.2 lets you pass a string to `uuid` which will be hashed and
returned as a UUID.

Fixes #109
  • Loading branch information
danielcompton committed Nov 20, 2015
1 parent d994035 commit 762d1a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ All notable changes to this project will be documented in this file. This change
## [Unreleased]
### Changed
- Disable Nagle's algorithm (set TCP NO_DELAY to true). This provides a speedup of around 30-40x for small queries on Linux. [#114](https://github.com/apa512/clj-rethinkdb/pull/114)
- Added a new arity to `changes` that allows you to pass optargs. [#112](https://github.com/apa512/clj-rethinkdb/issues/112)
- Renamed changes arg from `table` to `xs`. [#76](https://github.com/apa512/clj-rethinkdb/issues/76)
- Prefix RethinkDB server exceptions with `RethinkDB server:`. [#100](https://github.com/apa512/clj-rethinkdb/pull/100)
- Mask auth-key when logging connection exceptions [#90](https://github.com/apa512/clj-rethinkdb/issues/90)

### Added
- Added a new arity to `changes` that allows you to pass optargs. [#112](https://github.com/apa512/clj-rethinkdb/issues/112)
- Added new arity to `uuid` to allow you to pass a string. The string is then SHA-1 hashed to a UUID. Only valid in RethinkDB >= 2.2. [#109](https://github.com/apa512/clj-rethinkdb/issues/109)

## [0.11.0] - 2015-10-19
### Added
Expand Down
9 changes: 6 additions & 3 deletions src/rethinkdb/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,12 @@

(defn uuid
"Return a UUID (universally unique identifier), a string that can be used as
a unique ID."
[]
(term :UUID []))
a unique ID. If a string is passed, a UUID is generated based on a SHA-1 hash
of the string."
([]
(term :UUID []))
([string]
(term :UUID [string])))

;;; Sorting

Expand Down
12 changes: 9 additions & 3 deletions test/rethinkdb/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[rethinkdb.query :as r]
[rethinkdb.core :as core]
[rethinkdb.net :as net])
(:import (clojure.lang ExceptionInfo)))
(:import (clojure.lang ExceptionInfo)
(java.util UUID)))

(def test-db "cljrethinkdb_test")
(def test-table :pokedex)
Expand Down Expand Up @@ -61,7 +62,7 @@
(r/table-create (r/db test-db) :tmp) {:tables_created 1}
(r/table-create (r/db test-db) :tmp2) {:tables_created 1}
(-> (r/table :tmp)
(r/insert {:id (java.util.UUID/randomUUID)})) {:inserted 1}
(r/insert {:id (UUID/randomUUID)})) {:inserted 1}
(r/table-drop (r/db test-db) :tmp) {:tables_dropped 1}
(r/table-drop :tmp2) {:tables_dropped 1}
(-> (r/table test-table) (r/index-create :name)) {:created 1}
Expand Down Expand Up @@ -181,7 +182,12 @@
(r/split "split,this string" ",") ["split" "this string"]
(r/split "split this string" " " 1) ["split" "this string"]
(r/upcase "Shouting") "SHOUTING"
(r/downcase "Whispering") "whispering")))
(r/downcase "Whispering") "whispering"

;; UUID's
(r/uuid "slava@example.com") "90691cbc-b5ea-5826-ae98-951e30fc3b2d"
(r/uuid "a") "d0333a3b-39b1-5201-b37a-7bfbf6542b5f")
(is (instance? UUID (UUID/fromString (r/run (r/uuid) conn))))))

(deftest dates-and-times
(with-open [conn (r/connect)]
Expand Down

0 comments on commit 762d1a7

Please # to comment.