Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jczuchnowski committed Mar 7, 2021
1 parent 8d45314 commit a0697c5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 69 deletions.
23 changes: 12 additions & 11 deletions core/jvm/src/main/scala/zio/sql/select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait SelectModule { self: ExprModule with TableModule =>

// [F, Repr, A, B <: SelectionSet.Aux[Repr, A]]
def from[A1 <: A](table: Table.Aux[A1]): Read.Select[F, selection.value.ResultTypeRepr, A1] = {
type B0 = SelectionSet.Aux[selection.value.ResultTypeRepr, A]
type B0 = SelectionSet.Aux[selection.value.ResultTypeRepr, A]
val b: B0 = selection.value

Read.Select(Selection[F, A1, B0](b), table, true, Nil)
Expand All @@ -23,10 +23,10 @@ trait SelectModule { self: ExprModule with TableModule =>
val mapper: ResultType => Out

/**
* Maps the [[Read]] query's output to another type by providing a function
* that can transform from the current type to the new type.
*/
def map[Out2](f: Out => Out2): Read.Aux[ResultType, Out2] =
* Maps the [[Read]] query's output to another type by providing a function
* that can transform from the current type to the new type.
*/
def map[Out2](f: Out => Out2): Read.Aux[ResultType, Out2] =
Read.Mapped(self, f)

def to[A, Target](f: A => Target)(implicit ev: Out <:< (A, Unit)): Read[Target] =
Expand Down Expand Up @@ -205,10 +205,10 @@ trait SelectModule { self: ExprModule with TableModule =>
f(a, b, c, d, e, fArg, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
}

def union[Out1 >: Out](that: Read.Aux[ResultType, Out1]): Read.Aux[ResultType, Out1] =
def union[Out1 >: Out](that: Read.Aux[ResultType, Out1]): Read.Aux[ResultType, Out1] =
Read.Union[ResultType, Out1](self, that, true)

def unionAll[Out1 >: Out](that: Read.Aux[ResultType, Out1]): Read.Aux[ResultType, Out1] =
def unionAll[Out1 >: Out](that: Read.Aux[ResultType, Out1]): Read.Aux[ResultType, Out1] =
Read.Union[ResultType, Out1](self, that, false)
}

Expand All @@ -233,7 +233,7 @@ trait SelectModule { self: ExprModule with TableModule =>
offset: Option[Long] = None, //todo don't know how to do this outside of postgres/mysql
limit: Option[Long] = None
) extends Read[Repr] { self =>
type ResultType = Repr
type ResultType = Repr

val mapper: Repr => Repr = identity(_)

Expand Down Expand Up @@ -262,10 +262,11 @@ trait SelectModule { self: ExprModule with TableModule =>
}
}

sealed case class Union[Repr, Out](left: Read.Aux[Repr, Out], right: Read.Aux[Repr, Out], distinct: Boolean) extends Read[Out] {
sealed case class Union[Repr, Out](left: Read.Aux[Repr, Out], right: Read.Aux[Repr, Out], distinct: Boolean)
extends Read[Out] {
type ResultType = Repr

val mapper: ResultType => Out = left.mapper
val mapper: ResultType => Out = left.mapper
}

sealed case class Literal[B: TypeTag](values: Iterable[B]) extends Read[(B, Unit)] {
Expand Down Expand Up @@ -348,7 +349,7 @@ trait SelectModule { self: ExprModule with TableModule =>
}

object SelectionSet {
type Aux[ResultTypeRepr0, -Source] =
type Aux[ResultTypeRepr0, -Source] =
SelectionSet[Source] {
type ResultTypeRepr = ResultTypeRepr0
}
Expand Down
2 changes: 1 addition & 1 deletion jdbc/src/main/scala/zio/sql/JdbcInternalModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ trait JdbcInternalModule { self: Jdbc =>
private[sql] def getColumns(read: Read[_]): Vector[TypeTag[_]] =
read match {
case Read.Mapped(read, _) => getColumns(read)

case Read.Select(selection, _, _, _, _, _, _, _) =>
selection.value.selectionsUntyped.toVector.map(_.asInstanceOf[ColumnSelection[_, _]]).map {
case t @ ColumnSelection.Constant(_, _) => t.typeTag
Expand Down
22 changes: 12 additions & 10 deletions jdbc/src/main/scala/zio/sql/SqlDriverLiveModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ trait SqlDriverLiveModule { self: Jdbc =>

val resultSet = statement.getResultSet()

ZStream.unfoldM(resultSet) { rs =>
if (rs.next()) {
try unsafeExtractRow[read.ResultType](resultSet, schema) match {
case Left(error) => ZIO.fail(error)
case Right(value) => ZIO.succeed(Some((value, rs)))
} catch {
case e: SQLException => ZIO.fail(e)
}
} else ZIO.succeed(None)
}.map(read.mapper)
ZStream
.unfoldM(resultSet) { rs =>
if (rs.next()) {
try unsafeExtractRow[read.ResultType](resultSet, schema) match {
case Left(error) => ZIO.fail(error)
case Right(value) => ZIO.succeed(Some((value, rs)))
} catch {
case e: SQLException => ZIO.fail(e)
}
} else ZIO.succeed(None)
}
.map(read.mapper)

}.refineToOrDie[Exception]
}
Expand Down
6 changes: 1 addition & 5 deletions jdbc/src/main/scala/zio/sql/jdbc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import zio._
import zio.blocking.Blocking
import zio.stream._

trait Jdbc
extends zio.sql.Sql
with TransactionModule
with JdbcInternalModule
with SqlDriverLiveModule {
trait Jdbc extends zio.sql.Sql with TransactionModule with JdbcInternalModule with SqlDriverLiveModule {
trait SqlDriver {
def delete(delete: Delete[_]): IO[Exception, Int]

Expand Down
40 changes: 24 additions & 16 deletions mysql/src/test/scala/zio/sql/mysql/MysqlModuleTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ object MysqlModuleTest extends MysqlRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
})
val testResult = execute(
query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
}
)

val assertion = for {
r <- testResult.runCollect
Expand All @@ -84,10 +86,12 @@ object MysqlModuleTest extends MysqlRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, Boolean, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4, row._5)
})
val testResult = execute(
query
.to[UUID, String, String, Boolean, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4, row._5)
}
)

val assertion = for {
r <- testResult.runCollect
Expand All @@ -112,10 +116,12 @@ object MysqlModuleTest extends MysqlRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
})
val testResult = execute(
query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
}
)

val assertion = for {
r <- testResult.runCollect
Expand Down Expand Up @@ -154,10 +160,12 @@ object MysqlModuleTest extends MysqlRunnableSpec with ShopSchema {
Row("Jose", "Wiggins", LocalDate.parse("2020-01-15"))
)

val result = execute(query
.to[String, String, LocalDate, Row] { case row =>
Row(row._1, row._2, row._3)
})
val result = execute(
query
.to[String, String, LocalDate, Row] { case row =>
Row(row._1, row._2, row._3)
}
)

val assertion = for {
r <- result.runCollect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ trait PostgresModule extends Jdbc { self =>

private[zio] def renderReadImpl(read: self.Read[_])(implicit render: Renderer): Unit =
read match {
case Read.Mapped(read, _) => renderReadImpl(read)
case Read.Mapped(read, _) => renderReadImpl(read)
case read0 @ Read.Select(_, _, _, _, _, _, _, _) =>
object Dummy { type F; type A; type B <: SelectionSet[A] }
val read = read0.asInstanceOf[Read.Select[Dummy.F, Dummy.A, Dummy.B]]
Expand Down
10 changes: 6 additions & 4 deletions postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,12 @@ object FunctionDefSpec extends PostgresRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, Boolean, LocalDate, Customer]((id, fname, lname, verified, dob) =>
Customer(id, fname, lname, verified, dob)
))
val testResult = execute(
query
.to[UUID, String, String, Boolean, LocalDate, Customer]((id, fname, lname, verified, dob) =>
Customer(id, fname, lname, verified, dob)
)
)

val assertion = for {
r <- testResult.runCollect
Expand Down
50 changes: 30 additions & 20 deletions postgres/src/test/scala/zio/sql/postgresql/PostgresModuleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ object PostgresModuleSpec extends PostgresRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, Boolean, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4, row._5)
})
val testResult = execute(
query
.to[UUID, String, String, Boolean, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4, row._5)
}
)

val assertion = for {
r <- testResult.runCollect
Expand Down Expand Up @@ -89,10 +91,12 @@ object PostgresModuleSpec extends PostgresRunnableSpec with ShopSchema {

// execute(query ++ query ++ query ++ query)

val testResult = execute(query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
})
val testResult = execute(
query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
}
)

val assertion = for {
r <- testResult.runCollect
Expand Down Expand Up @@ -174,10 +178,12 @@ object PostgresModuleSpec extends PostgresRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
})
val testResult = execute(
query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
}
)

