Skip to content

Instantly share code, notes, and snippets.

@dmozzy
Created March 8, 2012 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmozzy/2001351 to your computer and use it in GitHub Desktop.
Save dmozzy/2001351 to your computer and use it in GitHub Desktop.
GeoTaskList tutorial #2 Appengine Persistence
;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