Skip to content

Commit

Permalink
Merge branch 'master' into update/sbt-1.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jczuchnowski authored Jul 24, 2023
2 parents a87ccfd + 8a5aa8b commit 85208c5
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.10
9bcedec20a4fc7adedce8aea4921c05b0c7acfa4
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI

env:
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g
JVM_OPTS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g -Xss4m
JVM_OPTS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g -Xss4m

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.9"
version = "3.7.10"
maxColumn = 120
align.preset = most
continuationIndent.defnSite = 2
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck"
val zioVersion = "2.0.6"
val zioSchemaVersion = "0.4.2"
val testcontainersVersion = "1.17.6"
val testcontainersScalaVersion = "0.40.11"
val testcontainersScalaVersion = "0.40.17"
val logbackVersion = "1.2.11"

lazy val root = project
Expand Down
26 changes: 0 additions & 26 deletions core/shared/src/test/scala/zio-sql/HelloWorldSpec.scala

This file was deleted.

1 change: 1 addition & 0 deletions jdbc/src/main/scala/zio/sql/JdbcInternalModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait JdbcInternalModule { self: Jdbc =>
else
try {
val value = decoder
if (resultSet.wasNull()) return Right(null.asInstanceOf[A])

value match {
case Some(value) => Right(value)
Expand Down
2 changes: 1 addition & 1 deletion macros/src/main/scala-2/zio/sql/macros/insertlike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object InsertLike {
F,
ColsRepr,
AllColumnIdentities,
Z,
Z
] = macro createInsertLikeImpl[F, ColsRepr, AllColumnIdentities, Z]

def createInsertLikeImpl[
Expand Down
7 changes: 3 additions & 4 deletions macros/src/main/scala-3/zio/sql/macros/groupbylike.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package zio.sql.macros


sealed trait GroupByLike[All, Grouped]

object GroupByLike {

final case class CanBeGrouped[All, Grouped]() extends GroupByLike[All, Grouped]
final case class CanBeGrouped[All, Grouped]() extends GroupByLike[All, Grouped]

implicit def createGroupByLike[All, Grouped]: GroupByLike[All, Grouped] = CanBeGrouped[All, Grouped]()
}
implicit def createGroupByLike[All, Grouped]: GroupByLike[All, Grouped] = CanBeGrouped[All, Grouped]()
}
7 changes: 4 additions & 3 deletions macros/src/main/scala-3/zio/sql/macros/havinglike.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package zio.sql.macros
package zio.sql.macros

sealed trait HavingIsSound[AllF, GroupByF, HavingF]

object HavingIsSound {

final case class HavingCanBeCalled[AllF, GroupByF, HavingF]() extends HavingIsSound[AllF, GroupByF, HavingF]

implicit def materializeHavingIsSound[AllF, GroupByF, HavingF]: HavingIsSound[AllF, GroupByF, HavingF] = HavingCanBeCalled[AllF, GroupByF, HavingF]()
implicit def materializeHavingIsSound[AllF, GroupByF, HavingF]: HavingIsSound[AllF, GroupByF, HavingF] =
HavingCanBeCalled[AllF, GroupByF, HavingF]()

}
}
2 changes: 1 addition & 1 deletion macros/src/main/scala-3/zio/sql/macros/insertlike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ object InsertLike {
F,
ColsRepr,
AllColumnIdentities,
Z,
Z
] = CanBeInserted[F, ColsRepr, AllColumnIdentities, Z]()
}
3 changes: 1 addition & 2 deletions macros/src/main/scala-3/zio/sql/macros/normalizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ object Normalizer {
// override type Out = Out2
// }

implicit def createNormalizer[In]: Normalizer[In] = {
implicit def createNormalizer[In]: Normalizer[In] =
new Normalizer[In] {}
}

}
11 changes: 5 additions & 6 deletions macros/src/main/scala-3/zio/sql/macros/notliteral.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package zio.sql.macros
package zio.sql.macros

sealed trait IsNotLiteral[F]

object IsNotLiteral {

final case class FIsNotLiteral[F]() extends IsNotLiteral[F]
final case class FIsNotLiteral[F]() extends IsNotLiteral[F]

implicit def materializeIsNotLiteral[F]: IsNotLiteral[F] = {
FIsNotLiteral[F]()
}
}
implicit def materializeIsNotLiteral[F]: IsNotLiteral[F] =
FIsNotLiteral[F]()
}
3 changes: 1 addition & 2 deletions macros/src/main/scala-3/zio/sql/macros/tablelike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ object TableSchema {

final case class Compatible[T]() extends TableSchema[T]


implicit def materializeTableSchema[T]: TableSchema[T] = Compatible[T]()

}
}
6 changes: 3 additions & 3 deletions macros/src/main/scala-3/zio/sql/macros/wherelike.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package zio.sql.macros
package zio.sql.macros

