Skip to content

Commit

Permalink
Fix array of uuid on pg
Browse files Browse the repository at this point in the history
  • Loading branch information
sake92 committed Sep 6, 2024
1 parent 4926a03 commit 285f771
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions generator/src/ba/sake/squery/generator/SqueryGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ class SqueryGenerator(ds: DataSource, config: SqueryGeneratorConfig = SqueryGene
q"import java.time.*",
q"import java.util.UUID",
q"import ba.sake.squery.{*, given}",
q"import ..${List(dbSpecificImporter)}",
q"import ba.sake.squery.read.{*, given}",
q"import ba.sake.squery.write.{*, given}"
q"import ba.sake.squery.write.{*, given}",
q"import ..${List(dbSpecificImporter)}"
)
}
private def generateDaoImports(dbType: DbType, basePackage: String) = {
Expand Down
2 changes: 2 additions & 0 deletions squery/src/ba/sake/squery/SqlNonScalarType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ trait SqlNonScalarType[T]

given [T]: SqlNonScalarType[Array[T]] = new {}
given [T]: SqlNonScalarType[Seq[T]] = new {}
given [T]: SqlNonScalarType[List[T]] = new {}
given [T]: SqlNonScalarType[Vector[T]] = new {}
2 changes: 1 addition & 1 deletion squery/src/ba/sake/squery/postgres/typeNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package ba.sake.squery.postgres
import ba.sake.squery.write.SqlTypeName
import java.util.UUID

given SqlTypeName[Array[UUID]] with {
given SqlTypeName[UUID] with {
def value: String = "UUID"
}
16 changes: 10 additions & 6 deletions squery/test/src/ba/sake/squery/postgres/PostgresSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ case class Datatypes(
d_array_int: Option[Vector[Int]],
d_array_array_int: Option[Vector[Vector[Int]]],
d_array_str: Option[Vector[String]],
d_array_array_str: Option[Vector[Vector[String]]]
d_array_array_str: Option[Vector[Vector[String]]],
d_array_uuid: Option[Vector[UUID]]
) derives SqlReadRow:

def insertTuple =
sql"""(${d_int}, ${d_long}, ${d_double}, ${d_boolean}, ${d_string}, ${d_uuid}, ${d_tstz}, ${d_clr},
${d_array_bytes}, ${d_array_int}, ${d_array_array_int}, ${d_array_str}, ${d_array_array_str}
${d_array_bytes}, ${d_array_int}, ${d_array_array_int}, ${d_array_str}, ${d_array_array_str}, ${d_array_uuid}
)"""

object Datatypes:
inline val allCols =
"d_int, d_long, d_double, d_boolean, d_string, d_uuid, d_tstz, d_clr, d_array_bytes, d_array_int, d_array_array_int, d_array_str, d_array_array_str"
"d_int, d_long, d_double, d_boolean, d_string, d_uuid, d_tstz, d_clr, d_array_bytes, d_array_int, d_array_array_int, d_array_str, d_array_array_str, d_array_uuid"

enum Color derives SqlRead, SqlWrite:
case red, green, blue
Expand Down Expand Up @@ -290,7 +291,8 @@ class PostgresSuite extends munit.FunSuite {
d_array_int INTEGER[],
d_array_array_int INTEGER[][],
d_array_str VARCHAR[],
d_array_array_str VARCHAR[][]
d_array_array_str VARCHAR[][],
d_array_uuid uuid[]
)
""".update()
val dt1 = Datatypes(
Expand All @@ -306,9 +308,10 @@ class PostgresSuite extends munit.FunSuite {
Some(Vector(1, 2, 3)),
Some(Vector(Vector(1, 1, 1), Vector(2, 2, 2), Vector(3, 3, 3))),
Some(Vector("abc")),
Some(Vector(Vector("aaa"), Vector("bbb"), Vector("ccc")))
Some(Vector(Vector("aaa"), Vector("bbb"), Vector("ccc"))),
Some(Vector(UUID.randomUUID))
)
val dt2 = Datatypes(None, None, None, None, None, None, None, None, None, None, None, None, None)
val dt2 = Datatypes(None, None, None, None, None, None, None, None, None, None, None, None, None, None)

val values = Seq(dt1, dt2)
.map(_.insertTuple)
Expand Down Expand Up @@ -339,6 +342,7 @@ class PostgresSuite extends munit.FunSuite {
assertEquals(firstRow.d_array_array_int, dt1.d_array_array_int)
assertEquals(firstRow.d_array_str, dt1.d_array_str)
assertEquals(firstRow.d_array_array_str, dt1.d_array_array_str)
assertEquals(firstRow.d_array_uuid, dt1.d_array_uuid)
}
}

Expand Down

0 comments on commit 285f771

Please sign in to comment.