-
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.
Extraction to separate Collection from Model for more complex scenarios
- Loading branch information
1 parent
b4cf710
commit 62324ce
Showing
22 changed files
with
136 additions
and
88 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
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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package lightdb.model | ||
|
||
import fabric.rw.RW | ||
import lightdb.{Document, LightDB} | ||
|
||
abstract class Collection[D <: Document[D]](val collectionName: String, | ||
protected[lightdb] val db: LightDB, | ||
val autoCommit: Boolean = false, | ||
val atomic: Boolean = true) extends AbstractCollection[D] with DocumentModel[D] { | ||
override def model: DocumentModel[D] = this | ||
} | ||
|
||
object Collection { | ||
def apply[D <: Document[D]](collectionName: String, | ||
db: LightDB, | ||
autoCommit: Boolean = false)(implicit docRW: RW[D]): Collection[D] = | ||
new Collection[D](collectionName, db, autoCommit = autoCommit) { | ||
override implicit val rw: RW[D] = docRW | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package lightdb.model | ||
|
||
import cats.effect.IO | ||
import cats.implicits.{catsSyntaxApplicativeByName, toTraverseOps} | ||
import fabric.Json | ||
import fabric.rw.RW | ||
import lightdb.index.IndexedField | ||
import lightdb.{Document, Id, IndexedLinks} | ||
|
||
trait DocumentModel[D <: Document[D]] { | ||
type Field[F] = IndexedField[F, D] | ||
|
||
implicit val rw: RW[D] | ||
|
||
private[lightdb] var _indexedLinks = List.empty[IndexedLinks[_, D]] | ||
|
||
def indexedLinks: List[IndexedLinks[_, D]] = _indexedLinks | ||
|
||
/** | ||
* Called before preSetJson and before the data is set to the database | ||
*/ | ||
def preSet(doc: D, collection: AbstractCollection[D]): IO[D] = IO.pure(doc) | ||
|
||
/** | ||
* Called after preSet and before the data is set to the database | ||
*/ | ||
def preSetJson(json: Json, collection: AbstractCollection[D]): IO[Json] = IO.pure(json) | ||
|
||
/** | ||
* Called after set | ||
*/ | ||
def postSet(doc: D, collection: AbstractCollection[D]): IO[Unit] = for { | ||
// Update IndexedLinks | ||
_ <- _indexedLinks.map(_.add(doc)).sequence | ||
_ <- collection.commit().whenA(collection.autoCommit) | ||
} yield () | ||
|
||
def preDelete(id: Id[D], collection: AbstractCollection[D]): IO[Id[D]] = IO.pure(id) | ||
|
||
def postDelete(doc: D, collection: AbstractCollection[D]): IO[Unit] = for { | ||
// Update IndexedLinks | ||
_ <- _indexedLinks.map(_.remove(doc)).sequence | ||
_ <- collection.commit().whenA(collection.autoCommit) | ||
} yield () | ||
} |
3 changes: 2 additions & 1 deletion
3
lucene/src/main/scala/lightdb/lucene/index/BigDecimalField.scala
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
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
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
Oops, something went wrong.