Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 support #677

Merged
merged 15 commits into from
Dec 17, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
java: [8, 11]
scala: [2.12.18, 2.13.12]
scala: [2.12.18, 2.13.12, 3.3.1]
postgres: [11, 12, 13, 14]
name: Test (Postgres ${{ matrix.postgres }} Scala ${{ matrix.scala }} Java ${{ matrix.java }})
runs-on: ubuntu-latest
Expand Down
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
@@ -1,17 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import argonaut.Argonaut._
import argonaut._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgArgonautSupport
Expand All @@ -24,7 +23,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val strListTypeMapper: DriverJdbcType[List[JsonField]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile
Expand All @@ -40,7 +39,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def json = column[Json]("json")

def * = (id, json) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -158,7 +157,7 @@ class PgArgonautSupportSuite extends AnyFunSuite with PostgresContainer {
test("Argonaut json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean] = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))

val b = JsonBean(34L, """ { "a":101, "b":"aaa", "c":[3,4,5,9] } """.parseOption.getOrElse(jNull))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import cats.syntax.either._
import io.circe._
import io.circe.parser._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgCirceJsonSupport
Expand All @@ -25,7 +24,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile
Expand All @@ -40,7 +39,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def json = column[Json]("json")

def * = (id, json) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -137,7 +136,7 @@ class PgCirceJsonSupportSuite extends AnyFunSuite with PostgresContainer {
test("Circe json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean] = GetResult(r => JsonBean(r.nextLong(), r.nextJson()))

val b = JsonBean(34L, parse(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """).getOrElse(Json.Null))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.typelevel.jawn._
import org.typelevel.jawn.ast._

import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgJawnJsonSupport
Expand All @@ -25,8 +23,8 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val jsonArrayTypeMapper =
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val jsonArrayTypeMapper: DriverJdbcType[List[JValue]] =
new AdvancedArrayJdbcType[JValue](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JValue](JParser.parseUnsafe(_))(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JValue](_.toString())(v)
Expand All @@ -47,7 +45,7 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
def json = column[JValue]("json", O.Default(JParser.parseUnsafe(""" {"a":"v1","b":2} """)))
def jsons = column[List[JValue]]("jsons")

def * = (id, json, jsons) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json, jsons) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -173,7 +171,7 @@ class PgJawnJsonSupportSuite extends AnyFunSuite with PostgresContainer {
test("Json Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean1] = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))

val b = JsonBean1(34L, JParser.parseUnsafe(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """))

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
@@ -1,15 +1,14 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.joda.time._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}

class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgDateSupportJoda {
Expand All @@ -19,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 Expand Up @@ -47,7 +46,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
def interval = column[Period]("interval")
def instant = column[Instant]("instant")

def * = (id, date, time, datetime, datetimetz, interval, instant) <> (DatetimeBean.tupled, DatetimeBean.unapply)
def * = (id, date, time, datetime, datetimetz, interval, instant) <> ((DatetimeBean.apply _).tupled, DatetimeBean.unapply)
}
val Datetimes = TableQuery[DatetimeTable]

Expand Down Expand Up @@ -248,7 +247,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer {
test("Joda time Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getDateBean = GetResult(r => DatetimeBean(
implicit val getDateBean: GetResult[DatetimeBean] = GetResult(r => DatetimeBean(
r.nextLong(), r.nextLocalDate(), r.nextLocalTime(), r.nextLocalDateTime(), r.nextZonedDateTime(), r.nextPeriod(), r.nextInstant()))

val b1 = new DatetimeBean(107L, LocalDate.parse("2010-11-03"), LocalTime.parse("12:33:01.101357"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import org.json4s._
import org.scalatest.funsuite.AnyFunSuite
import slick.jdbc.{GetResult, PostgresProfile}

import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import scala.concurrent.duration._

class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends PostgresProfile
with PgJson4sSupport
Expand All @@ -26,8 +25,8 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {

///
trait API extends JdbcAPI with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val json4sJsonArrayTypeMapper =
implicit val strListTypeMapper: DriverJdbcType[List[String]] = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val json4sJsonArrayTypeMapper: DriverJdbcType[List[JValue]] =
new AdvancedArrayJdbcType[JValue](pgjson,
(s) => utils.SimpleArrayUtils.fromString[JValue](jsonMethods.parse(_))(s).orNull,
(v) => utils.SimpleArrayUtils.mkString[JValue](j=>jsonMethods.compact(jsonMethods.render(j)))(v)
Expand All @@ -49,7 +48,7 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
def json = column[JValue]("json")
def jsons = column[List[JValue]]("jsons")

def * = (id, json, jsons) <> (JsonBean.tupled, JsonBean.unapply)
def * = (id, json, jsons) <> ((JsonBean.apply _).tupled, JsonBean.unapply)
}
val JsonTests = TableQuery[JsonTestTable]

Expand Down Expand Up @@ -175,7 +174,7 @@ class PgJson4sSupportSuite extends AnyFunSuite with PostgresContainer {
test("Json4s Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val getJsonBeanResult = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))
implicit val getJsonBeanResult: GetResult[JsonBean1] = GetResult(r => JsonBean1(r.nextLong(), r.nextJson()))

val b = JsonBean1(34L, parse(""" { "a":101, "b":"aaa", "c":[3,4,5,9] } """))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import slick.jdbc.GetResult

import com.vividsolutions.jts.geom.{Geometry, Point}
import com.vividsolutions.jts.io.{WKBWriter, WKTReader, WKTWriter}
import org.scalatest.funsuite.AnyFunSuite


class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends ExPostgresProfile with PgPostGISSupport {

Expand Down Expand Up @@ -41,7 +38,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def geom = column[Geometry]("geom")
def geog = column[Geography]("geog")

def * = (id, geom, geog) <> (GeometryBean.tupled, GeometryBean.unapply)
def * = (id, geom, geog) <> ((GeometryBean.apply _).tupled, GeometryBean.unapply)
}
val GeomTests = TableQuery[GeomTestTable]

Expand All @@ -52,7 +49,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def point = column[Point]("point")

def * = (id, point) <> (PointBean.tupled, PointBean.unapply)
def * = (id, point) <> ((PointBean.apply _).tupled, PointBean.unapply)
}
val PointTests = TableQuery[PointTestTable]

Expand Down Expand Up @@ -830,7 +827,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
test("PostGIS Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val GetPointBeanResult = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))
implicit val GetPointBeanResult: GetResult[PointBean] = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))

val b = PointBean(77L, wktReader.read("POINT(4 5)").asInstanceOf[Point])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.github.tminglei.slickpg

import java.util.concurrent.Executors

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutorService}
import slick.jdbc.GetResult

import org.locationtech.jts.geom.{Geometry, Point}
import org.locationtech.jts.io.{WKBWriter, WKTReader, WKTWriter}
import org.scalatest.funsuite.AnyFunSuite


class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))
implicit val testExecContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

trait MyPostgresProfile extends ExPostgresProfile with PgPostGISSupport {

Expand Down Expand Up @@ -41,7 +38,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def geom = column[Geometry]("geom")
def geog = column[Geography]("geog")

def * = (id, geom, geog) <> (GeometryBean.tupled, GeometryBean.unapply)
def * = (id, geom, geog) <> ((GeometryBean.apply _).tupled, GeometryBean.unapply)
}
val GeomTests = TableQuery[GeomTestTable]

Expand All @@ -52,7 +49,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def point = column[Point]("point")

def * = (id, point) <> (PointBean.tupled, PointBean.unapply)
def * = (id, point) <> ((PointBean.apply _).tupled, PointBean.unapply)
}
val PointTests = TableQuery[PointTestTable]

Expand Down Expand Up @@ -816,7 +813,7 @@ class PgPostGISSupportSuite extends AnyFunSuite with PostgresContainer {
test("PostGIS (lt) Plain SQL support") {
import MyPostgresProfile.plainAPI._

implicit val GetPointBeanResult = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))
implicit val GetPointBeanResult: GetResult[PointBean] = GetResult(r => PointBean(r.nextLong(), r.nextGeometry[Point]()))

val b = PointBean(77L, wktReader.read("POINT(4 5)").asInstanceOf[Point])

Expand Down
Loading
Loading