val assertion = for {
r <- testResult.runCollect
Expand Down Expand Up @@ -235,10 +241,12 @@ object PostgresModuleSpec extends PostgresRunnableSpec with ShopSchema {
Row("Mila", "Paterso", LocalDate.parse("2020-04-30"))
)

val result = execute(query
.to[String, String, LocalDate, Row] { case row =>
Row(row._1, row._2, row._3)
})
val result = execute(
query
.to[String, String, LocalDate, Row] { case row =>
Row(row._1, row._2, row._3)
}
)

val assertion = for {
r <- result.runCollect
Expand All @@ -261,10 +269,12 @@ object PostgresModuleSpec extends PostgresRunnableSpec with ShopSchema {
)
)

val testResult = execute(query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
})
val testResult = execute(
query
.to[UUID, String, String, LocalDate, Customer] { case row =>
Customer(row._1, row._2, row._3, row._4)
}
)

val assertion = for {
r <- testResult.runCollect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ trait SqlServerModule extends Jdbc { self =>
def buildReadString(read: self.Read[_]): Unit =
read match {
case Read.Mapped(read, _) => buildReadString(read)

//todo offset (needs orderBy, must use fetch _instead_ of top)
case read0 @ Read.Select(_, _, _, _, _, _, _, _) =>
object Dummy {
Expand Down

0 comments on commit a0697c5

Please sign in to comment.