Skip to content

Commit

Permalink
project compiles for 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
sviezypan committed Feb 16, 2023
1 parent 85a47e7 commit 1ef0d8c
Show file tree
Hide file tree
Showing 37 changed files with 201 additions and 160 deletions.
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 @@ -61,5 +61,5 @@ trait Sql {
},
someA => Right(someA)
)
implicit val none: Schema[None.type] = Schema.singleton(None)
implicit val none: Schema[None.type] = Schema.singleton(None)
}
1 change: 1 addition & 0 deletions core/jvm/src/main/scala/zio/sql/expr/AggregationDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zio.sql.expr

import zio.sql.typetag.TypeTag
import zio.sql.Features
import java.math.BigDecimal

final case class AggregationDef[-A, +B](name: FunctionName) { self =>

Expand Down
5 changes: 1 addition & 4 deletions core/jvm/src/main/scala/zio/sql/table/Table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,5 @@ object Table {
override type TableType = A
}

trait TableEx[A]

type TableExtension[A] <: Table.TableEx[A]

trait TableExtension[A]
}
4 changes: 0 additions & 4 deletions core/jvm/src/main/scala/zio/sql/typetag/Decodable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ import zio.sql.select.DecodingError

trait Decodable[+A] {
def decode(column: Int, resultSet: ResultSet): Either[DecodingError, A]
}

object Decodable {
type TypeTagExtension[+A] <: Tag[A] with Decodable[A]
}
5 changes: 4 additions & 1 deletion core/jvm/src/main/scala/zio/sql/typetag/TypeTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time._
import java.util.UUID
import zio.Chunk
import zio.schema._
import zio.sql.typetag.Decodable._
import zio.sql.typetag.Decodable

