Giter Site home page Giter Site logo

scalads's Introduction

ScalaDS

ScalaDS aims to provide macro based serialization and deserialization of classes for different datastore backends.

Philosophy

This is an experiment to see if I could make a datastore that would abstract the core features of serialization and generating queries while letting the native features of the backends shine through. To that end, entities are always natively accessible from query results even when deserializing to its scala class.

Features

  • Automatic serialization and deserialization of fields in class constructors (case class and regular class)
  • De-serialized classes are augmented with convenience methods for updating the datastore
  • Supports nested types and flattens the structure for storage
  • Type safe query system
  • Don’t need to add Serializable interface to classes
  • Returned “entities” are the real scala case classes augmented with different datastore methods to allow updating, removing, etc. See the ‘ds_’ methods of the EntityBacker trait that is mixed in to returned entities.

Supported Backends

Google App Engine Datastore

The starting point for this project, Googles App Engine Datastore is a first class citizen.

MongoDB

Fresh off the press is MongoDB support. It’s largely feature complete, but like the rest of this young lib, there are almost certainly bugs.

Flux

The library is still largely in the experimental stage. I expect the library to have an initially high code. Hopefully features will come and bugs will go...

sbt Dependency

There are currently no packages in maven repos which can automatically be pulled. The best way to get the library is to pull the github url directly.

Examples

getting the datastore will depend on the backend being used as there are different connection considerations

Serializing a class

val ds = Datastore.getDatastoreService()

case class Person(name: String, age: Int)

val bill = Person("Bill", 28)

ds.put(bill)

Querying a class

val ds = Datastore.getDatastoreService()

case class Person(name: String, age: Int)

val it = ds.query[Person].getIterator

for(p <- it) println(s"Hello ${p.name}. You are ${p.age} old!")

Applying filters and sorting

val ds = Datastore.getDatastoreService()

case class Person(name: String, age: Int)

val it = ds.query[Person]
    .filter(p => p.age > 21)
    .sortAsc(_.age)
    .getIterator

for(p <- it) println(s"Hello ${p.name}. You are older than 21")

Projecting Results

val ds = Datastore.getDatastoreService()

case class Person(name: String, age: Int)
case class Team(teamName: String, person1: Person, person2: Person)

val team = Team("cool", Person("Bill", 12), Person("Jane", 11))
ds.put(team)

val it = ds.query[Team]
  .sortAsc(_.teamName)       // Shortcut for .sortAsc(p => p.age)
  .project{ t =>
  val p1 = t.person1
  (t.teamName, p1.name)
}

for(p <- it) println(s"Hello ${p._2}. You are on team ${p._1}")

License

This project is licensed under the Apache 2.0 License.

Author

Bryce Anderson ([email protected])

scalads's People

Contributors

bryce-anderson avatar

Stargazers

Jakub Liska avatar Facundo Viale avatar Ross A. Baker avatar Ryan LeCompte avatar  avatar

Watchers

Ryan LeCompte avatar James Cloos avatar egorgorodov avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.