-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from narma/add_more_powerful_versions_of_execu…
…te_select_selectFirst add more powerful versions of execute, select and selectFirst
- Loading branch information
Showing
8 changed files
with
82 additions
and
32 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package zio.cassandra.session.cql.query | ||
|
||
import com.datastax.oss.driver.api.core.cql.BoundStatement | ||
import zio.{ Task, ZIO } | ||
import zio.stream.Stream | ||
import zio.cassandra.session.Session | ||
import zio.cassandra.session.cql.codec.Reads | ||
import zio.stream.Stream | ||
import zio.{ Task, ZIO } | ||
|
||
class Query[R: Reads] private[cql] ( | ||
session: Session, | ||
private[cql] val statement: BoundStatement | ||
) { | ||
def config(statement: BoundStatement => BoundStatement) = new Query[R](session, statement(this.statement)) | ||
|
||
def select: Stream[Throwable, R] = session.select(statement).mapChunksZIO { chunk => | ||
def select: Stream[Throwable, R] = session.select(statement).mapChunksZIO { chunk => | ||
chunk.mapZIO(row => ZIO.attempt(Reads[R].read(row))) | ||
} | ||
|
||
def selectFirst: Task[Option[R]] = session.selectFirst(statement).flatMap { | ||
def selectFirst: Task[Option[R]] = session.selectFirst(statement).flatMap { | ||
case None => ZIO.none | ||
case Some(row) => ZIO.attempt(Reads[R].read(row)).map(Some(_)) | ||
} | ||
|
||
def execute: Task[Boolean] = session.execute(statement).map(_.wasApplied) | ||
def execute: Task[Boolean] = session.execute(statement).map(_.wasApplied) | ||
} |
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