-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(dsl): Support refresh parameter (#33)
- Loading branch information
Showing
5 changed files
with
157 additions
and
74 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
37 changes: 37 additions & 0 deletions
37
modules/library/src/main/scala/zio/elasticsearch/Refresh.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package zio.elasticsearch | ||
|
||
import zio.elasticsearch.ElasticRequest.{CreateOrUpdateRequest, CreateRequest, DeleteByIdRequest, Map} | ||
import zio.elasticsearch.ElasticRequestType.{Create, DeleteById, Upsert} | ||
|
||
object Refresh { | ||
|
||
trait WithRefresh[ERT <: ElasticRequestType] { | ||
def withRefresh[A](request: ElasticRequest[A, ERT], value: Boolean): ElasticRequest[A, ERT] | ||
} | ||
|
||
object WithRefresh { | ||
implicit val createWithRefresh: WithRefresh[Create] = new WithRefresh[Create] { | ||
def withRefresh[A](request: ElasticRequest[A, Create], value: Boolean): ElasticRequest[A, Create] = | ||
request match { | ||
case Map(r, mapper) => Map(withRefresh(r, value), mapper) | ||
case r: CreateRequest => r.copy(refresh = value) | ||
} | ||
} | ||
|
||
implicit val deleteByIdWithRefresh: WithRefresh[DeleteById] = new WithRefresh[DeleteById] { | ||
def withRefresh[A](request: ElasticRequest[A, DeleteById], value: Boolean): ElasticRequest[A, DeleteById] = | ||
request match { | ||
case Map(r, mapper) => Map(withRefresh(r, value), mapper) | ||
case r: DeleteByIdRequest => r.copy(refresh = value) | ||
} | ||
} | ||
|
||
implicit val upsertWithRefresh: WithRefresh[Upsert] = new WithRefresh[Upsert] { | ||
def withRefresh[A](request: ElasticRequest[A, Upsert], value: Boolean): ElasticRequest[A, Upsert] = | ||
request match { | ||
case Map(r, mapper) => Map(withRefresh(r, value), mapper) | ||
case r: CreateOrUpdateRequest => r.copy(refresh = value) | ||
} | ||
} | ||
} | ||
} |