org.evcode.queryfy:queryfy-core

Queryfy translate a SQL-like DSL in an query object

License

License

GroupId

GroupId

org.evcode.queryfy
ArtifactId

ArtifactId

queryfy-core
Last Version

Last Version

1.2.2
Release Date

Release Date

Type

Type

jar
Description

Description

Queryfy translate a SQL-like DSL in an query object
Project Organization

Project Organization

Edmo Vamerlatti Costa

Download queryfy-core

How to add to project

<!-- https://jarcasting.com/artifacts/org.evcode.queryfy/queryfy-core/ -->
<dependency>
    <groupId>org.evcode.queryfy</groupId>
    <artifactId>queryfy-core</artifactId>
    <version>1.2.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.evcode.queryfy/queryfy-core/
implementation 'org.evcode.queryfy:queryfy-core:1.2.2'
// https://jarcasting.com/artifacts/org.evcode.queryfy/queryfy-core/
implementation ("org.evcode.queryfy:queryfy-core:1.2.2")
'org.evcode.queryfy:queryfy-core:jar:1.2.2'
<dependency org="org.evcode.queryfy" name="queryfy-core" rev="1.2.2">
  <artifact name="queryfy-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.evcode.queryfy', module='queryfy-core', version='1.2.2')
)
libraryDependencies += "org.evcode.queryfy" % "queryfy-core" % "1.2.2"
[org.evcode.queryfy/queryfy-core "1.2.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.parboiled : parboiled-java jar 1.1.7

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Queryfy

Build Status

Queryfy is a simple SQL-like language designed to provide a safe and flexible way to filter, sort and to paginate data over REST APIs and Front-end as well.

  • As it is NOT SQL, there is no SQL Injection.

  • The Queryfy-Core is responsible for build the abstract syntax tree (AST) from the query string and use a provided visitor to build the filter object (eg. JPAQuery, etc).

  • You can use the existing implementation (QueryDSL JPA, MongoDB (Bson)) or implement your own visitor.

Usage

<dependency>
    <groupId>org.evcode.queryfy</groupId>
    <artifactId>queryfy-core</artifactId>
    <version>1.2.2</version>
</dependency>

QueryDSL

<dependency>
    <groupId>org.evcode.queryfy</groupId>
    <artifactId>queryfy-querydsl-jpa</artifactId>
    <version>1.2.2</version>
</dependency>
EntityManager em = ...;
String query = "select name, age where age > 18 order by name limit 0, 100";

JPAQueryDslParser parser = new JPAQueryDslParser(em);

//Create an evaluation context. All paths added here will be available on the query syntax
QueryDslContext context = QueryDslContext.from(QTest.test)
                .withPath("name", QTest.test.name)
                .withPath("age", QTest.test.age)
                .withPath("other.id", QTest.test.other.id)
                .withPath("other.name", QTest.test.other.name)
                .build();
                
//Parse the query string into a QueryDSL JPAQuery or JPAEvaluatedQuery object
JPAEvaluatedQuery jpaQuery = parser.parseAndFind(query, context);

//List applying the projections fields (name and age)
List<Test> list = jpaQuery.listWithProjections();

MongoDB (Bson)

<dependency>
    <groupId>org.evcode.queryfy</groupId>
    <artifactId>queryfy-mongodb</artifactId>
    <version>1.2.2</version>
</dependency>
String query = "select name, age where age > 18 order by name limit 0, 100"; 
MongodbQueryParser parser = new MongodbQueryParser();

//Create an evaluation context. All paths added here will be available on the query syntax
MongodbContext context = MongodbContext.builder()
                .withPath("name")
                .withPath("age")
                .withPath("otherId", "other.id")
                .build();
                
MongoCollection<Document> collection = ....;

//The parseAndFind method will parse the query and return a MongoDB FindIterable. you can also use the parseAndApply method
//to set the parameters on an existing FindIterable object.
FindIterable<Document> result = parser.parseAndFind(collection, query, context);

See more

Documentation

Versions

Version
1.2.2
1.2.1
1.2.0
1.0.0
v1.0.0