Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Conversation

@WojciechMazur
Copy link
Collaborator

Introduces transactional operations using Mutatus as it is supported in Datastore.
It does not break backward compability due to introduction of Contexts. Operations executed with default mode (not transactional or batched) are handled with implicit Context.Default

In case if all operations within transaction block would pass, transaction should be automatically commited, in other case whole transaction would be rolled back

 Dao.transaction{ implicit tx =>  for{
       foo <-  Result(Dao.all.filter(_.bar == "bar").run()) //since now .run returns Stream[Result[T]]
       bar  <- foo.map(_.copy(bar = "foo")).saveAll
      } yield bar
    }

Also changed return type of QueryBuilder.run() to Stream[Result[T]]
from previous Result[Stream[Result[T]]]

Using the same syntax is possible to execute Batch, using Dao.batch(implicit batch => ..., which is write only operation. In case of using read operations within batch block compile time error would be thrown.

val q"($arg) => $fnBody" = batch
//Using external context is a proof that provided Context.Batch was not sufficient to perform operation, though external (default) context was used
//Such construct could be considered as dirty hack, but I've not found better way to found usage of default context
val usesExternalContext = fnBody.exists(showCode(_).contains("Context.default"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit dirty hack, but I've not found better solution to check at compile time if prohibited read operations were used.

@WojciechMazur WojciechMazur requested a review from propensive May 6, 2020 14:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant