Scalad

Scalad is a collection of data access components for your Scala code. The code [greatly] simplifies the code you have to write to manipulate objects that will end up in some kind of database in your Scala applications. Naturally, Scalad supports the traditional relational data access as well as the modern document and graph databases.

As usual, the sample code shows our thinking & motivation:

val entityManagerFactory = 
  Persistence.createEntityManagerFactory("example")
val entityManager = entityManagerFactory.createEntityManager()
val jpa = new JPA(entityManager)

for (i <- 0 to 20) {
  val u = new User()
  u.setUsername("a" + i)
  jpa.persist(u)
}

val users = jpa.select(list[User])
// users is a List[User] containing all users

val m1 = head[User] >>= (u => head map (u2 => (u <|*|> u2)))
val ftSelector = jpa.selector(m1)
// ftSelector is a function that expects some query and
// returns a Option of tuple of the first two matching records
// or None if there are fewer than two records

val a1Something = ftSelector("username" like "a1%")
val a2Something = ftSelector("username" like "a2%")
// a2Something == Some(u1, u2) where u1 and u2 are the User objects
//                             whose username is LIKE a2%
// a1Something == Some(u1, u2) where u1 and u2 are the User objects
//                             whose username is LIKE a1%


jpa.select(one[User])
// fails: there are more than one User objects
jpa.selectThat(one[User])("username" like "B")
// fails: there are no such User objects
jpa.selectThat(one[User])("username" is "a1")
// succeeds: returns User whose username equals "a1"

val a1 = jpa.selectThat(head[User])("username" like "a10%")
// a1 == Some(u) where u is the User object
                 whose username is LIKE a10%
}

Downloads & Links

The downloads, documentation and all other goodneess is coming shortly. The artifacts will be available directly from here and from Maven central. For now, if you are interested in Scalad, you will have to get your hands on the source code at https://github.com/janm399/scalad and read some blog posts at http://www.cakesolutions.net/teamblogs/tag/scalad/

Latest Tweets

 
 
@technige Well, good sir, we incentivise the stakeholders of enterprise cake initiatives :) So, ehm... sorry, no real cakes.
RT @AmarettoAndCode: The 'This week in #Scala' that you know and love has just been released! http://t.co/E1D4Bwm6 Check it out, you kn ...
RT @rjurney: Loading data from Pig right into Cube via MongoDB and MongoStorage. Woot! #in cc @ChrisDiehl @mbostock @rit