Integration RSQL query language and Querydsl framework.
@Test
fun shouldReturnTupleWithLimitNumber() {
val clazz = Car::class.java
val pathBuilder = pathFactory.create(clazz)
val selectFields = RsqlUtil.parseSelect("name,description", pathBuilder).toTypedArray()
val select = Projections.bean(
clazz,
pathBuilder.getNumber("id", Long::class.java).add(1000).`as`("id"),
*selectFields,
)
val rsqlConfig = RsqlConfig.Builder(entityManager).build()
val querydslRsql = QuerydslRsql.Builder<Car>(rsqlConfig)
.select(select)
// .from(clazz)
.where("id=notnull='' and (name=like='%a%' or name=con='Béla2,Béla11')")
.sort("id.desc")
.limit(15L, 15)
.build()
val cars = querydslRsql.buildJPAQuery(pathBuilder).fetch()
assertFalse(cars.isEmpty(), "Can't handle limit expression")
assertEquals(15, cars.size, "Can't handle limit expression")
}
// will generate SQL:
// select car0_.id+? as col_0_0_,
// car0_.name as col_1_0_,
// car0_.description as col_2_0_
// from car car0_
// where (car0_.id is not null) and (car0_.name like ? escape '!' or car0_.name like ? escape '!')
// order by car0_.id desc
// limit ?
// offset ?
//
// binding parameter [1] as [BIGINT] - [1000]
// binding parameter [2] as [VARCHAR] - [%a%]
// binding parameter [3] as [VARCHAR] - [%Béla2,Béla11%]
For more usage, please refer to https://ymind.github.io/rsql-querydsl
@ymind, full stack engineer.
This is open-sourced software licensed under the MIT license.