Skip to content

Commit

Permalink
allow to bind multiple scala types to json extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Aug 10, 2014
1 parent 0c8dc78 commit a70cf80
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes
import org.json4s._

type DOCType
type JSONType = JValue

val jsonMethods: JsonMethods[DOCType]

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("->>")
Expand All @@ -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 */
Expand Down

0 comments on commit a70cf80

Please sign in to comment.