trait Tag[+A] {
private[zio] def cast(a: Any): A = a.asInstanceOf[A]
Expand All @@ -13,6 +13,9 @@ trait Tag[+A] {
sealed trait TypeTag[+A] extends Tag[A]

object TypeTag {

trait TypeTagExtension[+A] extends Tag[A] with Decodable[A]

sealed trait NotNull[+A] extends TypeTag[A]
implicit case object TBigDecimal extends NotNull[java.math.BigDecimal]
implicit case object TBoolean extends NotNull[Boolean]
Expand Down
17 changes: 9 additions & 8 deletions examples/src/main/scala/zio/sql/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import java.util.UUID
import java.time._
import zio.sql.postgresql.PostgresJdbcModule
import zio.schema.DeriveSchema
import zio.sql.expr.AggregationDef._
import zio.sql.expr.FunctionDef._
import zio.sql.table._

object Examples extends App with PostgresJdbcModule {
import this.AggregationDef._
import this.FunctionDef._
import this.OrderDetails._
import this.Orders._
import this.Users._
import Orders._
import Users._
import OrderDetails._

val basicSelect =
select(fName, lName).from(users)
Expand Down Expand Up @@ -173,7 +174,7 @@ object Examples extends App with PostgresJdbcModule {

implicit val userSchema = DeriveSchema.gen[Users]

val users = defineTable[Users]
val users = Table.defineTable[Users]

val (userId, age, dob, fName, lName) = users.columns
}
Expand All @@ -184,7 +185,7 @@ object Examples extends App with PostgresJdbcModule {

implicit val orderSchema = DeriveSchema.gen[Orders]

val orders = defineTable[Orders]
val orders = Table.defineTable[Orders]

val (orderId, fkUserId, orderDate) = orders.columns
}
Expand All @@ -194,7 +195,7 @@ object Examples extends App with PostgresJdbcModule {

implicit val orderDetailSchema = DeriveSchema.gen[OrderDetail]

val orderDetails = defineTable[OrderDetail]
val orderDetails = Table.defineTable[OrderDetail]

val (fkOrderId, fkProductId, quantity, unitPrice) = orderDetails.columns
}
Expand Down
5 changes: 3 additions & 2 deletions examples/src/main/scala/zio/sql/GroupByExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package zio.sql

import zio.schema.DeriveSchema
import zio.sql.postgresql.PostgresJdbcModule
import zio.sql.expr.AggregationDef._
import zio.sql.table._

object GroupByExamples extends App with PostgresJdbcModule {
import AggregationDef._

case class Product(id: Int, name: String, amount: Int, price: Double)

implicit val productSchema = DeriveSchema.gen[Product]

val productTable = defineTable[Product]
val productTable = Table.defineTable[Product]

val (id, name, amount, price) = productTable.columns

Expand Down
2 changes: 2 additions & 0 deletions jdbc/src/main/scala/zio/sql/JdbcInternalModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package zio.sql
import java.sql._
import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset }
import zio.Chunk
import zio.sql.select._
import zio.sql.typetag._

trait JdbcInternalModule { self: Jdbc =>

Expand Down
4 changes: 4 additions & 0 deletions jdbc/src/main/scala/zio/sql/SqlDriverLiveModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import zio._
import zio.stream.{ Stream, ZStream }
import zio.schema.Schema
import zio.IO
import zio.sql.update._
import zio.sql.select._
import zio.sql.insert._
import zio.sql.delete._

trait SqlDriverLiveModule { self: Jdbc =>
private[sql] trait SqlDriverCore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package zio.sql
import zio._
import zio.stream.ZStream
import zio.schema.Schema
import zio.sql.update._
import zio.sql.select._
import zio.sql.insert._
import zio.sql.delete._

trait ExprSyntaxModule { self: Jdbc =>
trait TransactionSyntaxModule { self: Jdbc =>
implicit final class ReadSyntax[A](self: Read[A]) {
def run: ZStream[SqlTransaction, Exception, A] =
ZStream.serviceWithStream(_.read(self))
Expand Down
6 changes: 5 additions & 1 deletion jdbc/src/main/scala/zio/sql/jdbc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import zio._
import zio.stream._
import zio.schema.Schema
import zio.sql.macros.GroupByLike
import zio.sql.update._
import zio.sql.select._
import zio.sql.insert._
import zio.sql.delete._

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

Expand Down
31 changes: 19 additions & 12 deletions mysql/src/main/scala/zio/sql/mysql/MysqlRenderModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ import zio.Chunk
import zio.schema._
import zio.schema.StandardType._
import zio.sql.driver.Renderer
import zio.sql.update._
import zio.sql.select._
import zio.sql.insert._
import zio.sql.delete._
import zio.sql.expr._
import zio.sql.table._
import zio.sql.typetag._

trait MysqlRenderModule extends MysqlSqlModule { self =>

override def renderRead(read: self.Read[_]): String = {
override def renderRead(read: Read[_]): String = {
implicit val render: Renderer = Renderer()
MysqlRenderer.renderReadImpl(read)
render.toString
}

override def renderInsert[A: Schema](insert: self.Insert[_, A]): String = {
override def renderInsert[A: Schema](insert: Insert[_, A]): String = {
implicit val render: Renderer = Renderer()
MysqlRenderer.renderInsertImpl(insert)
render.toString
}

override def renderDelete(delete: self.Delete[_]): String = {
override def renderDelete(delete: Delete[_]): String = {
implicit val render: Renderer = Renderer()
MysqlRenderer.renderDeleteImpl(delete)
render.toString
}

override def renderUpdate(update: self.Update[_]): String = {
override def renderUpdate(update: Update[_]): String = {
implicit val render: Renderer = Renderer()
MysqlRenderer.renderUpdateImpl(update)
render.toString
Expand Down Expand Up @@ -62,7 +69,7 @@ trait MysqlRenderModule extends MysqlSqlModule { self =>
renderWhereExpr(whereExpr)
}

def renderReadImpl(read: self.Read[_])(implicit render: Renderer): Unit =
def renderReadImpl(read: Read[_])(implicit render: Renderer): Unit =
read match {
case Read.Mapped(read, _) => renderReadImpl(read)

Expand Down Expand Up @@ -250,7 +257,7 @@ trait MysqlRenderModule extends MysqlSqlModule { self =>
table match {
case Table.DialectSpecificTable(_) => ???
// The outer reference in this type test cannot be checked at run time?!
case sourceTable: self.Table.Source =>
case sourceTable: Table.Source =>
render(sourceTable.name)
case Table.DerivedTable(read, name) =>
render(" ( ")
Expand All @@ -273,14 +280,14 @@ trait MysqlRenderModule extends MysqlSqlModule { self =>

private[zio] def quoted(name: String): String = "\"" + name + "\""

private def renderExpr[A, B](expr: self.Expr[_, A, B])(implicit render: Renderer): Unit = expr match {
private def renderExpr[A, B](expr: Expr[_, A, B])(implicit render: Renderer): Unit = expr match {
case Expr.Subselect(subselect) =>
render(" (")
renderRead(subselect)
render(") ")
case Expr.Source(table, column) =>
(table, column.name) match {
case (tableName: TableName, Some(columnName)) => render(tableName, ".", columnName)
case (tableName: String, Some(columnName)) => render(tableName, ".", columnName)
case _ => ()
}
case Expr.Unary(base, op) =>
Expand Down Expand Up @@ -402,15 +409,15 @@ trait MysqlRenderModule extends MysqlSqlModule { self =>
render(")")
}

private def renderLit[A, B](lit: self.Expr.Literal[_])(implicit render: Renderer): Unit = {
private def renderLit[A, B](lit: Expr.Literal[_])(implicit render: Renderer): Unit = {
import MysqlSpecific.MysqlTypeTag._
import TypeTag._
lit.typeTag match {
case TDialectSpecific(tt) =>
tt match {
case tt @ TYear =>
case tt @ TYear =>
render(tt.cast(lit.value))
case _: MysqlSpecific.MysqlTypeTag[_] => ???
case _ => ???
}
case TByteArray =>
render(
Expand Down Expand Up @@ -531,7 +538,7 @@ trait MysqlRenderModule extends MysqlSqlModule { self =>
* Drops the initial Litaral(true) present at the start of every WHERE expressions by default
* and proceeds to the rest of Expr's.
*/
private def renderWhereExpr[A, B](expr: self.Expr[_, A, B])(implicit render: Renderer): Unit = expr match {
private def renderWhereExpr[A, B](expr: Expr[_, A, B])(implicit render: Renderer): Unit = expr match {
case Expr.Literal(true) => ()
case Expr.Binary(_, b, _) =>
render(" WHERE ")
Expand Down
7 changes: 4 additions & 3 deletions mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import java.time._
import java.sql.ResultSet
import java.util.UUID
import zio.sql.Sql
import zio.sql.select._
import zio.sql.expr._
import zio.sql.typetag._

trait MysqlSqlModule extends Sql { self =>

override type TypeTagExtension[+A] = MysqlSpecific.MysqlTypeTag[A]

object MysqlSpecific {
trait MysqlTypeTag[+A] extends Tag[A] with Decodable[A]
trait MysqlTypeTag[+A] extends TypeTag.TypeTagExtension[A]

object MysqlTypeTag {
implicit case object TYear extends MysqlTypeTag[Year] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import zio.sql.Jdbc
import java.util.UUID
import java.time.LocalDate
import zio.schema._
import zio.sql.expr.FunctionDef.{ CharLength => _, _ }
import zio.sql.table._

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

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 customers = Table.defineTable[Customers]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.time.{ LocalDate, LocalTime, ZoneId }
import java.time.format.DateTimeFormatter
import zio.sql.Jdbc
import java.util.UUID
import zio.sql.table._

object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {

Expand All @@ -16,7 +17,7 @@ object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]
val customers = Table.defineTable[Customers]

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

Expand Down
3 changes: 2 additions & 1 deletion mysql/src/test/scala/zio/sql/mysql/DeleteSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import java.util.UUID
import java.time.LocalDate
import zio.schema.DeriveSchema
import zio.test.TestAspect.sequential
import zio.sql.table._

object DeleteSpec extends MysqlRunnableSpec {

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

implicit val customerSchema = DeriveSchema.gen[Customers]

val customers = defineTable[Customers]
val customers = Table.defineTable[Customers]

val (_, _, _, lastName, verified) = customers.columns

Expand Down
12 changes: 6 additions & 6 deletions mysql/src/test/scala/zio/sql/mysql/MysqlModuleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ import zio.test._
import zio.test.Assertion._
import zio.test.TestAspect._
import java.math.BigDecimal

import zio.sql.table._
import scala.language.postfixOps
import zio.sql.expr.AggregationDef._

object MysqlModuleSpec extends MysqlRunnableSpec {

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 customers = Table.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 orders = Table.defineTable[Orders]

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

case class ProductPrice(productId: UUID, effective: LocalDate, price: BigDecimal)
implicit val productPriceSchema = DeriveSchema.gen[ProductPrice]

val productPrices = defineTableSmart[ProductPrice]
val productPrices = Table.defineTableSmart[ProductPrice]

val (productPricesOrderId, effectiveDate, productPrice) = productPrices.columns

case class OrderDetails(orderId: UUID, productId: UUID, quantity: Int, unitPrice: BigDecimal)

implicit val orderDetailsSchema = DeriveSchema.gen[OrderDetails]

val orderDetails = defineTableSmart[OrderDetails]
val orderDetails = Table.defineTableSmart[OrderDetails]

val (orderDetailsOrderId, orderDetailsProductId, quantity, unitPrice) = orderDetails.columns

Expand Down Expand Up @@ -206,7 +207,6 @@ object MysqlModuleSpec extends MysqlRunnableSpec {
* Uncomment it when aggregation function handling is fixed.
*/
test("Can count rows") {
import AggregationDef._
val query = select(Count(customerId)) from customers

for {
Expand Down
Loading

0 comments on commit 1ef0d8c

Please sign in to comment.