Created
May 25, 2009 16:52
-
-
Save koduki/117611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def toFilter1(property:Symbol) = new { | |
def ===(value:Any):Query => Query = | |
query => query.addFilter(property.toString, Query.FilterOperator.EQUAL, value) | |
} | |
class DataStore(){ | |
val ds = DatastoreServiceFactory.getDatastoreService() | |
def from(name:Symbol) = new Filter(ds, new Query(name.toString)) | |
} | |
class Filter(ds:DatastoreService, query:Query){ def where(predicate:Query => Query) = new FetchOption(ds, predicate(query))} | |
class FetchOption(ds:DatastoreService, query:Query){ | |
def limit(offset:Int, limit:Int) = new { | |
def asIterator() = ds.prepare(query).asIterable(FetchOptions.Builder.withLimit(limit).offset(offset)) | |
} | |
} | |
// Sample Query | |
new DataStore() from('Person) where('age === 9) limit(1, 3) asIterator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment