Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

This library brings the convenience of SQL declarative nature to restful APIs in the form of RSQL but without the danger of sql injection by using a typesafe mapping of allowed field paths defined via integration with querydsl library. Like sql, it supports clauses such as select, filter, pagination and sorting that can easily be represented in …

License

NotificationsYou must be signed in to change notification settings

vineey/archelix-rsql

Repository files navigation

Author : John Michael Vincent S. Rustia

Build StatusLicenseCoverage StatusCodacy code qualityMaven CentralGitter

This library brings the convenience of SQL declarative nature to restful APIs in the form of RSQLbut without the danger of sql injection by using a typesafe mapping of allowed field paths definedvia integration with querydsl library. Like sql, it supports clauses such as select, filter, paginationand sorting that can easily be represented in http request parameters.

It primarily supports JPA model and MongoDB query via Querydsl. This is a small project but at its heartis dedicated to maintain highly cohesive and modular components. Contributions and suggestions are verymuch welcome and appreciated!

QueryDSL API Modules

Rql specification used by this library is defined by thisreference andrsql-parser.
Please see for more information about rql expressions.

  • select - converts rql select expression into its querydsl projection equivalent

  • filter - usesrsql-parser library ast to convert filter string into its querydsl predicate equivalent

  • page - converts rql limit expression into its querydsl pagination equivalent

  • sort - converts rql sort expression into its querydsl sorting equivalent

  • spring - provides integration with spring data such as pageable

2.0.0.RELEASE Notes

#13 Ported rsql-querydsl v1.0.0.RELEASE code to v2.0.0 branch to be compatible with querydsl latest version v4.x.x.
1.0.0.RELEASE and 2.0.0 will be simultaneous releases.

Contributions:

  • Thanks@natros for pointing me on this direction, hence a simultaneous 2.0.0.RELEASE

  • ThanksWallace Wadge for your effort in delivering this task, you are awesome!

1.0.0.RELEASE Notes

Completes filter conversion to querydsl predicate.Completes sort and page conversion for rsql querydsl
Completes select conversion to querydsl projections.
Full support on Mongodb projection, filter, sort and page conversion.

NEXT MILESTONES

2.1.0 and 1.1.0 Milestones

  • Add support for embeddable or nested Querydsl Paths

  • Add support for JPA Association Paths (OneToMany, ManyToOne)

Rsql-JOOQ Milestones

  • Support for rsql conversion toJOOQ Library

MAVEN

Bundled Rsql Querydsl Modules

You can get all rsql-querydsl modules via this dependency,

For Querydsl 3.x.x, use 1.0.0.RELEASE
For Querydsl 4.x.x, use 2.0.0.RELEASE

<dependency>    <groupId>com.github.vineey</groupId>    <artifactId>rsql-querydsl-all</artifactId>    <version>2.0.0.RELEASE</version></dependency>
dependencies {    compile'com.github.vineey:rsql-querydsl-all:2.0.0.RELEASE'  }

Selective Rsql Querydsl Modules

or you can specify which module you only need by changing the artifactId by any of the ff:

  • rsql-querydsl-select

  • rsql-querydsl-filter

  • rsql-querydsl-sort

  • rsql-querydsl-page

such as

dependencies {    compile'com.github.vineey:rsql-querydsl-filter:2.0.0.RELEASE'  }

To integrate with Spring Data Pageable, include this dependency,

dependencies {    compile'com.github.vineey:rsql-querydsl-spring:2.0.0.RELEASE'  }

Minimum JDK Required

  • Java 8 (will try to support Java 7 in the next release by externalizing Java 8 DateTime converters)

Querydsl Integration Dependencies Required

  • com.mysema.querydsl:querydsl-core:3.x.x or prior for rsql-querydsl 1.x.x.RELEASE

  • com.querydsl:querydsl-core:4.x.x or latest for rsql-querydsl 2.x.x.RELEASE

Spring Integration Dependencies Required

  • org.springframework.data:spring-data-commons:1.x.x or latest

API DOCS

Querydsl Filter (rsql-querydsl-filter)

Note: AOTM, this only supports first level fields of the entity or document. But will support embeddable pojoand other kinds of nested querydsl path.

Sample operators

     equals is ==           e.g. field == 'value'     not equals is !=            e.g. field != 'value'     like is =*            startsWith e.g.  field == 'value*'            endsWith   e.g.  field == '*value'            contains   e.g.  field == '*value*'
