Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Aug 8, 2015
1 parent 8c2caae commit 84d6b09
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.github.tminglei.slickpg
package utils
package com.github.tminglei.slickpg.utils

import scala.reflect.ClassTag
import slick.jdbc.{GetResult, PositionedResult, SetParameter, PositionedParameters}
Expand All @@ -14,7 +13,8 @@ object PlainSQLUtils {
println(s"[info]\u001B[36m >>> adding next array converter for ${u.typeOf[T]} \u001B[0m")
val existed = nextArrayConverters.get(u.typeOf[T])
if (existed.isDefined) new RuntimeException(
s"\u001B[31m[warn] >>> DUPLICATED BINDING for ${u.typeOf[T]}!!!\u001B[0m").printStackTrace()
s"\u001B[31m[warn] >>> DUPLICATED converter for ${u.typeOf[T]}!!! \u001B[36m If it's expected, pls ignore it.\u001B[0m"
).printStackTrace()
nextArrayConverters += (u.typeOf[T] -> conv)
}

Expand All @@ -38,7 +38,7 @@ object PlainSQLUtils {

private def internalSet[T](sqlType: Int, typeName: String, v: Option[T], p: PositionedParameters, toStr: (T => String)) =
v match {
case Some(v) => p.setObject(utils.mkPGobject(typeName, toStr(v)), java.sql.Types.OTHER)
case Some(v) => p.setObject(mkPGobject(typeName, toStr(v)), java.sql.Types.OTHER)
case None => p.setNull(sqlType)
}

Expand Down
31 changes: 3 additions & 28 deletions src/test/scala/com/github/tminglei/slickpg/MyPostgresDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,14 @@ trait MyPostgresDriver extends ExPostgresDriver
with HStoreImplicits
with SearchImplicits
with SearchAssistants {}
}

object MyPostgresDriver extends MyPostgresDriver

/// for plain sql tests
import slick.driver.PostgresDriver
import scala.reflect.runtime.{universe => u}
import slick.jdbc.PositionedResult

import utils.SimpleArrayUtils._

object MyPlainPostgresDriver extends PostgresDriver
with PgArraySupport
with PgJsonSupport
with PgNetSupport
with PgLTreeSupport
with PgRangeSupport
with PgHStoreSupport
with PgSearchSupport {
override val pgjson = "jsonb"
///
val plainAPI = new API with SimpleArrayPlainImplicits
with SimpleJsonPlainImplicits
with SimpleNetPlainImplicits
with SimpleLTreePlainImplicits
with SimpleRangePlainImplicits
with SimpleHStorePlainImplicits
with SimpleSearchPlainImplicits {
override protected def extNextArray(tpe: u.Type, r: PositionedResult): (Boolean, Option[Seq[_]]) =
tpe match {
case tpe if tpe.typeConstructor =:= u.typeOf[LTree].typeConstructor =>
(true, r.nextStringOption().flatMap(fromString(LTree.apply)))
case _ => super.extNextArray(tpe, r)
}
}
with SimpleSearchPlainImplicits {}
}

object MyPostgresDriver extends MyPostgresDriver
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class PgArraySupportSuite extends FunSuite {
)

test("Array Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

implicit val getArrarBean1Result = GetResult(r =>
ArrayBean1(r.nextLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PgHStoreSupportSuite extends FunSuite {
//------------------------------------------------------------------------------

test("Hstore Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

implicit val getMapBeanResult = GetResult(r => MapBean(r.nextLong(), r.nextHStore()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class PgJsonSupportSuite extends FunSuite {
//------------------------------------------------------------------------------

test("Json Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

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

Expand All @@ -128,7 +128,7 @@ class PgJsonSupportSuite extends FunSuite {
DBIO.seq(
sqlu"""create table JsonTest0(
id int8 not null primary key,
json #${MyPlainPostgresDriver.pgjson} not null)
json #${MyPostgresDriver.pgjson} not null)
""",
///
sqlu""" insert into JsonTest0 values(${b.id}, ${b.json}) """,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class PgLTreeSupportSuite extends FunSuite {
//------------------------------------------------------------------------------

test("Ltree Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

implicit val getLTreeBeanResult = GetResult(r => LTreeBean(r.nextLong(), r.nextLTree(), r.nextArray[LTree]().toList))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class PgNetSupportSuite extends FunSuite {
//------------------------------------------------------------------------------

test("net Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

implicit val getNetBeanResult = GetResult(r => NetBean(r.nextLong(), r.nextIPAddr(), r.nextMacAddrOption()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PgRangeSupportSuite extends FunSuite {
//////////////////////////////////////////////////////////////////////

test("Range Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

implicit val getRangeBeanResult = GetResult(r =>
RangeBean(r.nextLong(), r.nextIntRange(), r.nextFloatRange(), r.nextTimestampRangeOption()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class PgSearchSupportSuite extends FunSuite {
//--------------------------------------------------------------------------------

test("Text search Plain SQL support") {
import MyPlainPostgresDriver.plainAPI._
import MyPostgresDriver.plainAPI._

case class SearchBean(id: Long, tVec: TsVector, tQ: TsQuery)

Expand Down

0 comments on commit 84d6b09

Please sign in to comment.