Skip to content

Commit

Permalink
compilation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sviezypan committed Nov 17, 2022
1 parent 02076b2 commit d216f67
Show file tree
Hide file tree
Showing 26 changed files with 447 additions and 606 deletions.
28 changes: 28 additions & 0 deletions core/jvm/src/main/scala/zio/sql/insertutils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,34 @@ trait InsertUtilsModule { self: FeaturesModule =>

// TODO fix scalafmt error - it fails in caseClass20 and above because of - `Search state exploded`
// https://scalameta.org/scalafmt/docs/known-issues.html#deeply-nested-code

// implicit def caseClass20[
// F, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z, ColsRepr, AllColumnIdentities, Source, Identity1, Identity2, Identity3, Identity4, Identity5, Identity6, Identity7, Identity8, Identity9, Identity10, Identity11, Identity12, Identity13, Identity14, Identity15, Identity16, Identity17, Identity18, Identity19, Identity20
// ](implicit
// ccSchema: Schema.CaseClass20[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z],
// ev: ColsRepr <:< (A1, (A2, (A3, (A4, (A5, (A6, (A7, (A8, (A9, (A10, (A11, (A12, (A13, (A14, (A15, (A16, (A17, (A18, (A19, (A20, Unit)))))))))))))))))))),
// ev2: F <:< Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Source[Identity1, Source], Features.Source[Identity2, Source]], Features.Source[Identity3, Source]], Features.Source[Identity4, Source]], Features.Source[Identity5, Source]], Features.Source[Identity6, Source]], Features.Source[Identity7, Source]], Features.Source[Identity8, Source]], Features.Source[Identity9, Source]], Features.Source[Identity10, Source]], Features.Source[Identity11, Source]], Features.Source[Identity12, Source]], Features.Source[Identity13, Source]], Features.Source[Identity14, Source]], Features.Source[Identity15, Source]], Features.Source[Identity16, Source]], Features.Source[Identity17, Source]], Features.Source[Identity18, Source]], Features.Source[Identity19, Source]], Features.Source[Identity20, Source]],
// ev3: AllColumnIdentities <:< Identity1 with Identity2 with Identity3 with Identity4 with Identity5 with Identity6 with Identity7 with Identity8 with Identity9 with Identity10 with Identity11 with Identity12 with Identity13 with Identity14 with Identity15 with Identity16 with Identity17 with Identity18 with Identity19 with Identity20
// ): SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] =
// new SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] {}

// implicit def caseClass21[F, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z, ColsRepr, AllColumnIdentities, Source, Identity1, Identity2, Identity3, Identity4, Identity5, Identity6, Identity7, Identity8, Identity9, Identity10, Identity11, Identity12, Identity13, Identity14, Identity15, Identity16, Identity17, Identity18, Identity19, Identity20, Identity21
// ](implicit
// ccSchema: Schema.CaseClass21[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z],
// ev: ColsRepr <:< (A1, (A2, (A3, (A4, (A5, (A6, (A7, (A8, (A9, (A10, (A11, (A12, (A13, (A14, (A15, (A16, (A17, (A18, (A19, (A20, (A21, Unit))))))))))))))))))))),
// ev2: F <:< Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Source[Identity1, Source], Features.Source[Identity2, Source]], Features.Source[Identity3, Source]], Features.Source[Identity4, Source]], Features.Source[Identity5, Source]], Features.Source[Identity6, Source]], Features.Source[Identity7, Source]], Features.Source[Identity8, Source]], Features.Source[Identity9, Source]], Features.Source[Identity10, Source]], Features.Source[Identity11, Source]], Features.Source[Identity12, Source]], Features.Source[Identity13, Source]], Features.Source[Identity14, Source]], Features.Source[Identity15, Source]], Features.Source[Identity16, Source]], Features.Source[Identity17, Source]], Features.Source[Identity18, Source]], Features.Source[Identity19, Source]], Features.Source[Identity20, Source]], Features.Source[Identity21, Source]],
// ev3: AllColumnIdentities <:< Identity1 with Identity2 with Identity3 with Identity4 with Identity5 with Identity6 with Identity7 with Identity8 with Identity9 with Identity10 with Identity11 with Identity12 with Identity13 with Identity14 with Identity15 with Identity16 with Identity17 with Identity18 with Identity19 with Identity20 with Identity21
// ): SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] =
// new SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] {}

// implicit def caseClass22[F, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, Z, ColsRepr, AllColumnIdentities, Source, Identity1, Identity2, Identity3, Identity4, Identity5, Identity6, Identity7, Identity8, Identity9, Identity10, Identity11, Identity12, Identity13, Identity14, Identity15, Identity16, Identity17, Identity18, Identity19, Identity20, Identity21, Identity22
// ](implicit
// ccSchema: Schema.CaseClass22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, Z],
// ev: ColsRepr <:< (A1, (A2, (A3, (A4, (A5, (A6, (A7, (A8, (A9, (A10, (A11, (A12, (A13, (A14, (A15, (A16, (A17, (A18, (A19, (A20, (A21, (A22, Unit)))))))))))))))))))))),
// ev2: F <:< Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Union[Features.Source[Identity1, Source], Features.Source[Identity2, Source]], Features.Source[Identity3, Source]], Features.Source[Identity4, Source]], Features.Source[Identity5, Source]], Features.Source[Identity6, Source]], Features.Source[Identity7, Source]], Features.Source[Identity8, Source]], Features.Source[Identity9, Source]], Features.Source[Identity10, Source]], Features.Source[Identity11, Source]], Features.Source[Identity12, Source]], Features.Source[Identity13, Source]], Features.Source[Identity14, Source]], Features.Source[Identity15, Source]], Features.Source[Identity16, Source]], Features.Source[Identity17, Source]], Features.Source[Identity18, Source]], Features.Source[Identity19, Source]], Features.Source[Identity20, Source]], Features.Source[Identity21, Source]], Features.Source[Identity22, Source]],
// ev3: AllColumnIdentities <:< Identity1 with Identity2 with Identity3 with Identity4 with Identity5 with Identity6 with Identity7 with Identity8 with Identity9 with Identity10 with Identity11 with Identity12 with Identity13 with Identity14 with Identity15 with Identity16 with Identity17 with Identity18 with Identity19 with Identity20 with Identity21 with Identity22
// ): SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] =
// new SchemaValidity[F, Z, ColsRepr, AllColumnIdentities, Source] {}
}
// format: on
}
34 changes: 33 additions & 1 deletion examples/src/main/scala/zio/sql/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.time._
import zio.sql.postgresql.PostgresJdbcModule
import zio.schema.DeriveSchema

