-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support for Materialized to use JSON
- Loading branch information
1 parent
903f896
commit 1a83cb5
Showing
2 changed files
with
12 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package lightdb.index | ||
|
||
import fabric.Json | ||
import fabric.rw.{Asable, RW} | ||
import lightdb.{Document, Id} | ||
|
||
class Materialized[D <: Document[D]](map: Map[Index[_, D], Any]) { | ||
def get[F](index: Index[F, D]): Option[F] = map.get(index).map(_.asInstanceOf[F]) | ||
def apply[F](index: Index[F, D]): F = get(index).getOrElse(throw new NullPointerException(s"${index.fieldName} not found in [${map.keySet.map(_.fieldName).mkString(", ")}]")) | ||
class Materialized[D <: Document[D]](json: Json) { | ||
def get[F](index: Index[F, D]): Option[F] = json.get(index.fieldName).map(_.as[F](index.rw)) | ||
def apply[F](index: Index[F, D]): F = get(index).getOrElse(throw new NullPointerException(s"${index.fieldName} not found in $json")) | ||
def as[T](implicit rw: RW[T]): T = json.as[T] | ||
} |
This file contains 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