Skip to content

Commit db76d5c

Browse files
committed
Test only - add Postgres JSONB raw() expression example
1 parent f92c2f8 commit db76d5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ebean-test/src/test/java/org/tests/json/TestDbJsonBStringType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tests.json;
22

33
import io.ebean.DB;
4+
import io.ebean.annotation.Platform;
45
import io.ebean.test.LoggedSql;
56
import org.junit.jupiter.api.Test;
67
import org.tests.model.json.EBasicJsonBString;
@@ -38,10 +39,21 @@ void test() {
3839

3940

4041
// change content only
41-
found.content("{\"mykey\": 95}");
42+
found.content("{\"mykey\": 95, \"other\": \"AI\"}");
4243
DB.save(found);
4344
sql = LoggedSql.stop();
4445
assertThat(sql.get(0)).contains("update ebasic_json_bstring set content=?, version=? where id=? and version=?");
4546

47+
48+
if (DB.getDefault().platform() == Platform.POSTGRES) {
49+
List<EBasicJsonBString> result = DB.find(EBasicJsonBString.class)
50+
.where()
51+
.raw("content -> 'other' ?? ?", "AI")
52+
.raw("jsonb_exists(content -> 'other', ?)", "AI")
53+
.raw("jsonb_path_exists(content, '$.other ? (@ >= $param)', '{\"param\":\"AI\"}')")
54+
.findList();
55+
56+
assertThat(result).hasSize(1);
57+
}
4658
}
4759
}

0 commit comments

Comments
 (0)