object Examples extends App with ShopSchema with PostgresJdbcModule {
object Examples extends App with PostgresJdbcModule {
import this.AggregationDef._
import this.FunctionDef._
import this.OrderDetails._
Expand Down Expand Up @@ -155,4 +155,36 @@ object Examples extends App with ShopSchema with PostgresJdbcModule {
SELECT "orders"."usr_id" FROM "orders"
*/
val selectWithUnionAll = select(userId).from(users).unionAll(select(fkUserId).from(orders))

object Users {

case class Users(id: UUID, age: Int, dob: LocalDate, firstName: String, lastName: String)

implicit val userSchema = DeriveSchema.gen[Users]

val users = defineTable[Users]

val (userId, age, dob, fName, lName) = users.columns
}

object Orders {

case class Orders(id: java.util.UUID, userId: java.util.UUID, orderDate: LocalDate)

implicit val orderSchema = DeriveSchema.gen[Orders]

val orders = defineTable[Orders]

val (orderId, fkUserId, orderDate) = orders.columns
}

object OrderDetails {
case class OrderDetail(orderId: Int, productId: Int, quantity: Double, unitPrice: Double)

implicit val orderDetailSchema = DeriveSchema.gen[OrderDetail]

val orderDetails = defineTable[OrderDetail]

val (fkOrderId, fkProductId, quantity, unitPrice) = orderDetails.columns
}
}
2 changes: 1 addition & 1 deletion examples/src/main/scala/zio/sql/GroupByExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zio.sql
import zio.schema.DeriveSchema
import zio.sql.postgresql.PostgresJdbcModule

object GroupByExamples extends App with ShopSchema with PostgresJdbcModule {
object GroupByExamples extends App with PostgresJdbcModule {
import AggregationDef._

case class Product(id: Int, name: String, amount: Int, price: Double)
Expand Down
21 changes: 16 additions & 5 deletions mysql/src/test/scala/zio/sql/mysql/CommonFunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ import zio.Cause
import zio.stream.ZStream
import zio.test.Assertion._
import zio.test._
import zio.sql.Jdbc
import java.util.UUID
import java.time.LocalDate
import zio.schema._

object CommonFunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
object CommonFunctionDefSpec extends MysqlRunnableSpec with Jdbc {
import FunctionDef.{ CharLength => _, _ }
import Customers._

case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean)

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]

val (customerId, dob, fName, lName, verified) = customers.columns

private def collectAndCompare[R, E](
expected: Seq[String],
Expand All @@ -20,7 +31,7 @@ object CommonFunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
test("concat_ws #2 - combine columns") {

// note: you can't use customerId here as it is a UUID, hence not a string in our book
val query = select(ConcatWs3(Customers.fName, Customers.fName, Customers.lName)) from customers
val query = select(ConcatWs3(fName, fName, lName)) from customers

val expected = Seq(
"RonaldRonaldRussell",
Expand All @@ -35,7 +46,7 @@ object CommonFunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
},
test("concat_ws #3 - combine columns and flat values") {

val query = select(ConcatWs4(" ", "Person:", Customers.fName, Customers.lName)) from customers
val query = select(ConcatWs4(" ", "Person:", fName, lName)) from customers

val expected = Seq(
"Person: Ronald Russell",
Expand All @@ -51,7 +62,7 @@ object CommonFunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
test("concat_ws #3 - combine function calls together") {

val query = select(
ConcatWs3(" and ", Concat("Name: ", Customers.fName), Concat("Surname: ", Customers.lName))
ConcatWs3(" and ", Concat("Name: ", fName), Concat("Surname: ", lName))
) from customers

val expected = Seq(
Expand Down
15 changes: 12 additions & 3 deletions mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ package zio.sql.mysql

import zio.test._
import zio.test.Assertion._

import zio.schema._
import java.time.{ LocalDate, LocalTime, ZoneId }
import java.time.format.DateTimeFormatter
import zio.sql.Jdbc
import java.util.UUID

object CustomFunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {

import Customers._
import MysqlFunctionDef._

case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean)

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]

val (customerId, dob, fName, lName, verified) = customers.columns

override def specLayered = suite("MySQL FunctionDef")(
test("crc32") {
val query = select(Crc32("MySQL")) from customers
Expand Down
37 changes: 23 additions & 14 deletions mysql/src/test/scala/zio/sql/mysql/MysqlModuleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ import zio.test.TestAspect._

import scala.language.postfixOps

object MysqlModuleSpec extends MysqlRunnableSpec with ShopSchema {
object MysqlModuleSpec extends MysqlRunnableSpec {

import Customers._
import Orders._
case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean)

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]

val (customerId, dob, fName, lName, verified) = customers.columns

case class Orders(id: UUID, customer_id: UUID, order_date: LocalDate, deleted_at: Option[LocalDateTime])

implicit val orderSchema = DeriveSchema.gen[Orders]

val orders = defineTable[Orders]

val (orderId, fkCustomerId, orderDate, deletedAt) = orders.columns

override def specLayered = suite("Mysql module")(
test("Can select from single table") {
Expand Down Expand Up @@ -193,20 +206,16 @@ object MysqlModuleSpec extends MysqlRunnableSpec with ShopSchema {
implicit val customerRowSchema =
Schema.CaseClass5[UUID, LocalDate, String, String, Boolean, CustomerRow](
TypeId.parse("zio.sql.mysql.CustomerRow"),
Schema.Field("id", Schema.primitive[UUID](zio.schema.StandardType.UUIDType)),
Schema.Field("id", Schema.primitive[UUID](zio.schema.StandardType.UUIDType), get0 = _.id, set0 = (r, a) => r.copy(id = a)),
Schema.Field(
"dateOfBirth",
Schema.primitive[LocalDate](zio.schema.StandardType.LocalDateType(DateTimeFormatter.ISO_DATE))
Schema.primitive[LocalDate](zio.schema.StandardType.LocalDateType(DateTimeFormatter.ISO_DATE)),
get0 = _.dateOfBirth, set0 = (r, a) => r.copy(dateOfBirth = a)
),
Schema.Field("firstName", Schema.primitive[String](zio.schema.StandardType.StringType)),
Schema.Field("lastName", Schema.primitive[String](zio.schema.StandardType.StringType)),
Schema.Field("verified", Schema.primitive[Boolean](zio.schema.StandardType.BoolType)),
Schema.Field("firstName", Schema.primitive[String](zio.schema.StandardType.StringType), get0 = _.firstName, set0 = (r, a) => r.copy(firstName = a)),
Schema.Field("lastName", Schema.primitive[String](zio.schema.StandardType.StringType), get0 = _.lastName, set0 = (r, a) => r.copy(lastName = a)),
Schema.Field("verified", Schema.primitive[Boolean](zio.schema.StandardType.BoolType), get0 = _.verified, set0 = (r, a) => r.copy(verified = a)),
CustomerRow.apply,
_.id,
_.dateOfBirth,
_.firstName,
_.lastName,
_.verified
)

val rows = List(
Expand Down Expand Up @@ -248,7 +257,7 @@ object MysqlModuleSpec extends MysqlRunnableSpec with ShopSchema {
orderId,
fkCustomerId,
orderDate,
deleted_at
deletedAt
).values(rows)

println(renderInsert(command))
Expand Down
Empty file.
22 changes: 11 additions & 11 deletions mysql/src/test/scala/zio/sql/mysql/TransactionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ package zio.sql.mysql
import java.util.UUID

import zio._
import zio.schema._
import zio.test.Assertion._
import zio.test._
import zio.test.TestAspect.sequential
import java.time.LocalDate
import zio.sql.Jdbc

object TransactionSpec extends MysqlRunnableSpec with ShopSchema {
object TransactionSpec extends MysqlRunnableSpec with Jdbc {

import Customers._
case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean)

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]

val (customerId, dob, fName, lName, verified) = customers.columns

override def specLayered = suite("MySQL module")(
test("Transaction is returning the last value") {
Expand All @@ -26,15 +35,6 @@ object TransactionSpec extends MysqlRunnableSpec with ShopSchema {

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
},
test("Transaction is failing") {
val query = select(customerId) from customers

for {
result <- execute(ZTransaction(query) *> ZTransaction.fail(new Exception("failing")) *> ZTransaction(query))
.mapError(_.getMessage)
.flip
} yield assertTrue(result == "failing")
},
test("Transaction failed and didn't deleted rows") {
val query = select(customerId) from customers
val deleteQuery = deleteFrom(customers).where(verified === false)
Expand Down
11 changes: 0 additions & 11 deletions oracle/src/main/scala/zio/sql/oracle/OracleSqlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import java.time.OffsetTime
import java.time.OffsetDateTime

trait OracleSqlModule extends Sql { self =>
import ColumnSet._

override type TypeTagExtension[+A] = OracleTypeTag[A]

trait OracleTypeTag[+A] extends Tag[A] with Decodable[A]
Expand Down Expand Up @@ -45,11 +43,6 @@ trait OracleSqlModule extends Sql { self =>
val Sind = FunctionDef[Double, Double](FunctionName("sind"))
}

object Dual {
val dual = (string("dummy")).table("dual")
val (dummy) = dual.columns
}

implicit val instantSchema =
Schema.primitive[Instant](zio.schema.StandardType.InstantType(DateTimeFormatter.ISO_OFFSET_DATE_TIME))

Expand All @@ -70,8 +63,4 @@ trait OracleSqlModule extends Sql { self =>

implicit val zonedDatetimeSchema =
Schema.primitive[ZonedDateTime](zio.schema.StandardType.ZonedDateTimeType(DateTimeFormatter.ISO_ZONED_DATE_TIME))

def yearMonth(name: String): Singleton[YearMonth, name.type] = singleton[YearMonth, name.type](name)

def duration(name: String): Singleton[Duration, name.type] = singleton[Duration, name.type](name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import zio.Cause
import zio.stream.ZStream
import zio.test.Assertion._
import zio.test._
import zio.schema.DeriveSchema

object CommonFunctionDefSpec extends OracleRunnableSpec with ShopSchema {
import FunctionDef.{ CharLength => _, _ }
import Customers._
import Dual._

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

private def collectAndCompare[R, E](
expected: Seq[String],
Expand Down
Loading

0 comments on commit d216f67

Please sign in to comment.