Skip to content

Commit

Permalink
fix more scala 3 compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Nov 28, 2023
1 parent e18a32f commit f14654d
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait MyPostgresProfile extends ExPostgresProfile
override val api = MyAPI

object MyAPI extends ExtPostgresAPI with ArrayImplicits
with DateTimeImplicits
with Date2DateTimeImplicitsDuration
with JsonImplicits
with NetImplicits
with LTreeImplicits
Expand Down Expand Up @@ -91,7 +91,7 @@ class TestTable(tag: Tag) extends Table[Test](tag, Some("xxx"), "Test") {
def props = column[Map[String,String]]("props_hstore")
def tags = column[List[String]]("tags_arr")

def * = (id, during, location, text, props, tags) <> (Test.tupled, Test.unapply)
def * = (id, during, location, text, props, tags) <> ((Test.apply _).tupled, Test.unapply)
}

object tests extends TableQuery(new TestTable(_)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTyp
}
}

/// alias
trait DateTimeImplicits extends JodaDateTimeImplicits

trait JodaDateTimeFormatters {
val jodaDateFormatter = ISODateTimeFormat.date()
val jodaTimeFormatter = DateTimeFormat.forPattern("HH:mm:ss.SSSSSS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
val plainAPI = new API with JodaDateTimePlainImplicits

///
trait API extends JdbcAPI with DateTimeImplicits
trait API extends JdbcAPI with JodaDateTimeImplicits
}
object MyPostgresProfile extends MyPostgresProfile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import play.api.libs.json._
import slick.jdbc.{GetResult, JdbcType, PostgresProfile}
import com.github.tminglei.slickpg.utils.JsonUtils
import org.scalatest.funsuite.AnyFunSuite
import play.api.libs.functional.syntax.toFunctionalBuilderOps
import slick.ast.BaseTypedType


Expand All @@ -15,7 +16,12 @@ class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer {

case class JBean(name: String, count: Int)
object JBean {
implicit val jbeanFmt: OFormat[JBean] = Json.format[JBean]
// jbeanFmt should just be this, but there's a bug in play-json for scala 3 that causes it to throw a java.lang.ClassCastException -- and we're not testing that here
// implicit val jbeanFmt: OFormat[JBean] = Json.format[JBean]
implicit val jbeanFmt: OFormat[JBean] = (
(__ \ implicitly[JsonConfiguration].naming("name")).format[String] and
(__ \ implicitly[JsonConfiguration].naming("count")).format[Int]
)(JBean.apply _, x => (x.name, x.count))
implicit val jbeanWrt: OWrites[JBean] = Json.writes[JBean]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
case Some(p) => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode, LiteralNode(p))
case None => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode)
}
def makeBox[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = {
def makeBox[G <: GEOMETRY, P1, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P1]#to[GEOMETRY, R]) = {
om.column(GeomLibrary.MakeBox, lowLeftPoint.toNode, upRightPoint.toNode)
}
def makeBox3d[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = {
def makeBox3d[G <: GEOMETRY, P1, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P2]#to[GEOMETRY, R]) = {
om.column(GeomLibrary.MakeBox3D, lowLeftPoint.toNode, upRightPoint.toNode)
}
def makeEnvelope(xmin: Rep[Double], ymin: Rep[Double], xmax: Rep[Double], ymax: Rep[Double], srid: Option[Int] = None)(
Expand All @@ -75,8 +75,8 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
case (None, Some(m)) => om.column(GeomLibrary.MakePointM, x.toNode, y.toNode, LiteralNode(m))
case (None, None) => om.column(GeomLibrary.MakePoint, x.toNode, y.toNode)
}
def makeLine[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](point1: Rep[P1], point2: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = {
def makeLine[G <: GEOMETRY, P1, P2, R](point1: Rep[P1], point2: Rep[P2])(
implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P2]#to[GEOMETRY, R]) = {
om.column(GeomLibrary.MakeLine, point1.toNode, point2.toNode)
}
def makePolygon[G <: GEOMETRY, P, R](linestring: Rep[P])(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait PgStringExtensions extends JdbcTypesComponent { driver: PostgresProfile =>
}

class PgStringColumnExtensionMethods[P1](val c: Rep[P1]) extends ExtensionMethods[String, P1] {
protected implicit def b1Type = implicitly[TypedType[String]]
protected def b1Type = implicitly[TypedType[String]]

def ilike[P2, R](e: Rep[P2])(implicit om: o#arg[String, P2]#to[Boolean, R]) = {
om.column(StringLibrary.ILike, n, e.toNode)
Expand Down Expand Up @@ -58,7 +58,7 @@ trait PgStringExtensions extends JdbcTypesComponent { driver: PostgresProfile =>
}

class PgStringByteaColumnExtensionMethods[P1](val c: Rep[P1]) extends ExtensionMethods[Array[Byte], P1] {
protected implicit def b1Type = implicitly[TypedType[Array[Byte]]]
protected def b1Type = implicitly[TypedType[Array[Byte]]]

def convert[R](srcEncoding: Rep[String], destEncoding: Rep[String])(implicit om: o#to[Array[Byte], R]) = {
om.column(StringLibrary.Convert, n, srcEncoding.toNode, destEncoding.toNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait MyPostgresDriver extends ExPostgresProfile
//////
trait MyAPI extends ExtPostgresAPI
with ArrayImplicits
with DateTimeImplicits
with Date2DateTimeImplicitsDuration
with RangeImplicits
with HStoreImplicits
with SearchImplicits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait MyPostgresDriver extends ExPostgresDriver
override val pgjson = "jsonb"
///
override val api = new ExtPostgresAPI with ArrayImplicits
with DateTimeImplicits
with Date2DateTimeImplicitsDuration
with PlayJsonImplicits
with NetImplicits
with LTreeImplicits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ trait PgDate2Support extends date.PgDateExtensions with utils.PgCommonJdbcTypes
}

/// alias
trait DateTimeImplicits extends Date2DateTimeImplicitsDuration
trait DateTimeImplicitsPeriod extends Date2DateTimeImplicitsPeriod

trait Date2DateTimeImplicitsDuration extends Date2DateTimeImplicits[Duration]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import slick.jdbc.{JdbcType, PostgresProfile}
trait PgDateSupport extends date.PgDateExtensions with utils.PgCommonJdbcTypes with date.PgDateJdbcTypes { driver: PostgresProfile =>
import driver.api._

/// alias
trait DateTimeImplicits extends SimpleDateTimeImplicits

trait SimpleDateTimeImplicits {
implicit val simpleIntervalTypeMapper: JdbcType[Interval] = new GenericJdbcType[Interval]("interval", Interval.apply, hasLiteralForm=false)
implicit val simpleTimestampTZTypeMapper: JdbcType[Calendar] = new GenericDateJdbcType[Calendar]("timestamptz", java.sql.Types.TIMESTAMP_WITH_TIMEZONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait MyPostgresProfile extends ExPostgresProfile

trait MyAPI extends ExtPostgresAPI with ArrayImplicits
with SimpleDateTimeImplicits
with DateTimeImplicits
with Date2DateTimeImplicitsDuration
with SimpleJsonImplicits
with NetImplicits
with LTreeImplicits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class PgArraySupportSuite extends AnyFunSuite with PostgresContainer {
r => assert(List(testRec2) === r)
),
// @>
ArrayTests.filter(_.strArr @> Vector("str3")).sortBy(_.id).to[List].result.map(
ArrayTests.filter(_.strArr @> (Vector("str3"): Rep[Vector[String]])).sortBy(_.id).to[List].result.map(
r => assert(List(testRec1, testRec2, testRec3) === r)
),
ArrayTests.filter(_.mktFinancialProducts @> List(MarketFinancialProduct("product1"))).sortBy(_.id).to[List].result.map(
Expand Down Expand Up @@ -255,7 +255,7 @@ class PgArraySupportSuite extends AnyFunSuite with PostgresContainer {
sqlu"insert into ArrayTest1 values(${b.id}, ${b.bytea}, ${b.uuidArr}, ${b.strArr}, ${b.longArr}, ${b.intArr}, ${b.shortArr}, ${b.floatArr}, ${b.doubleArr}, ${b.boolArr}, ${b.dateArr}, ${b.timeArr}, ${b.tsArr}, ${b.institutionArr})",
sql"select * from ArrayTest1 where id = ${b.id}".as[ArrayBean1].head.map(
f => {
b.bytea.zip(f.bytea).map(r => assert(r._1 === r._2))
b.bytea.toSeq.zip(f.bytea.toSeq).map(r => assert(r._1 === r._2))
b.uuidArr.zip(f.uuidArr).map(r => assert(r._1 === r._2))
b.strArr.getOrElse(Nil).zip(f.strArr.getOrElse(Nil)).map(r => assert(r._1 === r._2))
b.longArr.zip(f.longArr).map(r => assert(r._1 === r._2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object PgCompositeSupportSuite {
}
override val api: API = new API {}

val plainImplicits = new API with SimpleArrayPlainImplicits {
object plainImplicits extends API with SimpleArrayPlainImplicits {
import utils.PlainSQLUtils._
// to support 'nextArray[T]/nextArrayOption[T]' in PgArraySupport
{
Expand Down
22 changes: 11 additions & 11 deletions src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer {
def values = _values map (v => (v.toString, v)) toMap
}

object Currency extends Enum[Currency]
sealed trait Currency extends Currency.Value
object Currency extends Enum[Currency]
case object EUR extends Currency
case object GBP extends Currency
case object USD extends Currency
Expand Down Expand Up @@ -60,10 +60,10 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val rainbowTypeMapper: JdbcType[Rainbows.Value] = createEnumJdbcType[Rainbows.type]("Rainbow", Rainbows, true)
implicit val rainbowListTypeMapper: JdbcType[List[Rainbows.Value]] = createEnumListJdbcType[Rainbows.type]("Rainbow", Rainbows, true)

implicit val weekDayColumnExtensionMethodsBuilder: api.Rep[WeekDays.Value] => EnumColumnExtensionMethods[WeekDays.Value, WeekDays.Value] = createEnumColumnExtensionMethodsBuilder[WeekDays.type](WeekDays)
implicit val weekDayOptionColumnExtensionMethodsBuilder: api.Rep[Option[WeekDays.Value]] => EnumColumnExtensionMethods[WeekDays.Value, Option[WeekDays.Value]] = createEnumOptionColumnExtensionMethodsBuilder[WeekDays.type](WeekDays)
implicit val rainbowColumnExtensionMethodsBuilder: api.Rep[Rainbows.Value] => EnumColumnExtensionMethods[Rainbows.Value, Rainbows.Value] = createEnumColumnExtensionMethodsBuilder[Rainbows.type](Rainbows)
implicit val rainbowOptionColumnExtensionMethodsBuilder: api.Rep[Option[Rainbows.Value]] => EnumColumnExtensionMethods[Rainbows.Value, Option[Rainbows.Value]] = createEnumOptionColumnExtensionMethodsBuilder[Rainbows.type](Rainbows)
implicit def weekDayColumnExtensionMethodsBuilder(rep: Rep[WeekDays.Value]): EnumColumnExtensionMethods[WeekDays.Value, WeekDays.Value] = createEnumColumnExtensionMethodsBuilder[WeekDays.type](WeekDays).apply(rep)
implicit def weekDayOptionColumnExtensionMethodsBuilder(rep: Rep[Option[WeekDays.Value]]): EnumColumnExtensionMethods[WeekDays.Value, Option[WeekDays.Value]] = createEnumOptionColumnExtensionMethodsBuilder[WeekDays.type](WeekDays).apply(rep)
implicit def rainbowColumnExtensionMethodsBuilder(rep: Rep[Rainbows.Value]): EnumColumnExtensionMethods[Rainbows.Value, Rainbows.Value] = createEnumColumnExtensionMethodsBuilder[Rainbows.type](Rainbows).apply(rep)
implicit def rainbowOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Rainbows.Value]]): EnumColumnExtensionMethods[Rainbows.Value, Option[Rainbows.Value]] = createEnumOptionColumnExtensionMethodsBuilder[Rainbows.type](Rainbows).apply(rep)

/// custom types of java enums and algebraic data type (ADT)
implicit val currencyTypeMapper: JdbcType[Currency] = createEnumJdbcType[Currency]("Currency", _.toString, Currency.values.get(_).get, quoteName = false)
Expand All @@ -73,12 +73,12 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val genderTypeMapper: JdbcType[Gender] = createEnumJdbcType[Gender]("Gender", _.repr, Gender.fromString, quoteName = false)
implicit val genderTypeListMapper: JdbcType[List[Gender]] = createEnumListJdbcType[Gender]("Gender", _.repr, Gender.fromString, quoteName = false)

implicit val currencyColumnExtensionMethodsBuilder: api.Rep[Currency] => EnumColumnExtensionMethods[Currency, Currency] = createEnumColumnExtensionMethodsBuilder[Currency]
implicit val currencyOptionColumnExtensionMethodsBuilder: api.Rep[Option[Currency]] => EnumColumnExtensionMethods[Currency, Option[Currency]] = createEnumOptionColumnExtensionMethodsBuilder[Currency]
implicit val languagesColumnExtensionMethodsBuilder: api.Rep[Languages] => EnumColumnExtensionMethods[Languages, Languages] = createEnumColumnExtensionMethodsBuilder[Languages]
implicit val languagesOptionColumnExtensionMethodsBuilder: api.Rep[Option[Languages]] => EnumColumnExtensionMethods[Languages, Option[Languages]] = createEnumOptionColumnExtensionMethodsBuilder[Languages]
implicit val genderColumnExtensionMethodsBuilder: api.Rep[Gender] => EnumColumnExtensionMethods[Gender, Gender] = createEnumColumnExtensionMethodsBuilder[Gender]
implicit val genderOptionColumnExtensionMethodsBuilder: api.Rep[Option[Gender]] => EnumColumnExtensionMethods[Gender, Option[Gender]] = createEnumOptionColumnExtensionMethodsBuilder[Gender]
implicit def currencyColumnExtensionMethodsBuilder(rep: Rep[Currency]): EnumColumnExtensionMethods[Currency, Currency] = createEnumColumnExtensionMethodsBuilder[Currency].apply(rep)
implicit def currencyOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Currency]]): EnumColumnExtensionMethods[Currency, Option[Currency]] = createEnumOptionColumnExtensionMethodsBuilder[Currency].apply(rep)
implicit def languagesColumnExtensionMethodsBuilder(rep: Rep[Languages]): EnumColumnExtensionMethods[Languages, Languages] = createEnumColumnExtensionMethodsBuilder[Languages].apply(rep)
implicit def languagesOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Languages]]): EnumColumnExtensionMethods[Languages, Option[Languages]] = createEnumOptionColumnExtensionMethodsBuilder[Languages].apply(rep)
implicit def genderColumnExtensionMethodsBuilder(rep: Rep[Gender]): EnumColumnExtensionMethods[Gender, Gender] = createEnumColumnExtensionMethodsBuilder[Gender].apply(rep)
implicit def genderOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Gender]]): EnumColumnExtensionMethods[Gender, Option[Gender]] = createEnumOptionColumnExtensionMethodsBuilder[Gender].apply(rep)
}
}
object MyPostgresProfile1 extends MyPostgresProfile1
Expand Down

0 comments on commit f14654d

Please sign in to comment.