Skip to content

Commit

Permalink
Merge pull request #503 from tsipinio/master
Browse files Browse the repository at this point in the history
fix generating sql for arrays with custom types
  • Loading branch information
tminglei authored Mar 5, 2021
2 parents d9372f4 + 9f11181 commit f85634f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait PgArrayJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>

override def updateValue(vList: Seq[T], r: ResultSet, idx: Int): Unit = r.updateArray(idx, mkArray(vList))

override def valueToSQLLiteral(vList: Seq[T]) = if(vList eq null) "NULL" else s"'${buildArrayStr(vList)}'"
override def valueToSQLLiteral(vList: Seq[T]) = if(vList eq null) "NULL" else s"'${buildArrayStr(vList.map(tcomap))}'"

//--
protected def mkArray(v: Seq[T], conn: Option[Connection] = None): java.sql.Array = (v, conn) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class PgArraySupportSuite extends FunSuite {
implicit val longlongWitness = ElemWitness.AnyWitness.asInstanceOf[ElemWitness[List[Long]]]
implicit val simpleLongLongListTypeMapper = new SimpleArrayJdbcType[List[Long]]("int8[]")
.to(_.asInstanceOf[Seq[Array[Any]]].toList.map(_.toList.asInstanceOf[List[Long]]))

implicit val institutionTypeWrapper = MappedJdbcType.base[Institution, Long](_.value, Institution)
implicit val marketFinancialProductTypeWrapper = MappedJdbcType.base[MarketFinancialProduct, String](_.value, MarketFinancialProduct)
}
}
object MyPostgresProfile1 extends MyPostgresProfile1
Expand Down Expand Up @@ -125,13 +128,22 @@ class PgArraySupportSuite extends FunSuite {
ArrayTests.filter(_.strArr @> Vector("str3")).sortBy(_.id).to[List].result.map(
r => assert(List(testRec1, testRec2, testRec3) === r)
),
ArrayTests.filter(_.mktFinancialProducts @> List(MarketFinancialProduct("product1"))).sortBy(_.id).to[List].result.map(
r => assert(List(testRec2) === r)
),
ArrayTests.filter(_.institutions @> List(Institution(579))).sortBy(_.id).to[List].result.map(
r => assert(List(testRec2) === r)
),
ArrayTests.filter(_.strArr @> Vector("str3").bind).sortBy(_.id).to[List].result.map(
r => assert(List(testRec1, testRec2, testRec3) === r)
),
// <@
ArrayTests.filter(Vector("str3").bind <@: _.strArr).sortBy(_.id).to[List].result.map(
r => assert(List(testRec1, testRec2, testRec3) === r)
),
ArrayTests.filter(List(Institution(579)).bind <@: _.institutions).sortBy(_.id).to[List].result.map(
r => assert(List(testRec2) === r)
),
// &&
ArrayTests.filter(_.longArr @& Buffer(5L, 17L).bind).sortBy(_.id).to[List].result.map(
r => assert(List(testRec1, testRec2, testRec3) === r)
Expand Down

0 comments on commit f85634f

Please sign in to comment.