Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests, add table arities #54

Merged
merged 3 commits into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. This change
- Add alias for `rethinkdb.core/connect` into `rethinkdb.query/connect` so you don't need to import the `rethinkdb.core` namespace. [#44](https://github.com/apa512/clj-rethinkdb/pull/44)
- Add CHANGELOG.md [#47](https://github.com/apa512/clj-rethinkdb/pull/47)

### Changed
- Add new arity for the queries `table-drop`, and `table-list` which doesn't require a db. [#54](https://github.com/apa512/clj-rethinkdb/pull/54/files)
- Add docstring to `rethinkdb.query` ns explaining DB priority [#54](https://github.com/apa512/clj-rethinkdb/pull/54/files)

### Fixed
- Fix close method on Connection record [#50](https://github.com/apa512/clj-rethinkdb/pull/50)
- Fix handling of sending CONTINUE queries to RethinkDB when using an implicit db on the connection. Affects any query that returns a Cursor. [#52](https://github.com/apa512/clj-rethinkdb/pull/52)
Expand Down
46 changes: 32 additions & 14 deletions src/rethinkdb/query.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
(ns rethinkdb.query
"Public interface to clj-rethinkdb. You should only need to require this namespace.

Priority of databases used in queries:
1. If a database is explicitly specified as part of a query it will always be used.
2. If there is no database used in the query AND a database is set on the database
at connection time (with the :db parameter), then this will be used.
3. If there is no database in the query or connection, then RethinkDB will fall back
to using the \"test\" database (You probably don't want this).

N.B. Database names are validated at query time, not connection time."
(:refer-clojure :exclude [count filter map get not mod replace merge
reduce make-array distinct keys nth min max
or and do fn sync time update])
(:require [clojure.data.json :as json]
[clojure.walk :refer [postwalk postwalk-replace]]
[clojure.test :as test]
[rethinkdb.net :refer [send-start-query] :as net]
[rethinkdb.core :as core]
[rethinkdb.query-builder :refer [term parse-term]]))
[rethinkdb.query-builder :refer [term parse-term]])
(:import (rethinkdb.core Connection)))

(defmacro fn [args & [body]]
(let [new-args (into [] (clojure.core/map #(hash-map :temp-var (keyword %)) args))
Expand All @@ -18,11 +30,12 @@

(def connect
"Creates a database connection to a RethinkDB host
[& {:keys [host port token auth-key]
[& {:keys [host port token auth-key db]
:or {host \"127.0.0.1\"
port 28015
token 0
auth-key \"\"}}" core/connect)
auth-key \"\"
db nil}}" core/connect)

;;; Cursors

Expand All @@ -32,13 +45,12 @@
;;; Manipulating databases

(defn db-create
"Create a database. Note that you can only use alphanumeric characters and
underscores for the database name."
"Creates a database."
[db-name]
(term :DB_CREATE [db-name]))

(defn db-drop
"Drop a database."
"Drops a database."
[db-name]
(term :DB_DROP [db-name]))

Expand All @@ -55,14 +67,20 @@
(term :TABLE_CREATE [db table-name] optargs))

(defn table-drop
"Drop a table."
[db table-name]
(term :TABLE_DROP [db table-name]))
"Drop a table. If no db is provided then precedence follows the
order given in the rethinkdb.query ns documentation."
([table-name]
(term :TABLE_DROP [table-name]))
([db table-name]
(term :TABLE_DROP [db table-name])))

(defn table-list
"List all table names in a database."
[db]
(term :TABLE_LIST [db]))
"List all table names in a database. If no db is provided then precedence
follows the order given in the rethinkdb.query ns documentation."
([]
(term :TABLE_LIST []))
([db]
(term :TABLE_LIST [db])))

(defn index-create
"Create a new secondary index on a table."
Expand Down Expand Up @@ -148,8 +166,8 @@

(defn table
"Select all documents in a table. This command can be chained with other
commands to do further processing on the data. If no db is provided then
the default database for the connection will be used"
commands to do further processing on the data. If no db is provided then precedence
follows the order given in the rethinkdb.query ns documentation."
([table-name]
(term :TABLE [table-name]))
([db table-name]
Expand Down
Loading