Skip to content

Commit

Permalink
Fix ZTransaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jczuchnowski committed Mar 12, 2021
2 parents 44d463d + 6dc80a1 commit c93a9d5
Show file tree
Hide file tree
Showing 45 changed files with 1,826 additions and 1,062 deletions.
36 changes: 7 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name: CI

on:
pull_request:
branches: ['*']
push:
branches: ['master']
tags: ['v*']
release:
types:
- published

jobs:
lint:
Expand All @@ -20,14 +21,7 @@ jobs:
- name: Setup Scala and Java
uses: olafurpg/setup-scala@v10
- name: Cache scala dependencies
uses: actions/cache@v2
with:
path: |
~/.ivy2/cache
~/.sbt
~/.m2
~/.cache
key: sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
uses: coursier/cache-action@v5
- name: Lint code
run: sbt check

Expand All @@ -37,7 +31,7 @@ jobs:
fail-fast: false
matrix:
java: ['[email protected]', '[email protected]']
scala: ['2.12.12', '2.13.3']
scala: ['2.12.13', '2.13.5']
steps:
- name: Checkout current branch
uses: actions/[email protected]
Expand All @@ -48,14 +42,7 @@ jobs:
with:
java-version: ${{ matrix.java }}
- name: Cache scala dependencies
uses: actions/cache@v2
with:
path: |
~/.ivy2/cache
~/.sbt
~/.m2
~/.cache
key: sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
uses: coursier/cache-action@v5
- name: Run tests
run: sbt ++${{ matrix.scala }}! test

Expand All @@ -71,16 +58,7 @@ jobs:
- name: Setup Scala and Java
uses: olafurpg/setup-scala@v10
- name: Cache scala dependencies
uses: actions/cache@v2
with:
path: |
~/.ivy2/cache
~/.sbt
~/.m2
~/.cache
key: sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- name: Setup GPG
uses: olafurpg/setup-gpg@v3
uses: coursier/cache-action@v5
- name: Release artifacts
run: sbt ci-release
env:
Expand Down
50 changes: 0 additions & 50 deletions .github/workflows/clean.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ project/plugins/project/
metals.sbt
.bloop/
project/secret
null

# mdoc
website/node_modules
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Running Reads | :heavy_check_mark:
Running Deletes | :heavy_check_mark:
Running Updates | :heavy_check_mark:
Running Inserts |
Transactions |
Transactions | :white_check_mark:
Connection pool |

#### Db-specific features:
Expand Down
26 changes: 13 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ addCommandAlias("fmtOnce", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("fmt", "fmtOnce;fmtOnce")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val zioVersion = "1.0.3"
val testcontainersVersion = "1.15.1"
val testcontainersScalaVersion = "1.0.0-alpha1"
val zioVersion = "1.0.4-2"
val testcontainersVersion = "1.15.2"
val testcontainersScalaVersion = "0.39.3"

lazy val startPostgres = taskKey[Unit]("Start up Postgres")
startPostgres := startService(Database.Postgres, streams.value)
Expand Down Expand Up @@ -160,7 +160,7 @@ lazy val mysql = project
"org.testcontainers" % "database-commons" % testcontainersVersion % Test,
"org.testcontainers" % "jdbc" % testcontainersVersion % Test,
"org.testcontainers" % "mysql" % testcontainersVersion % Test,
"mysql" % "mysql-connector-java" % "8.0.22" % Test,
"mysql" % "mysql-connector-java" % "8.0.23" % Test,
"com.dimafeng" %% "testcontainers-scala-mysql" % testcontainersScalaVersion % Test
)
)
Expand All @@ -175,14 +175,14 @@ lazy val oracle = project
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"org.testcontainers" % "testcontainers" % testcontainersVersion % Test,
"org.testcontainers" % "database-commons" % testcontainersVersion % Test,
"org.testcontainers" % "oracle-xe" % testcontainersVersion % Test,
"org.testcontainers" % "jdbc" % testcontainersVersion % Test,
"com.oracle.database.jdbc" % "ojdbc8" % "19.9.0.0" % Test,
"com.dimafeng" %% "testcontainers-scala-oracle-xe" % "0.38.8" % Test
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"org.testcontainers" % "testcontainers" % testcontainersVersion % Test,
"org.testcontainers" % "database-commons" % testcontainersVersion % Test,
"org.testcontainers" % "oracle-xe" % testcontainersVersion % Test,
"org.testcontainers" % "jdbc" % testcontainersVersion % Test,
"com.oracle.database.jdbc" % "ojdbc8" % "21.1.0.0" % Test,
"com.dimafeng" %% "testcontainers-scala-oracle-xe" % testcontainersScalaVersion % Test
)
)
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -202,7 +202,7 @@ lazy val postgres = project
"org.testcontainers" % "database-commons" % testcontainersVersion % Test,
"org.testcontainers" % "postgresql" % testcontainersVersion % Test,
"org.testcontainers" % "jdbc" % testcontainersVersion % Test,
"org.postgresql" % "postgresql" % "42.2.18" % Test,
"org.postgresql" % "postgresql" % "42.2.19" % Compile,
"com.dimafeng" %% "testcontainers-scala-postgresql" % testcontainersScalaVersion % Test
)
)
Expand Down
2 changes: 1 addition & 1 deletion core/jvm/src/main/scala/zio/sql/Sql.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait Sql extends SelectModule with DeleteModule with UpdateModule with ExprModu
def select[F, A, B <: SelectionSet[A]](selection: Selection[F, A, B]): SelectBuilder[F, A, B] =
SelectBuilder(selection)

