From a70cf808c2308a15c79c3314eec2f0dc6ca24c46 Mon Sep 17 00:00:00 2001 From: Minglei Tu Date: Sun, 10 Aug 2014 08:45:37 +0800 Subject: [PATCH] allow to bind multiple scala types to json extension methods --- .../com/github/tminglei/slickpg/PgArgonautSupport.scala | 6 ++---- .../scala/com/github/tminglei/slickpg/PgJson4sSupport.scala | 5 ++--- .../com/github/tminglei/slickpg/PgPlayJsonSupport.scala | 6 ++---- .../com/github/tminglei/slickpg/PgSprayJsonSupport.scala | 6 ++---- .../com/github/tminglei/slickpg/json/PgJsonExtensions.scala | 4 +--- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/addons/argonaut/src/main/scala/com/github/tminglei/slickpg/PgArgonautSupport.scala b/addons/argonaut/src/main/scala/com/github/tminglei/slickpg/PgArgonautSupport.scala index dc35f421..c80ed086 100644 --- a/addons/argonaut/src/main/scala/com/github/tminglei/slickpg/PgArgonautSupport.scala +++ b/addons/argonaut/src/main/scala/com/github/tminglei/slickpg/PgArgonautSupport.scala @@ -7,8 +7,6 @@ import scala.slick.jdbc.JdbcType trait PgArgonautSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresDriver => import argonaut._, Argonaut._ - type JSONType = argonaut.Json - trait JsonImplicits { implicit val jsonTypeMapper = new GenericJdbcType[Json]( @@ -20,11 +18,11 @@ trait PgArgonautSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp implicit def jsonColumnExtensionMethods(c: Column[Json])( implicit tm: JdbcType[Json], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[Json](c) + new JsonColumnExtensionMethods[Json, Json](c) } implicit def jsonOptionColumnExtensionMethods(c: Column[Option[Json]])( implicit tm: JdbcType[Json], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[Option[Json]](c) + new JsonColumnExtensionMethods[Json, Option[Json]](c) } } } diff --git a/addons/json4s/src/main/scala/com/github/tminglei/slickpg/PgJson4sSupport.scala b/addons/json4s/src/main/scala/com/github/tminglei/slickpg/PgJson4sSupport.scala index ae9aa0c5..296c1489 100644 --- a/addons/json4s/src/main/scala/com/github/tminglei/slickpg/PgJson4sSupport.scala +++ b/addons/json4s/src/main/scala/com/github/tminglei/slickpg/PgJson4sSupport.scala @@ -8,7 +8,6 @@ trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes import org.json4s._ type DOCType - type JSONType = JValue val jsonMethods: JsonMethods[DOCType] @@ -23,11 +22,11 @@ trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes implicit def jsonColumnExtensionMethods(c: Column[JValue])( implicit tm: JdbcType[JValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[JValue](c) + new JsonColumnExtensionMethods[JValue, JValue](c) } implicit def jsonOptionColumnExtensionMethods(c: Column[Option[JValue]])( implicit tm: JdbcType[JValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[Option[JValue]](c) + new JsonColumnExtensionMethods[JValue, Option[JValue]](c) } } } diff --git a/addons/play-json/src/main/scala/com/github/tminglei/slickpg/PgPlayJsonSupport.scala b/addons/play-json/src/main/scala/com/github/tminglei/slickpg/PgPlayJsonSupport.scala index ad88ad29..0fe25607 100644 --- a/addons/play-json/src/main/scala/com/github/tminglei/slickpg/PgPlayJsonSupport.scala +++ b/addons/play-json/src/main/scala/com/github/tminglei/slickpg/PgPlayJsonSupport.scala @@ -7,8 +7,6 @@ import scala.slick.jdbc.JdbcType trait PgPlayJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresDriver => import play.api.libs.json._ - type JSONType = JsValue - trait JsonImplicits { implicit val jsonTypeMapper = new GenericJdbcType[JsValue]("json", @@ -19,11 +17,11 @@ trait PgPlayJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp implicit def jsonColumnExtensionMethods(c: Column[JsValue])( implicit tm: JdbcType[JsValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[JsValue](c) + new JsonColumnExtensionMethods[JsValue, JsValue](c) } implicit def jsonOptionColumnExtensionMethods(c: Column[Option[JsValue]])( implicit tm: JdbcType[JsValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[Option[JsValue]](c) + new JsonColumnExtensionMethods[JsValue, Option[JsValue]](c) } } } \ No newline at end of file diff --git a/addons/spray-json/src/main/scala/com/github/tminglei/slickpg/PgSprayJsonSupport.scala b/addons/spray-json/src/main/scala/com/github/tminglei/slickpg/PgSprayJsonSupport.scala index 48572044..a657a62c 100644 --- a/addons/spray-json/src/main/scala/com/github/tminglei/slickpg/PgSprayJsonSupport.scala +++ b/addons/spray-json/src/main/scala/com/github/tminglei/slickpg/PgSprayJsonSupport.scala @@ -8,8 +8,6 @@ trait PgSprayJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTy import spray.json._ import DefaultJsonProtocol._ // !!! IMPORTANT, otherwise `convertTo` and `toJson` won't work correctly. - type JSONType = JsValue - trait JsonImplicits { implicit val jsonTypeMapper = new GenericJdbcType[JsValue]( @@ -21,11 +19,11 @@ trait PgSprayJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTy implicit def jsonColumnExtensionMethods(c: Column[JsValue])( implicit tm: JdbcType[JsValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[JsValue](c) + new JsonColumnExtensionMethods[JsValue, JsValue](c) } implicit def jsonOptionColumnExtensionMethods(c: Column[Option[JsValue]])( implicit tm: JdbcType[JsValue], tm1: JdbcType[List[String]]) = { - new JsonColumnExtensionMethods[Option[JsValue]](c) + new JsonColumnExtensionMethods[JsValue, Option[JsValue]](c) } } } diff --git a/core/src/main/scala/com/github/tminglei/slickpg/json/PgJsonExtensions.scala b/core/src/main/scala/com/github/tminglei/slickpg/json/PgJsonExtensions.scala index e537fb95..56ae691a 100644 --- a/core/src/main/scala/com/github/tminglei/slickpg/json/PgJsonExtensions.scala +++ b/core/src/main/scala/com/github/tminglei/slickpg/json/PgJsonExtensions.scala @@ -9,8 +9,6 @@ import scala.slick.jdbc.JdbcType trait PgJsonExtensions extends JdbcTypesComponent { driver: PostgresDriver => import driver.Implicit._ - type JSONType - object JsonLibrary { val Arrow = new SqlOperator("->") val BiArrow = new SqlOperator("->>") @@ -27,7 +25,7 @@ trait PgJsonExtensions extends JdbcTypesComponent { driver: PostgresDriver => // val jsonPopulateRecordset = new SqlFunction("json_populate_recordset") //not support, since "row" type not supported by slick/slick-pg yet } - class JsonColumnExtensionMethods[P1](val c: Column[P1])( + class JsonColumnExtensionMethods[JSONType, P1](val c: Column[P1])( implicit tm: JdbcType[JSONType], tm1: JdbcType[List[String]]) extends ExtensionMethods[JSONType, P1] { /** Note: json array's index starts with 0 */