Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add get and delete.

  • Loading branch information...
commit a782bbf9d01b611b021664fec492dd5dde8f8afc 1 parent 7555fd6
@duelinmarkers authored
View
17 src/appengine_clj/datastore.clj
@@ -1,8 +1,7 @@
(ns appengine-clj.datastore
(:import (com.google.appengine.api.datastore
- DatastoreServiceFactory
- Entity
- Query)))
+ DatastoreServiceFactory Entity Key Query))
+ (:refer-clojure :exclude [get]))
(defn entity-to-map
@@ -14,6 +13,11 @@
{:kind (.getKind entity) :key (.getKey entity)}
(.entrySet (.getProperties entity))))
+(defn get
+ "Retrieves the identified entity or raises EntityNotFoundException."
+ [#^Key key]
+ (.get (DatastoreServiceFactory/getDatastoreService) key))
+
(defn find-all
"Executes the given com.google.appengine.api.datastore.Query
and returns the results as a lazy sequence of items converted with entity-to-map."
@@ -27,7 +31,7 @@
The map must include a :kind String.
Returns the saved Entity converted with entity-to-map (which will include the assigned :key)."
([item] (create item nil))
- ([item parent-key]
+ ([item #^Key parent-key]
(let [kind (item :kind)
properties (dissoc item :kind)
entity (if parent-key (Entity. kind parent-key) (Entity. kind))]
@@ -35,3 +39,8 @@
(.put (DatastoreServiceFactory/getDatastoreService) entity)
(entity-to-map entity))))
+(defn delete
+ "Deletes the identified entities."
+ [& #^Key keys]
+ (.delete (DatastoreServiceFactory/getDatastoreService) keys))
+
View
6 test/appengine_clj/datastore_test.clj
@@ -6,6 +6,7 @@
(:import (com.google.appengine.api.datastore
DatastoreServiceFactory
Entity
+ EntityNotFoundException
Query
Query$FilterOperator
Query$SortDirection)))
@@ -43,3 +44,8 @@
(is (= (parent :key) (.getParent (child :key))))
(is (= [child] (ds/find-all (doto (Query. "Child" (parent :key))))))))
+(dstest delete-by-key
+ (let [key (:key (ds/create {:kind "MyKind"}))]
+ (ds/delete key)
+ (is (thrown? EntityNotFoundException (ds/get key)))))
+

0 comments on commit a782bbf

Please sign in to comment.
Something went wrong with that request. Please try again.