sealed trait WhereIsSound[WhereF, GroupByF]

object WhereIsSound {
final case class WhereCanBeCalled[WhereF, GroupByF]() extends WhereIsSound[WhereF, GroupByF]

implicit def materializeWhereIsSound[WhereF, GroupByF]: WhereIsSound[WhereF, GroupByF] =
implicit def materializeWhereIsSound[WhereF, GroupByF]: WhereIsSound[WhereF, GroupByF] =
WhereCanBeCalled[WhereF, GroupByF]()
}
}
3 changes: 2 additions & 1 deletion oracle/src/main/scala/zio/sql/oracle/OracleSqlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait OracleSqlModule extends Sql { self =>
}

object OracleFunctionDef {
val Sind = FunctionDef[Double, Double](FunctionName("sind"))
val Ltrim2 = FunctionDef[(String, String), String](FunctionName("ltrim"))
val Rtrim2 = FunctionDef[(String, String), String](FunctionName("rtrim"))
}
}
10 changes: 2 additions & 8 deletions oracle/src/test/scala/zio/sql/oracle/CommonFunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ import zio.Cause
import zio.stream.ZStream
import zio.test.Assertion._
import zio.test._
import zio.schema.DeriveSchema
import zio.sql.expr.FunctionDef.{ CharLength => _, _ }
import zio.sql.table._

