Skip to content

Commit

Permalink
scala v2.12 support (complement)
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Dec 11, 2016
1 parent cc8a0d9 commit 56ad9e0
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 55 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sudo: required
language: scala
scala:
- 2.11.8
- 2.12.1
jdk:
- oraclejdk8
before_install:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import scala.concurrent.duration._
class PgArgonautSupportSuite extends FunSuite {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgArgonautSupport
with array.PgArrayJdbcTypes {
override val pgjson = "jsonb"

override val api = new API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
override val api: API = new API {}

val plainAPI = new API with ArgonautJsonPlainImplicits

///
trait API extends super.API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ import scala.concurrent.duration._
class PgCirceJsonSupportSuite extends FunSuite {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgCirceJsonSupport
with array.PgArrayJdbcTypes {
override val pgjson = "jsonb"

override val api = new API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
override val api: API = new API {}

val plainAPI = new API with CirceJsonPlainImplicits

///
trait API extends super.API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
}
}
object MyPostgresProfile extends MyPostgresProfile

import MyPostgresProfile.api._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import scala.concurrent.{Await, ExecutionContext}
class PgDateSupportJodaSuite extends FunSuite {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgDateSupportJoda {

override val api = new API with DateTimeImplicits
override val api: API = new API {}

///
val plainAPI = new API with JodaDateTimePlainImplicits

///
trait API extends super.API with DateTimeImplicits
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ import scala.concurrent.duration._
class PgJson4sSupportSuite extends FunSuite {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgJson4sSupport
with array.PgArrayJdbcTypes {
/// for json support
override val pgjson = "jsonb"
type DOCType = text.Document
type DOCType = org.json4s.native.Document
override val jsonMethods = org.json4s.native.JsonMethods.asInstanceOf[JsonMethods[DOCType]]

override val api = new API with JsonImplicits {
override val api: API = new API {}

val plainAPI = new API with Json4sJsonPlainImplicits

///
trait API extends super.API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val json4sJsonArrayTypeMapper =
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)
).to(_.toList)
}

val plainAPI = new API with Json4sJsonPlainImplicits
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import scala.concurrent.duration._
class PgPostGISSupportSuite extends FunSuite {
implicit val testExecContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4))

object MyPostgresProfile extends PostgresProfile with PgPostGISSupport {
trait MyPostgresProfile extends PostgresProfile with PgPostGISSupport {

override val api = new API with PostGISImplicits with PostGISAssistants
override val api: API = new API {}
val plainAPI = new API with PostGISPlainImplicits

///
val plainAPI = new API with PostGISPlainImplicits
trait API extends super.API with PostGISImplicits with PostGISAssistants
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ class PgPlayJsonSupportSuite extends FunSuite {
implicit val jbeanWrt = Json.writes[JBean]
}

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgPlayJsonSupport
with array.PgArrayJdbcTypes {
override val pgjson = "jsonb"

override val api = new API with JsonImplicits {
override val api: API = new API {}

val plainAPI = new API with PlayJsonPlainImplicits

///
trait API extends super.API with JsonImplicits {
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val beanJsonTypeMapper = MappedJdbcType.base[JBean, JsValue](Json.toJson(_), _.as[JBean])
implicit val jsonArrayTypeMapper =
Expand All @@ -37,9 +42,8 @@ class PgPlayJsonSupportSuite extends FunSuite {
(v) => utils.SimpleArrayUtils.mkString[JBean](b => Json.stringify(Json.toJson(b)))(v)
).to(_.toList)
}

val plainAPI = new API with PlayJsonPlainImplicits
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class PgSprayJsonSupportSuite extends FunSuite {
implicit val jbeanFormat = jsonFormat2(JBean)
}

object MyPostgresProfile extends PostgresProfile
trait MyPostgresProfile extends PostgresProfile
with PgSprayJsonSupport
with array.PgArrayJdbcTypes {
override val pgjson = "jsonb"

override val api = new API with JsonImplicits {
override val api: API = new API {}

val plainAPI = new API with SprayJsonPlainImplicits

///
trait API extends super.API with JsonImplicits {
import MyJsonProtocol._
implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val beanJsonTypeMapper = MappedJdbcType.base[JBean, JsValue](_.toJson, _.convertTo[JBean])
}

val plainAPI = new API with SprayJsonPlainImplicits
}
object MyPostgresProfile extends MyPostgresProfile

///
import MyPostgresProfile.api._
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ lazy val commonSettings = Seq(
organizationName := "slick-pg",
organization := "com.github.tminglei",
name := "slick-pg",
version := "0.15.0-M4",
version := "0.15.0-M3",

scalaVersion := "2.11.8",
scalaVersion := "2.12.1",
crossScalaVersions := Seq("2.11.8", "2.12.1"),
scalacOptions ++= Seq("-deprecation", "-feature",
"-language:implicitConversions",
Expand Down
22 changes: 12 additions & 10 deletions src/test/scala/com/github/tminglei/slickpg/MyPostgresProfile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ trait MyPostgresProfile extends ExPostgresProfile

override val pgjson = "jsonb"
///
override val api = new API with ArrayImplicits
with SimpleDateTimeImplicits
with DateTimeImplicits
with SimpleJsonImplicits
with NetImplicits
with LTreeImplicits
with RangeImplicits
with HStoreImplicits
with SearchImplicits
with SearchAssistants {}
override val api: API = new API {}

trait API extends super.API with ArrayImplicits
with SimpleDateTimeImplicits
with DateTimeImplicits
with SimpleJsonImplicits
with NetImplicits
with LTreeImplicits
with RangeImplicits
with HStoreImplicits
with SearchImplicits
with SearchAssistants
///
val plainAPI = new API with SimpleArrayPlainImplicits
with Date2DateTimePlainImplicits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class PgArraySupportSuite extends FunSuite {
case class Institution(value: Long)
case class MarketFinancialProduct(value: String)

object MyPostgresProfile1 extends ExPostgresProfile with PgArraySupport {
override val api = new API with ArrayImplicits with MyArrayImplicitsPlus {}
trait MyPostgresProfile1 extends ExPostgresProfile with PgArraySupport {
override val api: API = new API {}

///
trait MyArrayImplicitsPlus {
trait API extends super.API with ArrayImplicits {
implicit val simpleLongBufferTypeMapper = new SimpleArrayJdbcType[Long]("int8").to(_.toBuffer)
implicit val simpleStrVectorTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toVector)
implicit val institutionListTypeWrapper = new SimpleArrayJdbcType[Long]("int8")
Expand All @@ -33,6 +33,7 @@ class PgArraySupportSuite extends FunSuite {
fromString(identity)(_).orNull, mkString(identity))
}
}
object MyPostgresProfile1 extends MyPostgresProfile1

//////////////////////////////////////////////////////////////////////////
import MyPostgresProfile1.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package com.github.tminglei.slickpg
import org.postgresql.util.HStoreConverter
import org.scalatest.FunSuite
import slick.jdbc.{GetResult, PositionedResult, PostgresProfile}
import slick.lifted.RepShapeImplicits

import scala.collection.convert.{WrapAsJava, WrapAsScala}
import scala.reflect.runtime.{universe => u}
import java.sql.Timestamp
import java.text.SimpleDateFormat

Expand Down Expand Up @@ -41,17 +39,13 @@ object PgCompositeSupportSuite {
) extends Struct

//-------------------------------------------------------------
object MyPostgresProfile1 extends PostgresProfile with PgCompositeSupport with PgArraySupport with utils.PgCommonJdbcTypes {
override val api = new API with ArrayImplicits with CompositeImplicits {}

val plainImplicits = new API with CompositePlainImplicits {}

trait MyPostgresProfile1 extends PostgresProfile with PgCompositeSupport with PgArraySupport with utils.PgCommonJdbcTypes {
def mapToString(m: Map[String, String]): String = HStoreConverter.toString(WrapAsJava.mapAsJavaMap(m))
def stringToMap(s: String): Map[String, String] = WrapAsScala.mapAsScalaMap(HStoreConverter.fromString(s)
.asInstanceOf[java.util.Map[String, String]]).toMap

///
trait CompositeImplicits {
trait API extends super.API with ArrayImplicits {
utils.TypeConverters.register(PgRangeSupportUtils.mkRangeFn(ts))
utils.TypeConverters.register(PgRangeSupportUtils.toStringFn[Timestamp](tsFormat.format))
utils.TypeConverters.register(mapToString)
Expand All @@ -64,8 +58,9 @@ object PgCompositeSupportSuite {
implicit val composite2ArrayTypeMapper = createCompositeArrayJdbcType[Composite2]("composite2").to(_.toList)
implicit val composite3ArrayTypeMapper = createCompositeArrayJdbcType[Composite3]("composite3").to(_.toList)
}
override val api: API = new API {}

trait CompositePlainImplicits extends SimpleArrayPlainImplicits {
val plainImplicits = new API with SimpleArrayPlainImplicits {
import utils.PlainSQLUtils._
// to support 'nextArray[T]/nextArrayOption[T]' in PgArraySupport
{
Expand Down Expand Up @@ -96,6 +91,7 @@ object PgCompositeSupportSuite {
implicit val composite3ArrayOptSetParameter = createCompositeOptionArraySetParameter[Composite3]("composite3")
}
}
object MyPostgresProfile1 extends MyPostgresProfile1
}

///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class PgEnumSupportSuite extends FunSuite {
import WeekDays._
import Rainbows._

object MyPostgresProfile1 extends PostgresProfile with PgEnumSupport {
override val api = new API with MyEnumImplicits {}
trait MyPostgresProfile1 extends PostgresProfile with PgEnumSupport {

trait MyEnumImplicits {
override val api: API = new API {}

///
trait API extends super.API {
implicit val weekDayTypeMapper = createEnumJdbcType("WeekDay", WeekDays)
implicit val weekDayListTypeMapper = createEnumListJdbcType("weekDay", WeekDays)
implicit val rainbowTypeMapper = createEnumJdbcType("Rainbow", Rainbows, true)
Expand All @@ -76,6 +78,7 @@ class PgEnumSupportSuite extends FunSuite {
implicit val genderOptionColumnExtensionMethodsBuilder = createEnumOptionColumnExtensionMethodsBuilder[Gender]
}
}
object MyPostgresProfile1 extends MyPostgresProfile1

////////////////////////////////////////////////////////////////////
import MyPostgresProfile1.api._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.tminglei.slickpg
import java.util.UUID

import org.scalatest.FunSuite
import slick.backend.StaticDatabaseConfig
import slick.basic.StaticDatabaseConfig

/*
* NOTE: to check it, we need move `MyPostgresDriver.scala` from test folder to main folder
Expand Down

0 comments on commit 56ad9e0

Please sign in to comment.