moved get-collection-names to new db ns
This commit is contained in:
parent
d5cce8c97b
commit
300220da15
4 changed files with 45 additions and 16 deletions
|
|
@ -170,14 +170,6 @@
|
||||||
[^Map cmd]
|
[^Map cmd]
|
||||||
(.command ^DB *mongodb-database* ^DBObject (to-db-object cmd)))
|
(.command ^DB *mongodb-database* ^DBObject (to-db-object cmd)))
|
||||||
|
|
||||||
(defn ^Set get-collection-names
|
|
||||||
"Returns a set containing the names of all collections in this database.."
|
|
||||||
([]
|
|
||||||
(.getCollectionNames ^DB *mongodb-database*))
|
|
||||||
([^DB database]
|
|
||||||
(.getCollectionNames ^DB database))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
(defprotocol Countable
|
(defprotocol Countable
|
||||||
(count [this] "Returns size of the object"))
|
(count [this] "Returns size of the object"))
|
||||||
|
|
|
||||||
26
src/monger/db.clj
Normal file
26
src/monger/db.clj
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
;; Copyright (c) 2011 Michael S. Klishin
|
||||||
|
;;
|
||||||
|
;; The use and distribution terms for this software are covered by the
|
||||||
|
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
||||||
|
;; which can be found in the file epl-v10.html at the root of this distribution.
|
||||||
|
;; By using this software in any fashion, you are agreeing to be bound by
|
||||||
|
;; the terms of this license.
|
||||||
|
;; You must not remove this notice, or any other, from this software.
|
||||||
|
|
||||||
|
(ns monger.db
|
||||||
|
(:refer-clojure :exclude [find remove count drop distinct empty?])
|
||||||
|
(:import [com.mongodb Mongo DB DBCollection])
|
||||||
|
(:require [monger core]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defn get-collection-names
|
||||||
|
"Returns a set containing the names of all collections in this database.."
|
||||||
|
([]
|
||||||
|
(into #{} (.getCollectionNames ^DB monger.core/*mongodb-database*)))
|
||||||
|
([^DB database]
|
||||||
|
(into #{} (.getCollectionNames ^DB database)))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,14 +28,6 @@
|
||||||
(is (instance? com.mongodb.DB db))))
|
(is (instance? com.mongodb.DB db))))
|
||||||
|
|
||||||
|
|
||||||
(deftest get-collection-names
|
|
||||||
(mgcol/insert "test-1" { :name "Clojure" })
|
|
||||||
(mgcol/insert "test-2" { :name "Clojure" })
|
|
||||||
(let [collections (monger.core/get-collection-names)]
|
|
||||||
(is (.contains collections "test-1"))
|
|
||||||
(is (.contains collections "test-2"))
|
|
||||||
))
|
|
||||||
|
|
||||||
;; (deftest get-database-with-valid-credentials
|
;; (deftest get-database-with-valid-credentials
|
||||||
;; (let [connection (monger.core/connect)
|
;; (let [connection (monger.core/connect)
|
||||||
;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]
|
;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]
|
||||||
|
|
|
||||||
19
test/monger/test/db.clj
Normal file
19
test/monger/test/db.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
(ns monger.test.db
|
||||||
|
(:require [monger core db]
|
||||||
|
[monger.test.helper :as helper]
|
||||||
|
[monger.collection :as mgcol])
|
||||||
|
(:import (com.mongodb Mongo DB))
|
||||||
|
(:use [clojure.test]))
|
||||||
|
|
||||||
|
(helper/connect!)
|
||||||
|
|
||||||
|
|
||||||
|
(deftest get-collection-names
|
||||||
|
(mgcol/insert "test-1" { :name "Clojure" })
|
||||||
|
(mgcol/insert "test-2" { :name "Clojure" })
|
||||||
|
(let [collections (monger.db/get-collection-names)]
|
||||||
|
(is (.contains collections "test-1"))
|
||||||
|
(is (.contains collections "test-2"))
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue