All Projects → vineey → archelix-rsql

vineey / archelix-rsql

Licence: MIT license
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 …

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to archelix-rsql

weedow-searchy
Automatically exposes web services over HTTP to search for Entity-related data using a powerful query language
Stars: ✭ 21 (-40%)
Mutual labels:  spring-data, querydsl, spring-data-jpa, spring-data-mongodb
BusinessInfrastructurePlatformGroupVersion
A java web project based on Spring Boot using MySQL, Spring MVC, Hibernate, Spring Data JPA, Query DSL, Lombok, Logback, etc.
Stars: ✭ 90 (+157.14%)
Mutual labels:  spring-data, querydsl, spring-data-jpa
spring-boot-mongodb-example
Spring Boot Using Spring Data MongoDB Example
Stars: ✭ 36 (+2.86%)
Mutual labels:  spring-data, spring-data-jpa, spring-data-mongodb
Spring5Certification
Spring Certification: This repository contains my examples and some best references to prepare the Spring 5 certification
Stars: ✭ 30 (-14.29%)
Mutual labels:  spring-data, spring-data-jpa
hibernate-springcache
Hibernate cache implementation that backs to the Spring Cache abstraction
Stars: ✭ 19 (-45.71%)
Mutual labels:  spring-data, spring-data-jpa
Spring Petclinic Rest
REST version of the Spring Petclinic sample application
Stars: ✭ 257 (+634.29%)
Mutual labels:  spring-data, spring-data-jpa
Spring Mvc Thymeleaf Crud
Spring MVC CRUD Application with Thymeleaf, HTML5, CSS3 and Bootstrap
Stars: ✭ 14 (-60%)
Mutual labels:  spring-data, spring-data-jpa
Spring
Personal notes of preparation to Spring 5 Professional Certification
Stars: ✭ 35 (+0%)
Mutual labels:  spring-data, spring-data-jpa
Library
Online Library Management. User can search, check in, checkout book. System adds fines automatically if the book is not checked in by due date
Stars: ✭ 27 (-22.86%)
Mutual labels:  spring-data, spring-data-jpa
Spring Data Jpa Entity Graph
Spring Data JPA extension allowing full dynamic usage of EntityGraph on repositories
Stars: ✭ 221 (+531.43%)
Mutual labels:  spring-data, spring-data-jpa
Angularjs Springmvc Sample Boot
A RESTful sample using Spring Boot, Spring MVC, Spring Data and Angular/Bootstrap.
Stars: ✭ 309 (+782.86%)
Mutual labels:  spring-data, spring-data-jpa
Spring-Boot-2
Spring Boot 2.x examples
Stars: ✭ 33 (-5.71%)
Mutual labels:  spring-data, spring-data-jpa
Spring Examples
SpringBoot Examples
Stars: ✭ 67 (+91.43%)
Mutual labels:  spring-data, spring-data-jpa
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (+100%)
Mutual labels:  spring-data, spring-data-jpa
TASK-Management-System
Spring Boot and Angular 7 web application for task management .
Stars: ✭ 34 (-2.86%)
Mutual labels:  spring-data, spring-data-jpa
gro-light-automation
A raspberry pi project to automate hydroponics with relays and data sensors through a web application
Stars: ✭ 44 (+25.71%)
Mutual labels:  spring-data-jpa
q-builders
Type safe database agnostic query builders.
Stars: ✭ 49 (+40%)
Mutual labels:  rsql
spring-data-cosmosdb
Access data with Azure Cosmos DB
Stars: ✭ 94 (+168.57%)
Mutual labels:  spring-data
creek
使用Spring Security + JWT Token + RBAC的方式实现认证和授权,持久层使用Mybatis plus。避免每次重复编写认证和授权功能、角色管理、异常处理、参数校验等代码,直接上手业务代码,不再烦恼于构建项目与风格统一。
Stars: ✭ 21 (-40%)
Mutual labels:  spring-data-jpa
spring-boot-shop-sample
My first web application using Spring Boot framework.
Stars: ✭ 66 (+88.57%)
Mutual labels:  spring-data-jpa

RSQL-QueryDSL

Author : John Michael Vincent S. Rustia

Build Status License Coverage Status Codacy code quality Maven Central Gitter

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 http request parameters.

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

QueryDSL API Modules

Rql specification used by this library is defined by this reference and rsql-parser.
Please see for more information about rql expressions.

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

  • filter - uses rsql-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

  • Thanks Wallace 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 to JOOQ 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 pojo and 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*'
DefaultFilterParser filterParser = new DefaultFilterParser();

String rqlFilter = "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();

Predicate predicate = filterParser.parse(rsqlFilter, withBuilderAndParam(new QuerydslFilterBuilder(), new QuerydslFilterParam()
                                                                             .setMapping(pathHashMap)));

  //or a shorter version

Predicate predicate = 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 pojo and other kinds of nested querydsl path.

//e.g. select(field1, field2,...)
String rqlSelectExpression = "select(contact.company, contact.name, contact.age)";
DefaultSelectParser selectParser = new DefaultSelectParser();
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();

Expression projection = 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 pojo and other kinds of nested querydsl path.

//ascending is +, descending is -
//e.g. sort(+field1, -field2,...)
String sortExpression = "sort(+employeeNumber)";

DefaultSortParser sortParser = new DefaultSortParser();

Map<String, Path> mappings = ImmutableMap.<String, Path>builder()
        .put("employeeNumber", QEmployee.employee.employeeNumber)
        .build();

OrderSpecifierList orderSpecifierList = sortParser.parse(sortExpression, QuerydslSortContext.withMapping(mappings));

List<OrderSpecifier> orderSpecifiers = orderSpecifierList.getOrders();

Querydsl Page Conversion (rsql-querydsl-page)

//limit(<offset>, <size>)
String rqlPage = "limit(10, 5)";

DefaultPageParser defaultPageParser = new DefaultPageParser();

QueryModifiers querydslPage = defaultPageParser.parse(rqlPage, withDefault());

or a simplified version

QuerydslPageParser querydslPageParser = new QuerydslPageParser();

QueryModifiers querydslPage = querydslPageParser.parse(rqlPage);

Bundled All Querydsl Modules (rsql-querydsl-all)

String rqlSelect = "select(contact.name, contact.age)";
String rqlFilter = "(contact.age =='1' and contact.name == 'A*') or (contact.age > '1'  and contact.bday == '2015-05-05')";
String limit = "limit(0, 10)";
String sort = "sort(+contact.name)";

RqlInput rqlInput = new RqlInput()
        .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();

QuerydslMappingResult querydslMappingResult = querydslRqlParser.parse(rqlInput, new QuerydslMappingParam().setRootPath(QContactDocument.contactDocument).setPathMapping(pathMapping));

Expression selectExpression = querydslMappingResult.getProjection();
Predicate predicate = querydslMappingResult.getPredicate();

QueryModifiers querydslPage = querydslMappingResult.getPage();

List<OrderSpecifier> orderSpecifiers = querydslMappingResult.getOrderSpecifiers();

Integration of Querydsl to Spring Data Pageable

Pageable pageable = 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!!!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].