package getAsyncObj
Asynchronous getter methods to retrieve data as objects.
For convenience, all synchronous getter methods from the get
package are here wrapped in Futures.
The Datomic On-Prem(ises) server model provides a Peer that returns data synchronously. The Peer which lives in application memory caches data aggressively and for data fitting in memory, latency can be extremely low and queries return very fast. And even when access to disk is needed, clever branching is used. Memcached is also an option.
The Datomic Cloud model data returns data asynchronously. If Datomic creates a Java API for the Cloud model, Molecule could relatively easy adapt to this model too. In the meanwhile, Future-wrapped methods in this package can be used.
Molecule has 4 groups of asynchronous getters for objects, each returning Futures of data in various formats:
- GetAsyncObjArray - fastest retrieved typed data set. Can be traversed with a fast
while
loop - GetAsyncObjIterable - for lazily traversing row by row
- GetAsyncObjList - default getter returning Lists of objects. Convenient typed data, suitable for smaller data sets
- GetAsyncRaw - fastest retrieved raw un-typed data from Datomic
Getters in each of the 4 groups come with 5 time-dependent variations:
- getAsync [current data]
- getAsyncAsOf
- getAsyncSince
- getAsyncWith
- getAsyncHistory
Each time variation has various overloads taking different parameters (see each group for more info).
- Source
- getAsyncObj.scala
- See also
equivalent synchronous getters in the getTpl package.
Type Members
- trait GetAsyncObjArray[Obj, Tpl] extends AnyRef
Asynchronous data getter methods on molecules returning
Future[Array[Obj]]
.Asynchronous data getter methods on molecules returning
Future[Array[Obj]]
.
The fastest way of getting a large typed data set since data is applied to a super fast pre-allocated Array. The Array can then be traversed with a fastwhile
loop.Ns.int.insert(1, 2, 3) // Map over Future Ns.int.getAsyncObjArray.map { rowObjects => rowObjects.map(_.int) === Array(1, 2, 3) // Fast while loop var i = 0 val length = rowObjects.length while(i < length) { println(rowObjects(i).int) // Do stuff with row object... i += 1 } }
Each asynchronous getter in this package simply wraps the result of its equivalent synchronous getter (in the
get
package) in a Future.getAsyncObjArrayAsOf
thus wraps the result ofgetObjArrayAsOf
in a Future and so on. - trait GetAsyncObjIterable[Obj, Tpl] extends AnyRef
Asynchronous data getter methods on molecules returning
Future[Iterable[Obj]]
.Asynchronous data getter methods on molecules returning
Future[Iterable[Obj]]
.
Suitable for data sets that are lazily consumed.for { personsIterable <- Person.name.age.getAsyncObjIterable } yield { val firstPerson = personsIterable.iterator.next firstPerson.name === "Ben" firstPerson.age === 42 }
Each asynchronous getter in this package simply wraps the result of its equivalent synchronous getter in a Future.
getAsyncObjIterableAsOf
thus wraps the result ofgetObjIterableAsOf
in a Future and so on. - trait GetAsyncObjList[Obj, Tpl] extends AnyRef
Default asynchronous data getter methods on molecules returning
Future[List[Obj]]
.Default asynchronous data getter methods on molecules returning
Future[List[Obj]]
.
For expected smaller result sets it's convenient to return Lists of objects of data.for { persons <- Person.name.age.getAsyncObjList } yield { persons.map(p => s"${p.name} is ${p.age} years old")) === List( "Ben is 42 years old", "Liz is 37 years old" ) }
Each asynchronous getter in this package simply wraps the result of its equivalent synchronous getter in a Future.
getAsyncObjListAsOf
thus wraps the result ofgetObjListAsOf
in a Future and so on.
Documentation/API for the Molecule library - a meta DSL for the Datomic database.
scalamolecule.org | Github | Forum