From 300220da15a2a8879c0765d86427816761077c48 Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Wed, 15 Feb 2012 21:00:01 +1100 Subject: [PATCH] moved get-collection-names to new db ns --- src/monger/core.clj | 8 -------- src/monger/db.clj | 26 ++++++++++++++++++++++++++ test/monger/test/core.clj | 8 -------- test/monger/test/db.clj | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 src/monger/db.clj create mode 100644 test/monger/test/db.clj diff --git a/src/monger/core.clj b/src/monger/core.clj index e538bc9..90fe581 100644 --- a/src/monger/core.clj +++ b/src/monger/core.clj @@ -170,14 +170,6 @@ [^Map 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 (count [this] "Returns size of the object")) diff --git a/src/monger/db.clj b/src/monger/db.clj new file mode 100644 index 0000000..345e6fb --- /dev/null +++ b/src/monger/db.clj @@ -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))) +) + + + diff --git a/test/monger/test/core.clj b/test/monger/test/core.clj index c43bd1b..62b7513 100644 --- a/test/monger/test/core.clj +++ b/test/monger/test/core.clj @@ -28,14 +28,6 @@ (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 ;; (let [connection (monger.core/connect) ;; db (monger.core/get-db connection "monger-test" "monger" "test_password")] diff --git a/test/monger/test/db.clj b/test/monger/test/db.clj new file mode 100644 index 0000000..300bf4c --- /dev/null +++ b/test/monger/test/db.clj @@ -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")) + )) + +