def deleteFrom[F[_], A, B](table: Table.Source.Aux[F, A, B]): Delete[A] = Delete(table, true)
def deleteFrom[T <: Table](table: T): Delete[table.TableType] = Delete(table, true)

def update[A](table: Table.Aux[A]): UpdateBuilder[A] = UpdateBuilder(table)

Expand Down
113 changes: 113 additions & 0 deletions core/jvm/src/main/scala/zio/sql/expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package zio.sql

import java.time._

import com.github.ghik.silencer.silent

import scala.language.implicitConversions

trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
Expand Down Expand Up @@ -203,6 +205,53 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
) extends InvariantExpr[Features.Union[F1, Features.Union[F2, Features.Union[F3, F4]]], A, Z] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}

sealed case class FunctionCall5[F1, F2, F3, F4, F5, A, B, C, D, E, F, Z: TypeTag](
param1: Expr[F1, A, B],
param2: Expr[F2, A, C],
param3: Expr[F3, A, D],
param4: Expr[F4, A, E],
param5: Expr[F5, A, F],
function: FunctionDef[(B, C, D, E, F), Z]
) extends InvariantExpr[Features.Union[F1, Features.Union[F2, Features.Union[F3, Features.Union[F4, F5]]]], A, Z] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}

sealed case class FunctionCall6[F1, F2, F3, F4, F5, F6, A, B, C, D, E, F, G, Z: TypeTag](
param1: Expr[F1, A, B],
param2: Expr[F2, A, C],
param3: Expr[F3, A, D],
param4: Expr[F4, A, E],
param5: Expr[F5, A, F],
param6: Expr[F6, A, G],
function: FunctionDef[(B, C, D, E, F, G), Z]
) extends InvariantExpr[
Features.Union[F1, Features.Union[F2, Features.Union[F3, Features.Union[F4, Features.Union[F5, F6]]]]],
A,
Z
] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}

sealed case class FunctionCall7[F1, F2, F3, F4, F5, F6, F7, A, B, C, D, E, F, G, H, Z: TypeTag](
param1: Expr[F1, A, B],
param2: Expr[F2, A, C],
param3: Expr[F3, A, D],
param4: Expr[F4, A, E],
param5: Expr[F5, A, F],
param6: Expr[F6, A, G],
param7: Expr[F7, A, H],
function: FunctionDef[(B, C, D, E, F, G, H), Z]
) extends InvariantExpr[
Features.Union[
F1,
Features.Union[F2, Features.Union[F3, Features.Union[F4, Features.Union[F5, Features.Union[F6, F7]]]]]
],
A,
Z
] {
def typeTag: TypeTag[Z] = implicitly[TypeTag[Z]]
}
}

sealed case class AggregationDef[-A, +B](name: FunctionName) { self =>
Expand Down Expand Up @@ -257,6 +306,69 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
self.narrow[(P1, P2, P3, P4)]: FunctionDef[(P1, P2, P3, P4), B1]
)