DefaultFilterParserfilterParser =newDefaultFilterParser();StringrqlFilter ="employee.name == 'John'";Map<String,Path>pathHashMap =ImmutableMap.<String,Path>builder()                .put("employee.name",QEmployee.employee.name)                .put("employee.age",QEmployee.employee.age)                .put("employee.bday",QEmployee.employee.birthDate)                .build();Predicatepredicate =filterParser.parse(rsqlFilter,withBuilderAndParam(newQuerydslFilterBuilder(),newQuerydslFilterParam()                                                                             .setMapping(pathHashMap)));//or a shorter versionPredicatepredicate =filterParser.parse(rsqlFilter,withMapping(pathHashMap));

Querydsl Select Conversion (rsql-querydsl-select)

Note: AOTM, this only supports first level fields of the entity or document. But will support embeddable pojoand other kinds of nested querydsl path.

//e.g. select(field1, field2,...)StringrqlSelectExpression ="select(contact.company, contact.name, contact.age)";DefaultSelectParserselectParser =newDefaultSelectParser();Map<String,Path>mappings =ImmutableMap.<String,Path>builder()        .put("contact.age",QContactDocument.contactDocument.age)        .put("contact.name",QContactDocument.contactDocument.name)        .put("contact.bday",QContactDocument.contactDocument.bday)        .put("contact.company",QContactDocument.contactDocument.company)        .build();Expressionprojection =selectParser.parse(rqlSelectExpression,QuerydslSelectContext.withMapping(QContactDocument.contactDocument,mappings));

Querydsl Sort Conversion (rsql-querydsl-sort)

Note: AOTM, this only supports first level fields of the entity or document. But will support embeddable pojoand other kinds of nested querydsl path.

//ascending is +, descending is -//e.g. sort(+field1, -field2,...)StringsortExpression ="sort(+employeeNumber)";DefaultSortParsersortParser =newDefaultSortParser();Map<String,Path>mappings =ImmutableMap.<String,Path>builder()        .put("employeeNumber",QEmployee.employee.employeeNumber)        .build();OrderSpecifierListorderSpecifierList =sortParser.parse(sortExpression,QuerydslSortContext.withMapping(mappings));List<OrderSpecifier>orderSpecifiers =orderSpecifierList.getOrders();

Querydsl Page Conversion (rsql-querydsl-page)

//limit(<offset>, <size>)StringrqlPage ="limit(10, 5)";DefaultPageParserdefaultPageParser =newDefaultPageParser();QueryModifiersquerydslPage =defaultPageParser.parse(rqlPage,withDefault());orasimplifiedversionQuerydslPageParserquerydslPageParser =newQuerydslPageParser();QueryModifiersquerydslPage =querydslPageParser.parse(rqlPage);

Bundled All Querydsl Modules (rsql-querydsl-all)

StringrqlSelect ="select(contact.name, contact.age)";StringrqlFilter ="(contact.age =='1' and contact.name == 'A*') or (contact.age > '1'  and contact.bday == '2015-05-05')";Stringlimit ="limit(0, 10)";Stringsort ="sort(+contact.name)";RqlInputrqlInput =newRqlInput()        .setSelect(rqlSelect)        .setFilter(rqlFilter)        .setLimit(limit)        .setSort(sort);Map<String ,Path>pathMapping =ImmutableMap.<String,Path>builder()        .put("contact.name",QContactDocument.contactDocument.name)        .put("contact.age",QContactDocument.contactDocument.age)        .put("contact.bday",QContactDocument.contactDocument.bday)        .build();QuerydslMappingResultquerydslMappingResult =querydslRqlParser.parse(rqlInput,newQuerydslMappingParam().setRootPath(QContactDocument.contactDocument).setPathMapping(pathMapping));ExpressionselectExpression =querydslMappingResult.getProjection();Predicatepredicate =querydslMappingResult.getPredicate();QueryModifiersquerydslPage =querydslMappingResult.getPage();List<OrderSpecifier>orderSpecifiers =querydslMappingResult.getOrderSpecifiers();

Integration of Querydsl to Spring Data Pageable

Pageablepageable =SpringUtil.toPageable(orderSpecifiers,querydslPage);

You can now use Expression, Predicate, QueryModifiers, OrderSpecifier or Pageable
in the Querydsl API, or in JPAQuery,
or in the Spring Data JPA/Mongo Repository.

A MORE APPROPRIATE WIKI

To be follow!!!

About

This library brings the convenience of SQL declarative nature to restful APIs in the form of RSQL but without the danger of sql injection by using a typesafe mapping of allowed field paths defined via integration with querydsl library. Like sql, it supports clauses such as select, filter, pagination and sorting that can easily be represented in …

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp