Skip to content

Commit 4e1cac4

Browse files
b-gyulajuliano
andauthored
Add default array en/decoder support to the H2 JdbcContext (#3269)
* - Added support for onConflictIgnore to H2 (v1.4.200 in PostgreSQL mode) - Doc updated with database actions return values * Add default array en/decoder support to the H2 JdbcContext --------- Co-authored-by: Juliano Alves <von.juliano@gmail.com>
1 parent 9c263c2 commit 4e1cac4

3 files changed

Lines changed: 59 additions & 17 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.getquill.context.jdbc.h2
2+
3+
import io.getquill.context.sql.encoding.ArrayEncodingBaseSpec
4+
5+
import java.sql.Timestamp
6+
7+
class ArrayJdbcEncodingSpec extends ArrayEncodingBaseSpec {
8+
val ctx = testContext
9+
import ctx._
10+
11+
val q = quote(query[ArraysTestEntity])
12+
val corrected = e.copy(timestamps = e.timestamps.map(d => new Timestamp(d.getTime)))
13+
14+
override protected def beforeEach(): Unit = {
15+
ctx.run(q.delete)
16+
()
17+
}
18+
19+
"Support all sql base types and `Seq` implementers" in {
20+
ctx.run(q.insertValue(lift(corrected)))
21+
val actual = ctx.run(q).head
22+
actual mustEqual corrected
23+
baseEntityDeepCheck(actual, corrected)
24+
}
25+
26+
"Support Seq encoding basing on MappedEncoding" in {
27+
val wrapQ = quote(querySchema[WrapEntity]("ArraysTestEntity"))
28+
ctx.run(wrapQ.insertValue(lift(wrapE)))
29+
ctx.run(wrapQ).head.texts mustBe wrapE.texts
30+
}
31+
32+
"empty array on found null" in {
33+
case class ArraysTestEntity(texts: Option[List[String]])
34+
ctx.run(query[ArraysTestEntity].insertValue(lift(ArraysTestEntity(None))))
35+
36+
case class E(texts: List[String])
37+
ctx.run(querySchema[E]("ArraysTestEntity")).headOption.map(_.texts) mustBe Some(Nil)
38+
}
39+
40+
}

quill-jdbc/src/main/scala/io/getquill/context/jdbc/SimplifiedContexts.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ trait H2JdbcTypes[+D <: H2Dialect, +N <: NamingStrategy]
3232
with ObjectGenericTimeEncoders
3333
with ObjectGenericTimeDecoders
3434
with BooleanObjectEncoding
35-
with UUIDObjectEncoding {
35+
with UUIDObjectEncoding
36+
with ArrayDecoders
37+
with ArrayEncoders {
3638

3739
val idiom: D
3840
}

quill-jdbc/src/test/resources/sql/h2-schema.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS Task(
2323
tsk VARCHAR(255)
2424
);
2525

26-
CREATE TABLE TimeEntity(
26+
CREATE TABLE IF NOT EXISTS TimeEntity(
2727
sqlDate DATE, -- java.sql.Date
2828
sqlTime TIME, -- java.sql.Time
2929
sqlTimestamp TIMESTAMP, -- java.sql.Timestamp
@@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS EncodingTestEntity(
4646
v6 INTEGER,
4747
v7 BIGINT,
4848
v8 FLOAT,
49-
v9 DOUBLE PRECISIOn,
49+
v9 DOUBLE PRECISION,
5050
v10 BYTEA,
5151
v11 TIMESTAMP,
5252
v12 VARCHAR(255),
@@ -60,7 +60,7 @@ CREATE TABLE IF NOT EXISTS EncodingTestEntity(
6060
o6 INTEGER,
6161
o7 BIGINT,
6262
o8 FLOAT,
63-
o9 DOUBLE PRECISIOn,
63+
o9 DOUBLE PRECISION,
6464
o10 BYTEA,
6565
o11 TIMESTAMP,
6666
o12 VARCHAR(255),
@@ -99,19 +99,19 @@ CREATE TABLE IF NOT EXISTS Product(
9999
sku BIGINT
100100
);
101101

102-
CREATE TABLE IF NOT EXISTS Contact(
103-
firstName VARCHAR(255),
104-
lastName VARCHAR(255),
105-
age int,
106-
addressFk int,
107-
extraInfo VARCHAR(255)
108-
);
109-
110-
CREATE TABLE IF NOT EXISTS Address(
111-
id int,
112-
street VARCHAR(255),
113-
zip int,
114-
otherExtraInfo VARCHAR(255)
102+
CREATE TABLE IF NOT EXISTS ArraysTestEntity (
103+
texts VARCHAR(255) ARRAY,
104+
decimals DECIMAL(5,2) ARRAY,
105+
bools BOOLEAN ARRAY,
106+
bytes TINYINT ARRAY,
107+
shorts SMALLINT ARRAY,
108+
ints INT ARRAY,
109+
longs BIGINT ARRAY,
110+
floats FLOAT ARRAY,
111+
doubles DOUBLE PRECISION ARRAY,
112+
timestamps TIMESTAMP ARRAY,
113+
dates DATE ARRAY,
114+
uuids UUID ARRAY
115115
);
116116

117117
CREATE TABLE IF NOT EXISTS Contact(

0 commit comments

Comments
 (0)