Skip to content

Commit 5dd6eb9

Browse files
authored
DAS-106 use new Postgres profile in devdashboard (#9)
1 parent 1c7b9e0 commit 5dd6eb9

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

slick-postgres-driver/src/main/scala/org/hatdex/libs/dal/HATPostgresProfile.scala

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import org.joda.time.DateTime
1515
import play.api.libs.json.{ JsValue, Json }
1616
import slick.jdbc.JdbcType
1717

18-
trait HATPostgresProfile extends ExPostgresProfile
18+
trait HATPostgresProfile
19+
extends ExPostgresProfile
1920
with PgArraySupport
2021
with PgDateSupportJoda
2122
with PgRangeSupport
@@ -27,9 +28,10 @@ trait HATPostgresProfile extends ExPostgresProfile
2728
override val api = new HatAPI {}
2829
override protected lazy val useTransactionForUpsert = false
2930

30-
trait HatAPI extends super.API
31+
trait HatAPI
32+
extends super.API
3133
with ArrayImplicits
32-
with DateTimeImplicits
34+
with JodaDateTimeImplicits
3335
with RangeImplicits
3436
with HStoreImplicits
3537
with SearchImplicits
@@ -39,39 +41,40 @@ trait HATPostgresProfile extends ExPostgresProfile
3941
implicit val playJsonArrayTypeMapper: DriverJdbcType[List[JsValue]] =
4042
new AdvancedArrayJdbcType[JsValue](
4143
pgjson,
42-
(s) => utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,
43-
(v) => utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)).to(_.toList)
44+
s => utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,
45+
v => utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)).to(_.toList)
4446

4547
import scala.language.implicitConversions
4648

47-
override implicit val playJsonTypeMapper: JdbcType[JsValue] =
49+
implicit override val playJsonTypeMapper: JdbcType[JsValue] =
4850
new GenericJdbcType[JsValue](
4951
pgjson,
50-
(v) => Json.parse(v),
51-
(v) => Json.stringify(v).replace("\\u0000", ""),
52+
v => Json.parse(v),
53+
v => Json.stringify(v).replace("\\u0000", ""),
5254
hasLiteralForm = false)
5355

54-
override implicit def playJsonColumnExtensionMethods(c: Rep[JsValue]): FixedJsonColumnExtensionMethods[JsValue, JsValue] = {
56+
implicit override def playJsonColumnExtensionMethods(
57+
c: Rep[JsValue]): FixedJsonColumnExtensionMethods[JsValue, JsValue] =
5558
new FixedJsonColumnExtensionMethods[JsValue, JsValue](c)
56-
}
57-
override implicit def playJsonOptionColumnExtensionMethods(c: Rep[Option[JsValue]]): FixedJsonColumnExtensionMethods[JsValue, Option[JsValue]] = {
59+
implicit override def playJsonOptionColumnExtensionMethods(
60+
c: Rep[Option[JsValue]]): FixedJsonColumnExtensionMethods[JsValue, Option[JsValue]] =
5861
new FixedJsonColumnExtensionMethods[JsValue, Option[JsValue]](c)
59-
}
6062

61-
class FixedJsonColumnExtensionMethods[JSONType, P1](override val c: Rep[P1])(
62-
implicit
63-
tm: JdbcType[JSONType]) extends JsonColumnExtensionMethods[JSONType, P1](c) {
64-
override def <@:[P2, R](c2: Rep[P2])(implicit om: o#arg[JSONType, P2]#to[Boolean, R]) = {
63+
class FixedJsonColumnExtensionMethods[JSONType, P1](
64+
override val c: Rep[P1])(implicit tm: JdbcType[JSONType])
65+
extends JsonColumnExtensionMethods[JSONType, P1](c) {
66+
override def <@:[P2, R](c2: Rep[P2])(implicit om: o#arg[JSONType, P2]#to[Boolean, R]) =
6567
om.column(jsonLib.ContainsBy, n, c2.toNode)
66-
}
6768
}
6869

6970
val toJson: Rep[String] => Rep[JsValue] = SimpleFunction.unary[String, JsValue]("to_jsonb")
7071
def toJsonGeneric[T]: Rep[T] => Rep[JsValue] = SimpleFunction.unary[T, JsValue]("to_jsonb")
7172
def toJsonGenericOptional[T](c: Rep[T]) = SimpleFunction[Option[JsValue]]("to_jsonb").apply(Seq(c))
7273
val toTimestamp: Rep[Double] => Rep[Timestamp] = SimpleFunction.unary[Double, Timestamp]("to_timestamp")
73-
val datePart: (Rep[String], Rep[DateTime]) => Rep[String] = SimpleFunction.binary[String, DateTime, String]("date_part")
74-
val datePartTimestamp: (Rep[String], Rep[Timestamp]) => Rep[String] = SimpleFunction.binary[String, Timestamp, String]("date_part")
74+
val datePart: (Rep[String], Rep[DateTime]) => Rep[String] =
75+
SimpleFunction.binary[String, DateTime, String]("date_part")
76+
val datePartTimestamp: (Rep[String], Rep[Timestamp]) => Rep[String] =
77+
SimpleFunction.binary[String, Timestamp, String]("date_part")
7578
}
7679

7780
}

0 commit comments

Comments
 (0)