Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming functions for doobie and slick with tests #108

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
91f4e39
#99: DBEngine requirement removed from DBSchema. Fixes #99.
salamonpavel Nov 30, 2023
5045b8a
#99: Added DBSchema tests in order to increase code coverage.
salamonpavel Dec 1, 2023
15e9603
tmp code of doobie integration
salamonpavel Dec 2, 2023
264f510
tmp code of doobie integration
salamonpavel Dec 3, 2023
27fac52
tmp code of doobie integration
salamonpavel Dec 4, 2023
c1baa58
it example, status handling (extends not the implementation)
salamonpavel Dec 4, 2023
d12d96a
integration tests
salamonpavel Dec 4, 2023
804035d
integration tests
salamonpavel Dec 4, 2023
d83b274
minors
salamonpavel Dec 5, 2023
491e235
enceladus example fixed
salamonpavel Dec 5, 2023
088065f
build related
salamonpavel Dec 5, 2023
d766c25
alternative constructors
salamonpavel Dec 5, 2023
6f0845e
licences added
salamonpavel Dec 5, 2023
991b446
allow for other types for doobiepgengine
salamonpavel Dec 5, 2023
8bd682e
scaladocs update with respect to generic type of doobiedbengine
salamonpavel Dec 5, 2023
25c42ec
fix formatting
salamonpavel Dec 5, 2023
1b789bb
fix slick part and added cats effect dependency
salamonpavel Dec 5, 2023
a95d958
minors
salamonpavel Dec 5, 2023
f49645c
relax monad requirement from dobiepgengine
salamonpavel Dec 5, 2023
b76801b
minors
salamonpavel Dec 5, 2023
d75b13a
tmp commit
salamonpavel Dec 7, 2023
a3784d7
tmp commit
salamonpavel Dec 7, 2023
bcd8d75
first working version
salamonpavel Dec 7, 2023
3a1f740
working version with status handling available to be defined by clien…
salamonpavel Dec 8, 2023
bd2a21f
StandardQueryStatusHandlingTest
salamonpavel Dec 8, 2023
45e483e
Slick tests refactoring
salamonpavel Dec 8, 2023
6684599
exceptions with docs
salamonpavel Dec 8, 2023
320073e
docs for the supporting classes
salamonpavel Dec 8, 2023
62f62b7
docs for dbfunction and query
salamonpavel Dec 8, 2023
88fce85
docs doobie module
salamonpavel Dec 8, 2023
299dde5
reduce the amount of docs in dbfunction
salamonpavel Dec 8, 2023
0c58a68
minors
salamonpavel Dec 8, 2023
84e30ef
minors
salamonpavel Dec 8, 2023
5f95411
slick function docs
salamonpavel Dec 8, 2023
6cd018d
selectEntry available for both Doobie and Slick modules
salamonpavel Dec 8, 2023
e4a16f7
package renamed, new test for all dates and times common in java, pac…
salamonpavel Dec 9, 2023
742ab50
write times and dates test
salamonpavel Dec 9, 2023
80a72d4
test of unsuccessfull functions with status
salamonpavel Dec 10, 2023
af15e7f
other types reading test
salamonpavel Dec 10, 2023
6711e88
clean-up
salamonpavel Dec 11, 2023
43b60c4
scala 2.13 support
salamonpavel Dec 11, 2023
414cfa0
added missing licenses
salamonpavel Dec 11, 2023
f5db217
github action for 2.13
salamonpavel Dec 11, 2023
03a4a58
clean-up
salamonpavel Dec 11, 2023
852bf6d
doobie module part of coverage reporting
salamonpavel Dec 11, 2023
7695b29
ExplicitNamingRequiredTest
salamonpavel Dec 11, 2023
2799189
DBFunctionFabricTest
salamonpavel Dec 11, 2023
9a2eeea
pr comments addressed
salamonpavel Dec 19, 2023
e3c6e7f
asisnaming test
salamonpavel Dec 19, 2023
b8a4338
downgrade to 1.0.0-RC2 as that's last version with compatible hikari
salamonpavel Dec 20, 2023
94d0212
package object removed - obsolete, meta instances test
salamonpavel Dec 21, 2023
f647caa
docs how to set up things in zio app
salamonpavel Dec 21, 2023
cdb6feb
docs how to set up things in zio app
salamonpavel Dec 21, 2023
712ac82
2.13.11 -> 2.13.12
salamonpavel Dec 22, 2023
6efd571
doc strings refactored
salamonpavel Dec 22, 2023
a8a6860
streaming functions for doobie and slick with tests
salamonpavel Dec 22, 2023
e3bf15a
streaming functions for doobie and slick with tests
salamonpavel Dec 22, 2023
50d7a3a
refactoring of dbfunction
salamonpavel Dec 23, 2023
b542bfc
add licences
salamonpavel Dec 23, 2023
e4e8edc
add licences
salamonpavel Dec 23, 2023
2cbc4f7
scala.language.higherKinds
salamonpavel Dec 23, 2023
bf49ae9
clean up docs
salamonpavel Dec 23, 2023
5d57f4a
fix compilation for scala 2.12
salamonpavel Dec 23, 2023
32e9bf8
fix docs strings
salamonpavel Dec 24, 2023
780a2bd
Added alternative apply to DBStreamingFunction that allows for explic…
salamonpavel Dec 27, 2023
8144e89
Added license headers.
salamonpavel Dec 27, 2023
bc729ea
Change package name
salamonpavel Dec 27, 2023
3fbd923
Merge branch 'feature/doobie-with-status' into feature/doobie-with-st…
salamonpavel Dec 27, 2023
4470c43
Change package name
salamonpavel Dec 27, 2023
7fdf6e4
Change package name
salamonpavel Dec 27, 2023
e8a5607
added Doobie into readme files
salamonpavel Jan 3, 2024
921f0e6
Merge branch 'feature/doobie-with-status' into feature/doobie-with-st…
salamonpavel Jan 3, 2024
0268e9a
merged with parent branch, updated docs
salamonpavel Jan 3, 2024
0a58735
DBFunction made public
salamonpavel Jan 3, 2024
627a554
Merge branch 'master' into feature/doobie-with-status-streaming
salamonpavel Jan 3, 2024
ad36f5f
streaming and slick-streaming modules
salamonpavel Jan 3, 2024
5e45619
jacoco for new modules
salamonpavel Jan 3, 2024
cb1fe0e
minors
salamonpavel Jan 3, 2024
fb92e83
backtics in docs replaced by square brackets in core module
salamonpavel Jan 4, 2024
64dbe90
backtics in docs replaced by square brackets in core module
salamonpavel Jan 4, 2024
05abfd4
docs fix
salamonpavel Jan 4, 2024
6b76004
doobieengine docs fix
salamonpavel Jan 4, 2024
8c7a17a
doobieengine docs fix
salamonpavel Jan 4, 2024
57ec737
doobieengine docs fix
salamonpavel Jan 4, 2024
d14b7d4
doobiequery docs fix
salamonpavel Jan 4, 2024
228177c
doobiefunction, doobiequery docs fix
salamonpavel Jan 4, 2024
2d1fc37
doobiefunction, doobiequery docs fix
salamonpavel Jan 4, 2024
db1d6e5
DoobieStreamingEngine docs fix
salamonpavel Jan 4, 2024
7ce5288
docs fix in slick module
salamonpavel Jan 4, 2024
c70ff3b
docs fix fs2 reference
salamonpavel Jan 4, 2024
c000455
readme update
salamonpavel Jan 4, 2024
2fd7487
alignment
salamonpavel Jan 4, 2024
a70daee
buid.sbt update
salamonpavel Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
fail-fast: false
matrix:
include:
- scala: 2.11.12
scalaShort: "2.11"
overall: 0.0
changed: 80.0
- scala: 2.12.17
scalaShort: "2.12"
overall: 0.0
changed: 80.0
- scala: 2.13.12
scalaShort: "2.13"
overall: 0.0
changed: 80.0
name: Build and test
steps:
- name: Checkout code
Expand All @@ -53,6 +53,7 @@ jobs:
${{ github.workspace }}/core/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/examples/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/slick/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/doobie/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
key: ${{ runner.os }}-${{ matrix.scalaShort }}-${{ hashFiles('**/jacoco.xml') }}