object CommonFunctionDefSpec extends OracleRunnableSpec with ShopSchema {
object CommonFunctionDefSpec extends OracleRunnableSpec with ShopSchema with DualSchema {
import Customers._

case class Dual(dummy: String)
implicit val dummySchema = DeriveSchema.gen[Dual]
val dual = Table.defineTable[Dual]
val dommy = dual.columns
import Dual._

private def collectAndCompare[R, E](
expected: Seq[String],
Expand Down
25 changes: 25 additions & 0 deletions oracle/src/test/scala/zio/sql/oracle/CustomFunctionDefSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package zio.sql.oracle

import zio.test.Assertion._
import zio.test.TestAspect.timeout
import zio.test._
import zio._

object CustomFunctionDefSpec extends OracleRunnableSpec with DualSchema {
import OracleFunctionDef._

import Dual._

override def specLayered = suite("Oracle FunctionDef")(
test("ltrim2") {
assertZIO(execute(select(Ltrim2("$## foo$#", "#$")).from(dual)).runHead.some)(
equalTo(" foo$#")
)
},
test("rtrim2") {
assertZIO(execute(select(Rtrim2("$#foo $##", "#$")).from(dual)).runHead.some)(
equalTo("$#foo ")
)
}
) @@ timeout(5.minutes)
}
14 changes: 14 additions & 0 deletions oracle/src/test/scala/zio/sql/oracle/DualSchema.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zio.sql.oracle

import zio.schema.DeriveSchema
import zio.sql.table._

trait DualSchema {
object Dual {
case class Dual(dummy: String)

implicit val dummySchema = DeriveSchema.gen[Dual]
val dual = Table.defineTable[Dual]
val dummy = dual.columns
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ trait PostgresRenderModule extends PostgresSqlModule { self =>
case _ => ()
}

private[zio] def quoted(name: String): String = "\"" + name + "\""
private[zio] def quoted(name: String): String =
name.split('.').map("\"" + _ + "\"").mkString(".")

private[zio] def renderExpr[A, B](expr: Expr[_, A, B])(implicit render: Renderer): Unit = expr match {
case Expr.Subselect(subselect) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ trait PostgresSqlModule extends Sql { self =>
val LocaltimestampWithPrecision = FunctionDef[Int, Instant](FunctionName("localtimestamp"))
val LocaltimeWithPrecision = FunctionDef[Int, LocalTime](FunctionName("localtime"))
val LPad = FunctionDef[(String, Int, String), String](FunctionName("lpad"))
val Ltrim2 = FunctionDef[(String, String), String](FunctionName("ltrim"))
val MakeDate = FunctionDef[(Int, Int, Int), LocalDate](FunctionName("make_date"))
val MakeInterval = FunctionDef[Interval, Interval](FunctionName("make_interval"))
val MakeTime = FunctionDef[(Int, Int, Double), LocalTime](FunctionName("make_time"))
Expand All @@ -271,6 +272,7 @@ trait PostgresSqlModule extends Sql { self =>
val Reverse = FunctionDef[String, String](FunctionName("reverse"))
val Right = FunctionDef[(String, Int), String](FunctionName("right"))
val RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad"))
val Rtrim2 = FunctionDef[(String, String), String](FunctionName("rtrim"))
val SetSeed = FunctionDef[Double, Unit](FunctionName("setseed"))
val Sind = FunctionDef[Double, Double](FunctionName("sind"))
val SplitPart = FunctionDef[(String, String, Int), String](FunctionName("split_part"))
Expand Down
8 changes: 8 additions & 0 deletions postgres/src/test/resources/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ ALTER TABLE metro_line ADD CONSTRAINT metro_line_id PRIMARY KEY(id);
ALTER TABLE metro_line ADD CONSTRAINT metro_line_system_fk
FOREIGN KEY(system_id) REFERENCES metro_system(id) ON DELETE CASCADE ON UPDATE CASCADE;

create table movies
(
id int not null primary key,
rating int
);

insert into "movies" ("id", "rating") values (1, null);

insert into "customers"
("id", "first_name", "last_name", "verified", "dob", "created_timestamp_string", "created_timestamp")
values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,17 @@ object CustomFunctionDefSpec extends PostgresRunnableSpec with DbSchema {
val testResult = execute(query)
collectAndCompare(expected, testResult)
}
)
),
test("ltrim2") {
assertZIO(execute(select(Ltrim2("$## foo$#", "#$"))).runHead.some)(
equalTo(" foo$#")
)
},
test("rtrim2") {
assertZIO(execute(select(Rtrim2("$#foo $##", "#$"))).runHead.some)(
equalTo("$#foo ")
)
}
),
test("repeat") {
assertZIO(execute(select(Repeat("Zio", 3))).runHead.some)(equalTo("ZioZioZio"))
Expand Down
13 changes: 13 additions & 0 deletions postgres/src/test/scala/zio/sql/postgresql/DbSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,17 @@ trait DbSchema extends PostgresJdbcModule { self =>

val (personsId, personsName, birthDate) = persons.columns
}

object MoviesSchema {

case class Movies(id: Int, rating: Option[Int])

implicit val moviesSchema = DeriveSchema.gen[Movies]

val movies = Table.defineTableSmart[Movies]

val (id, rating) = movies.columns

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package zio.sql.postgresql
import java.math.BigDecimal
import java.time._
import java.util.UUID

import zio._
import zio.schema._
import zio.test._
Expand All @@ -12,6 +11,7 @@ import zio.test.TestAspect._
import zio.sql.expr.AggregationDef._
import zio.sql.expr._
import zio.sql.select._

import scala.language.postfixOps

object PostgresSqlModuleSpec extends PostgresRunnableSpec with DbSchema {
Expand Down Expand Up @@ -703,6 +703,24 @@ object PostgresSqlModuleSpec extends PostgresRunnableSpec with DbSchema {
orders <- execute(allOrders).runCollect
products <- execute(allProducts).runCollect
} yield assertTrue(customers.length == 2) && assertTrue(orders.length == 35) && assertTrue(products.length == 10)
},
test("Select null int value as None Option") {
val movieColumns = MoviesSchema.id ++ MoviesSchema.rating
val selectStmt = select(movieColumns).from(MoviesSchema.movies).where(MoviesSchema.id === 1)
val selectResult = execute(selectStmt.to((MoviesSchema.Movies.apply _).tupled)).runCollect

for {
movies <- selectResult
} yield assert(movies.toList)(
equalTo(
List(
MoviesSchema.Movies(
id = 1,
rating = None
)
)
)
)
}
) @@ sequential
}
2 changes: 1 addition & 1 deletion project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BuildInfoKeys._
import scalafix.sbt.ScalafixPlugin.autoImport.scalafixSemanticdb

object BuildHelper {
val SilencerVersion = "1.7.12"
val SilencerVersion = "1.7.13"
val Scala212 = "2.12.17"
val Scala213 = "2.13.10"
val ScalaDotty = "3.2.1"
Expand Down
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.12.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.6")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.3")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.9")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.9")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
Expand Down

0 comments on commit 85208c5

Please sign in to comment.