Browse files

Merge branch 'release/0.9.0'

  • Loading branch information...
2 parents b208cdd + 993f1f1 commit 38830c8e0313428c6c9c1b5cb035dc2a04ec7625 @wilkes committed Dec 10, 2011
View
5 project.clj
@@ -1,7 +1,6 @@
-(defproject karras "0.8.0"
+(defproject karras "0.9.0"
:description "A clojure entity framework for MongoDB"
- :dependencies [[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]
+ :dependencies [[org.clojure/clojure "[1.2.1],[1.3.0]"]
[org.mongodb/mongo-java-driver "2.7.2"]
[inflections "0.6.3"]]
:dev-dependencies [[midje "1.3.0-RC4"]]
View
28 src/karras/collection.clj
@@ -21,8 +21,8 @@
;; THE SOFTWARE.
(ns karras.collection
- (:use [clojure.contrib.def :only [defnk defvar]]
- [karras.core :only [*mongo-db* to-dbo to-clj build-dbo]])
+ (:use [karras.core :only [*mongo-db* to-dbo to-clj build-dbo]]
+ [karras.def :only [defvar]])
(:import [com.mongodb Mongo DB DBCollection DBObject]
[org.bson.types ObjectId]))
@@ -116,7 +116,7 @@
(make-map include 1)
(make-map exclude 0))))
-(defnk fetch
+(defn fetch
"Fetch a seq of documents that match a given criteria.
Accepts the following keywords:
:limit, maximum number of documents to return
@@ -126,7 +126,8 @@
:sort, which keys to order by
:count, if true return the count of the result set, defaults to false"
[#^DBCollection coll criteria
- :limit nil :skip nil :include nil :exclude nil :sort nil :count false]
+ & {:keys [limit skip include exclude sort count]
+ :or {count false}}]
(let [cursor (if criteria
(if (or include exclude)
(let [keys (build-fields-subset include exclude)]
@@ -223,20 +224,25 @@
(.throwOnError response)
(to-clj (.get response "value"))))
-(defnk find-and-modify
+(defn find-and-modify
"See http://www.mongodb.org/display/DOCS/findandmodify+Command"
- [#^DBCollection coll criteria modifier :sort [] :return-new true :fields [] :upsert false]
+ [#^DBCollection coll criteria modifier
+ & {:keys [sort return-new fields upsert]
+ :or {sort [] return-new true fields [] upsert false}}]
(find-and-modify* coll criteria modifier false sort return-new fields upsert))
-(defnk find-and-remove
+(defn find-and-remove
"See http://www.mongodb.org/display/DOCS/findandmodify+Command"
- [#^DBCollection coll criteria :sort [] :return-new false :fields []]
+ [#^DBCollection coll criteria
+ & {:keys [sort return-new fields]
+ :or {sort [] return-new true fields []}}]
(find-and-modify* coll criteria nil true sort return-new fields false))
-(defnk map-reduce
+(defn map-reduce
"See http://www.mongodb.org/display/DOCS/MapReduce"
- [#^DBCollection coll mapfn reducefn :query nil :sort [] :limit nil
- :out nil :keeptemp? false :finalize nil :scope nil :verbose? true]
+ [#^DBCollection coll mapfn reducefn
+ & {:keys [query sort limit out keeptemp? finalize scope verbose?]
+ :or {sort [] keeptemp? false verbose? true}}]
(let [db (collection-db coll)
cmd (apply build-dbo
(concat [:mapreduce (.getName coll)]
View
1 src/karras/core.clj
@@ -21,7 +21,6 @@
;; THE SOFTWARE.
(ns karras.core
- (:use [clojure.contrib.def :only [defvar]])
(:import [com.mongodb Mongo DB BasicDBObject BasicDBObjectBuilder]
[java.util Map Map$Entry List]))
View
11 src/karras/def.clj
@@ -0,0 +1,11 @@
+(ns karras.def)
+
+;; Stolen from clojure.contrib.def until I figure out how to support clojure 1.2 and clojure 1.3
+(defmacro defvar
+ "Defines a var with an optional intializer and doc string"
+ ([name]
+ (list `def name))
+ ([name init]
+ (list `def name init))
+ ([name init doc]
+ (list `def (with-meta name (assoc (meta name) :doc doc)) init)))
View
4 src/karras/entity.clj
@@ -18,8 +18,8 @@ Example:
karras.entity
(:require [karras.collection :as c])
(:use karras.sugar
- [clojure.contrib.def :only [defnk defalias defvar]]
- [clojure.contrib.str-utils2 :only [lower-case]]
+ [karras.def :only [defvar]]
+ [clojure.string :only [lower-case]]
inflections.core))
(defrecord EntitySpec
View
14 src/karras/sugar.clj
@@ -1,17 +1,17 @@
;; The MIT License
-;;
+;;
;; Copyright (c) 2010 Wilkes Joiner
-;;
+;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
-;;
+;;
;; The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.
-;;
+;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -21,7 +21,7 @@
;; THE SOFTWARE.
(ns karras.sugar
- (:use [clojure.contrib.def :only [defvar]])
+ (:use [karras.def :only [defvar]])
(:import [java.util Calendar]))
(defn compound-index
@@ -124,8 +124,8 @@
(defn pull-all "" [field values] {:$pullAll {field values}})
(defn date
- "A convenience constructor for making a java.util.Date. Takes zero or more
- args. Zero args return the current time. One or more args returns a date
+ "A convenience constructor for making a java.util.Date. Takes zero or more
+ args. Zero args return the current time. One or more args returns a date
values provided and all other values zeroed out.
Args are year, month, date, hour, minute, second, and milliseconds"
[& [year month date hour minute second milli]]
View
17 test/karras/test_collection.clj
@@ -19,6 +19,11 @@
(defn person-by-name [n]
(fetch-one people {:first-name n}))
+(def ^:dynamic Bill nil)
+(def ^:dynamic Sally nil)
+(def ^:dynamic Jim nil)
+(def ^:dynamic Jane nil)
+
(background
(around :facts
(do
@@ -60,15 +65,15 @@
(fact "group by a key"
(group people [:age])
- => (in-any-order [{:age 21.0 :values [Bill]}
- {:age 18.0 :values [Sally]}
- {:age 16.0 :values [Jim Jane]}]))
+ => (in-any-order [{:age 21 :values [Bill]}
+ {:age 18 :values [Sally]}
+ {:age 16 :values [Jim Jane]}]))
(fact "group by multiple keys"
(group people [:age :last-name])
- => (in-any-order [{:age 21.0 :last-name "Smith" :values [Bill]}
- {:age 18.0 :last-name "Jones" :values [Sally]}
- {:age 16.0 :last-name "Johnson" :values [Jim Jane]}]))
+ => (in-any-order [{:age 21 :last-name "Smith" :values [Bill]}
+ {:age 18 :last-name "Jones" :values [Sally]}
+ {:age 16 :last-name "Johnson" :values [Jim Jane]}]))
(fact "group and count"
(group people
View
2 test/karras/test_entity.clj
@@ -81,7 +81,7 @@
(-> person :address class) => Address
(-> person :address :street class) => Street
(-> person :phones first class)=> Phone
- (-> person :counter) => 0.0
+ (-> person :counter) => 0
(-> person :phones first :country-code) => 1))
(let [person (make Person #^{:meta "data"} {:first-name "Jimmy"})]

0 comments on commit 38830c8

Please sign in to comment.