jacoco:
Expand All @@ -62,14 +63,14 @@ jobs:
fail-fast: false
matrix:
include:
- scala: 2.11.12
scalaShort: "2.11"
overall: 0.0
changed: 80.0
- scala: 2.12.17
scalaShort: "2.12"
overall: 0.0
changed: 80.0
- scala: 2.13.12
scalaShort: "2.13"
overall: 0.0
changed: 80.0
name: JaCoCo Code Coverage ${{matrix.scala}}
steps:
- name: Checkout code
Expand All @@ -80,6 +81,7 @@ jobs:
${{ github.workspace }}/core/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/examples/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/slick/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/doobie/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
key: ${{ runner.os }}-${{ matrix.scalaShort }}-${{ hashFiles('**/jacoco.xml') }}
- name: Setup Scala
uses: olafurpg/setup-scala@v10
Expand All @@ -92,6 +94,7 @@ jobs:
paths: >
${{ github.workspace }}/core/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml,
${{ github.workspace }}/slick/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
${{ github.workspace }}/slick/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
${{ github.workspace }}/slick/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml,

${{ github.workspace }}/doobie/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not agree with removing the code coverage fail-check logic - see the comment on the end of the file.
As I know there is no hard merge block enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@miroslavpojer I am not satisfied with this situation either. Unfortunately I couldn't perform merge of previous pull request with this check in place. Let's work together to find a good solution so we can perform tests against a database both locally and within a Github pipeline; for instance with a dockerized Postgres instance.

