Simplistic: Scala bindings for Amazon SimpleDB
Scala
Switch branches/tags
Pull request Compare This branch is 7 commits ahead of balshor:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
project
src
.classpath
.gitignore
.project
CHANGELOG
README

README

Simplistic: Scala Bindings for SimpleDB (Amazon Web Services)
=============================================================

This is a fork of <http://github.com/rbarooah/simpledb-scala-binding> migrating to sbt, and cleaning up the examples. 

// Assuming you have installed sbt ( http://code.google.com/p/simple-build-tool/ ) you can build like this:

sbt update
sbt compile

// run tests:

sbt test

// create a jar file

sbt package

//to do examples in the REPL do this:

sbt console

// then you can do the examples:
//
// (BTW, the most important file is the SimpleAPI.scala)

-------------------------------------------------------------------------------
/**
 * Simple test file used for experimentation at the console.
 */

import simplistic._
import Conversions._
import Attributes._
import Select._

val account = new SimpleDBAccount(System.getenv("AWS_ACCESS_KEY_ID"), System.getenv("AWS_SECRET_ACCESS_KEY"))

// List all domains
account.domains.toList

// get a domain
val data = account.domain("testdata")

// make sure the domain exists
data.create()

// define some attributes
val user = attribute("user")
val startDate = attribute("startDate", ISO8601Date)
val visits = attribute("visits", PositiveInt)
val tags = attribute("tags")

// insert some items

//create (or get) an item named ItemName
val item = data.item("ItemName")

//add an attribute named attributeName
item += (("attributeName", "attributeValue"))

//add an user typed attribute (defined above)
item += user("fred's user name")

//add a multple attribute
item += ("hobbies", Set("golf","hunting"))

//see all attributes as a Map
item.attributes

//return attributes as an Option
item.attributesOption

//get the attributes
item.attribute("hobbies")
item.attribute("attributeName")

//get back the typed attribute
item.attribute(user)

//remove an attribute
item -= ("attributeName")

//remove a typed attribute
item -= user

//-------------------------------------------------------------
// Selects 

for ( i <- data.select( user is "fred")) { println(user(i)) }


// unique uses a UUID as its name
data.unique += (user("robin"), startDate(new java.util.Date()), visits(3))
data.unique += (user("jon"), startDate(new java.util.Date()), visits(20))
data.unique += (user("alice"), startDate(new java.util.Date()), visits(15))
data.unique += (user("jack"), startDate(new java.util.Date()), visits(100))



// do some queries

data.select(visits > 16)



for (i <- data.select(visits > 16)) { println(user(i)) }

for (i <- data.select(  visits > 16 and  
                        visits < 50) ) { println(user(i)) }

for (i <- data.select(  visits > 1 and
                        visits < 50
                        orderBy visits desc) ) { println(user(i)) }

for (i <- data.select(  visits > 1 and
                        visits < 50
                        orderBy user desc) ) { println(user(i)) }

for (i <- data.select( user is "robin"))  { println(visits(i)) }

//as a foreach
data.select(visits > 1 and visits < 50).foreach( i => println( user(i) ))

data.count( visits > 10)

// get rid of the test data
(data items) foreach (_.clear)

---------------------------------------------------------------------------------


### Target platform ###

* Scala 2.8.0+
* JVM 1.6+

### License ###

Simplistic is is licensed under the terms of the Apache Software License v2.0.
<http://www.apache.org/licenses/LICENSE-2.0.html>