Created
March 8, 2012 14:50
-
-
Save dmozzy/2001351 to your computer and use it in GitHub Desktop.
GeoTaskList tutorial #2 Appengine Persistence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Follow the blog posts for this code here: http://www.digitalbricklayers.com/2012/03/geotasklist-part-2.html | |
(ns GeoTaskList.persistence | |
(:require [appengine-magic.services.datastore :as ds])) | |
(ds/defentity Location [^:key locationId, ^:clj location]) | |
;Save a location. -1 is used to signify no id passed in and nil | |
;should be substitued | |
(defn save-location [location-map] | |
(let [input-id (Integer/parseInt (:locationId location-map)) | |
id (if (= input-id -1) nil input-id)] | |
(ds/save! (Location. id location-map)))) | |
;Loads all locations. Retrieves the location field map for all locations | |
; and then adds in the locationId key value pair for each location. | |
(defn get-all-locations [] | |
(map | |
(fn [k] | |
(assoc (:location k) :locationId (ds/key-id k)));This line sets the id onto the map at load time | |
(ds/query :kind Location))) | |
;Deletes a location by locationId | |
(defn delete-location [locationId] | |
(ds/delete! | |
(ds/retrieve Location locationId))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment