This is a little Spring Boot application where my goal was to use purely JPA queries to enable queries of a labeled (key=value) resources in a SQL database.
Storing the key and value separately in the database and then querying them became impossible
(or at least very difficult). So, the solution cheats a little by textually combining the
key and value into a single string each using an =
delimiter. A
collection membership predicate
is supported for element collections that are lists of strings, so that was the predicate
the queries are built around.
POST localhost:8080/resource/_batch
[
{
"name": "red apple",
"labels": {
"fruit": "apple",
"color": "red"
}
},
{
"name": "green apple",
"labels": {
"fruit": "apple",
"color": "green"
}
},
{
"name": "yellow apple",
"labels": {
"fruit": "apple",
"color": "yellow"
}
},
{
"name": "green pear",
"labels": {
"fruit": "pear",
"color": "green"
}
}
]
GET localhost:8080/resource
DELETE localhost:8080/resource
POST localhost:8080/_query/resource
{
"labelSelectors": {
"fruit": "apple"
}
}