sdb
sdb copied to clipboard
A Clojure library for working with Amazon SimpleDB
h1. sdb
A Clojure library for working with "Amazon SimpleDB":http://aws.amazon.com/simpledb/ , "(docs)":http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/
Built on top of Amazon's "Java API for SimpleDB":http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1132&categoryID=189 , "(javadocs)":http://s3.amazonaws.com/awscode/amazon-simpledb/2007-11-07/java/library/doc/index.html
The library lets you directly save and load Clojure data, and query using data. No strings! Stores using lexicographically-sortable representations. Can store strings, keywords, ints, longs, Dates, booleans and UUIDs, and can be extended to other primitives.
The dependencies can be downloaded from "the downloads area":http://cloud.github.com/downloads/richhickey/sdb/deps.zip
h2. Usage
(use 'org.clojure.sdb) (def aws-key "[...]") (def aws-secret-key "[...]") (def client (create-client aws-key aws-secret-key)) (put-attrs client "heroes" {:sdb/id "spiderman" :power "spidery-things" :secret-identity "Peter Parker"}) (put-attrs client "heroes" {:sdb/id "hulk" :power "huge angry thing" :secret-identity "Bruce Banner"}) (put-attrs client "heroes" {:sdb/id "venom" :power "spidery-things" :secret-identity "Eddie Brock" :evil true}) (get-attrs client "heroes" "spiderman") ;; {:secret-identity "Peter Parker", :power "spidery-things", :sdb/id "spiderman"} (query client '{:select [:secret-identity] :from "heroes" :where (= :evil true)}) ;; ({:secret-identity "Eddie Brock", :sdb/id "venom"})
h2. Local Use
It's not always desirable to connect to a live server when using SimpleDB since you get charged (a small amount) for every transaction, and you won't be able to develop while offline. To develop against a local SimpleDB mock, download and install "SimpleDB-dev":http://code.google.com/p/simpledb-dev/ and configure your client to use an alternate service URL:
$ wget http://simpledb-dev.googlecode.com/files/simpledb-dev-0.1.10.zip $ unzip simpledb-dev-0.1.10.zip $ python SimpleDB-Dev/src/simpledb_dev.py & In your code: (create-client my-sdb-key my-sdb-secret-key (.withServiceURL (com.amazonaws.sdb.AmazonSimpleDBConfig.) "http://localhost:8080")))