# examples don't need code coverage - at least not now
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: ${{ matrix.overall }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ dist
test-output
build.log
.bsp
/.bloop/
/.metals/
32 changes: 32 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version = "3.5.3"
runner.dialect = scala213

maxColumn = 120

align.preset = some
align.multiline = false

align.tokens = [
{
code = "<-"
},
{
code = "=>"
owners = [{
regex = "Case"
}]
}
]

indent.main = 2
indent.defnSite = 2

lineEndings = unix

docstrings.blankFirstLine = yes
docstrings.style = AsteriskSpace
docstrings.wrap = no
docstrings.removeEmpty = true

align.openParenDefnSite = false
align.openParenCallSite = false
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,50 @@ Currently, the library is developed with Postgres as the target DB. But the appr

#### Sbt

Import one of the two available module at the moment. Slick module works with Scala Futures. Doobie module works with any effect type (typically IO or ZIO) provided cats effect's Async instance is available.

```scala
libraryDependencies ++= Seq(
"za.co.absa.fa-db" %% "core" % "X.Y.Z",
"za.co.absa.fa-db" %% "slick" % "X.Y.Z"
)
libraryDependencies *= "za.co.absa.fa-db" %% "slick" % "X.Y.Z"
libraryDependencies *= "za.co.absa.fa-db" %% "doobie" % "X.Y.Z"
```

#### Maven

##### Scala 2.11
##### Scala 2.12

Modules:
* Core [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.11)
* Slick [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.11)
* Core [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.12)
* Slick [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.12)
* Doobie [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/doobie_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/doobie_2.12)

```xml
<dependency>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>core_2.11</artifactId>
<version>${latest_version}</version>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>slick_2.12</artifactId>
<version>${latest_version}</version>
</dependency>
<dependency>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>slick_2.11</artifactId>
<version>${latest_version}</version>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>doobie_2.12</artifactId>
<version>${latest_version}</version>
</dependency>
```

### Scala 2.12
### Scala 2.13
Modules:
* Core [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.12)
* Slick [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.12)
* Core [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/core_2.13)
* Slick [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/slick_2.13)
* Doobie [![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/doobie_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/za.co.absa.fa-db/doobie_2.13)

```xml
<dependency>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>core_2.12</artifactId>
<version>${latest_version}</version>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>slick_2.13</artifactId>
<version>${latest_version}</version>
</dependency>
<dependency>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>slick_2.12</artifactId>
<artifactId>doobie_2.13</artifactId>
<version>${latest_version}</version>
</dependency>
```
Expand All @@ -109,13 +111,17 @@ Text about status codes returned from the database function can be found [here](

## Slick module

Slick module is the first (and so far only) implementation of fa-db able to execute. As the name suggests it runs on
[Slick library](https://github.com/slick/slick) and also brings in the [Slickpg library](https://github.com/tminglei/slick-pg/) for extended Postgres type support.
As the name suggests it runs on [Slick library](https://github.com/slick/slick) and also brings in the [Slickpg library](https://github.com/tminglei/slick-pg/) for extended Postgres type support.

It brings:

* `class SlickPgEngine` - implementation of _Core_'s `DBEngine` executing the queries via Slick
* `trait SlickFunction` and `trait SlickFunctionWithStatusSupport` - mix-in traits to use with `FaDbFunction` descendants
* `class SlickPgStreamingEngine` - implementation of _Core_'s `DBStreamingEngine` executing the queries via Slick in a streaming fashion
* `class SlickSingleResultFunction` - abstract class for DB functions returning single result
* `class SlickMultipleResultFunction` - abstract class for DB functions returning sequence of results
* `class SlickOptionalResultFunction` - abstract class for DB functions returning optional result
* `class SlickSingleResultFunctionWithStatus` - abstract class for DB functions with status handling; it requires an implementation of `StatusHandling` to be mixed-in (`StandardStatusHandling` available out-of-the-box)
* `class SlickStreamingResultFunction` - abstract class for DB functions returning sequence of results (fs2.Stream) in a streaming fashion
* `trait FaDbPostgresProfile` - to bring support for Postgres and its extended data types in one class (except JSON, as there are multiple implementations for this data type in _Slick-Pg_)
* `object FaDbPostgresProfile` - instance of the above trait for direct use

Expand All @@ -137,6 +143,21 @@ val hStore: Option[Map[String, String]] = pr.nextHStoreOption
val macAddr: Option[MacAddrString] = pr.nextMacAddrOption
```

## Doobie module

As the name suggests it runs on [Doobie library](https://tpolecat.github.io/doobie/). The main benefit of the module is that it allows to use any effect type (typically IO or ZIO) therefore is more suitable for functional programming. It also brings in the [Doobie-Postgres library](https://tpolecat.github.io/doobie/docs/14-PostgreSQL.html) for extended Postgres type support.

It brings:

* `class DoobieEngine` - implementation of _Core_'s `DBEngine` executing the queries via Doobie. The class is type parameterized with the effect type.
* `class DoobieStreamingEngine` - implementation of _Core_'s `DBStreamingEngine` executing the queries via Doobie in a streaming fashion. The class is type parameterized with the effect type.
* `class DoobieSingleResultFunction` - abstract class for DB functions returning single result
* `class DoobieMultipleResultFunction` - abstract class for DB functions returning sequence of results
* `class DoobieOptionalResultFunction` - abstract class for DB functions returning optional result
* `class DoobieSingleResultFunctionWithStatus` - abstract class for DB functions with status handling; it requires an implementation of `StatusHandling` to be mixed-in (`StandardStatusHandling` available out-of-the-box)
* `class DoobieStreamingResultFunction` - abstract class for DB functions returning sequence of results (fs2.Stream) in a streaming fashion
Since Doobie also interoperates with ZIO, there is an example of how a database connection can be properly established within a ZIO application. Please see [this file](doobie/zio-setup.md) for more details.

## Testing

### How to generate unit tests code coverage report
Expand Down
22 changes: 18 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import com.github.sbt.jacoco.report.JacocoReportSettings

ThisBuild / organization := "za.co.absa.fa-db"

lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.17"
lazy val scala213 = "2.13.12"

ThisBuild / scalaVersion := scala211
ThisBuild / crossScalaVersions := Seq(scala211, scala212)
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := Seq(scala212, scala213)

ThisBuild / versionScheme := Some("early-semver")

Expand All @@ -49,7 +49,7 @@ lazy val commonJacocoExcludes: Seq[String] = Seq(
)

lazy val parent = (project in file("."))
.aggregate(faDbCore, faDBSlick, faDBExamples)
.aggregate(faDbCore, faDBSlick, faDBDoobie, faDBExamples)
.settings(
name := "root",
libraryDependencies ++= rootDependencies(scalaVersion.value),
Expand Down Expand Up @@ -88,6 +88,20 @@ lazy val faDBSlick = (project in file("slick"))
jacocoExcludes := commonJacocoExcludes
)

lazy val faDBDoobie = (project in file("doobie"))
.configs(IntegrationTest)
.settings(
name := "doobie",
libraryDependencies ++= doobieDependencies(scalaVersion.value),
javacOptions ++= commonJavacOptions,
scalacOptions ++= commonScalacOptions,
Defaults.itSettings,
).dependsOn(faDbCore)
.settings(
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"doobie:slick Jacoco Report - scala:${scalaVersion.value}"),
jacocoExcludes := commonJacocoExcludes
)

lazy val faDBExamples = (project in file("examples"))
.configs(IntegrationTest)
.settings(
Expand Down
82 changes: 47 additions & 35 deletions core/src/main/scala/za/co/absa/fadb/DBEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,69 @@

package za.co.absa.fadb

import scala.concurrent.{ExecutionContext, Future}
import cats.Monad
import cats.implicits.toFunctorOps
import za.co.absa.fadb.exceptions.StatusException

import scala.language.higherKinds

/**
* A basis to represent a database executor
*/
trait DBEngine {
* `DBEngine` is an abstract class that represents a database engine.
* It provides methods to execute queries and fetch results from a database.
* @tparam F - The type of the context in which the database queries are executed.
*/
abstract class DBEngine[F[_]: Monad] {

/**
* A type representing the (SQL) query within the engine
* @tparam T - the return type of the query
*/
type QueryType[T] <: Query[T]
* A type representing the (SQL) query within the engine
* @tparam R - the return type of the query
*/
type QueryType[R] <: Query[R]
type QueryWithStatusType[R] <: QueryWithStatus[_, _, R]

implicit val executor: ExecutionContext
/**
* The actual query executioner of the queries of the engine
* @param query - the query to execute
* @tparam R - return type of the query
* @return - sequence of the results of database query
*/
protected def run[R](query: QueryType[R]): F[Seq[R]]

/**
* The actual query executioner of the queries of the engine
* @param query - the query to execute
* @tparam R - return the of the query
* @return - sequence of the results of database query
*/
protected def run[R](query: QueryType[R]): Future[Seq[R]]
* The actual query executioner of the queries of the engine with status
* @param query - the query to execute
* @tparam R - return type of the query
* @return - result of database query with status
*/
def runWithStatus[R](query: QueryWithStatusType[R]): F[Either[StatusException, R]]

/**
* Public method to execute when query is expected to return multiple results
* @param query - the query to execute
* @tparam R - return the of the query
* @return - sequence of the results of database query
*/
def fetchAll[R](query: QueryType[R]): Future[Seq[R]] = run(query)
* Public method to execute when query is expected to return multiple results
* @param query - the query to execute
* @tparam R - return type of the query
* @return - sequence of the results of database query
*/
def fetchAll[R](query: QueryType[R]): F[Seq[R]] = {
run(query)
}

/**
* Public method to execute when query is expected to return exactly one row
* @param query - the query to execute
* @tparam R - return the of the query
* @return - sequence of the results of database query
*/
def fetchHead[R](query: QueryType[R]): Future[R] = {
* Public method to execute when query is expected to return exactly one row
* @param query - the query to execute
* @tparam R - return type of the query
* @return - sequence of the results of database query
*/
def fetchHead[R](query: QueryType[R]): F[R] = {
run(query).map(_.head)
}

/**
* Public method to execute when query is expected to return one or no results
* @param query - the query to execute
* @tparam R - return the of the query
* @return - sequence of the results of database query
*/

def fetchHeadOption[R](query: QueryType[R]): Future[Option[R]] = {
* Public method to execute when query is expected to return one or no results
* @param query - the query to execute
* @tparam R - return type of the query
* @return - sequence of the results of database query
*/
def fetchHeadOption[R](query: QueryType[R]): F[Option[R]] = {
run(query).map(_.headOption)
}
}

Loading
Loading