def apply[F1, F2, F3, F4, F5, Source, P1, P2, P3, P4, P5, B1 >: B](
param1: Expr[F1, Source, P1],
param2: Expr[F2, Source, P2],
param3: Expr[F3, Source, P3],
param4: Expr[F4, Source, P4],
param5: Expr[F5, Source, P5]
)(implicit
ev: (P1, P2, P3, P4, P5) <:< A,
typeTag: TypeTag[B1]
): Expr[F1 :||: F2 :||: F3 :||: F4 :||: F5, Source, B1] =
Expr.FunctionCall5(
param1,
param2,
param3,
param4,
param5,
self.narrow[(P1, P2, P3, P4, P5)]: FunctionDef[(P1, P2, P3, P4, P5), B1]
)

def apply[F1, F2, F3, F4, F5, F6, Source, P1, P2, P3, P4, P5, P6, B1 >: B](
param1: Expr[F1, Source, P1],
param2: Expr[F2, Source, P2],
param3: Expr[F3, Source, P3],
param4: Expr[F4, Source, P4],
param5: Expr[F5, Source, P5],
param6: Expr[F6, Source, P6]
)(implicit
ev: (P1, P2, P3, P4, P5, P6) <:< A,
typeTag: TypeTag[B1]
): Expr[F1 :||: F2 :||: F3 :||: F4 :||: F5 :||: F6, Source, B1] =
Expr.FunctionCall6(
param1,
param2,
param3,
param4,
param5,
param6,
self.narrow[(P1, P2, P3, P4, P5, P6)]: FunctionDef[(P1, P2, P3, P4, P5, P6), B1]
)

def apply[F1, F2, F3, F4, F5, F6, F7, Source, P1, P2, P3, P4, P5, P6, P7, B1 >: B](
param1: Expr[F1, Source, P1],
param2: Expr[F2, Source, P2],
param3: Expr[F3, Source, P3],
param4: Expr[F4, Source, P4],
param5: Expr[F5, Source, P5],
param6: Expr[F6, Source, P6],
param7: Expr[F7, Source, P7]
)(implicit
ev: (P1, P2, P3, P4, P5, P6, P7) <:< A,
typeTag: TypeTag[B1]
): Expr[F1 :||: F2 :||: F3 :||: F4 :||: F5 :||: F6 :||: F7, Source, B1] =
Expr.FunctionCall7(
param1,
param2,
param3,
param4,
param5,
param6,
param7,
self.narrow[(P1, P2, P3, P4, P5, P6, P7)]: FunctionDef[(P1, P2, P3, P4, P5, P6, P7), B1]
)

def narrow[C](implicit ev: C <:< A): FunctionDef[C, B] = {
val _ = ev
self.asInstanceOf[FunctionDef[C, B]]
Expand Down Expand Up @@ -321,6 +433,7 @@ trait ExprModule extends NewtypesModule with FeaturesModule with OpsModule {
object Set {
type Aux[F, -A, Value0] = Set[F, A] { type Value = Value0 }

@silent
def apply[F: Features.IsSource, A, Value0: TypeTag](
lhs0: Expr[F, A, Value0],
rhs0: Expr[_, A, Value0]
Expand Down
3 changes: 3 additions & 0 deletions core/jvm/src/main/scala/zio/sql/features.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package zio.sql

import com.github.ghik.silencer.silent

import scala.annotation.implicitNotFound

trait FeaturesModule {
Expand All @@ -20,6 +22,7 @@ trait FeaturesModule {

implicit def AggregatedIsAggregated[A]: IsAggregated[Aggregated[A]] = new IsAggregated[Aggregated[A]] {}

@silent
implicit def UnionIsAggregated[A: IsAggregated, B: IsAggregated]: IsAggregated[Union[A, B]] =
new IsAggregated[Union[A, B]] {}
}
Expand Down
2 changes: 1 addition & 1 deletion core/jvm/src/main/scala/zio/sql/ops.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.sql

trait OpsModule extends TypeTagModule {
trait OpsModule extends TypeTagModule { self: SelectModule =>

sealed trait Operator {
val symbol: String
Expand Down
Loading

0 comments on commit c93a9d5

Please sign in to comment.