Skip to content

eaxdev/JsonSQL4J

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonSQL4J

Build Status GitHub license Maven Central codecov Quality Gate Status

This library for mapping JSON style query objects to SQL queries

Get it!

Maven

You can use following Maven dependency:

<dependency>
  <groupId>io.github.eaxdev</groupId>
  <artifactId>jsonsql4j</artifactId>
  <version>0.0.3</version>
</dependency>

Gradle

implementation 'io.github.eaxdev:jsonsql4j:0.0.3'

Also, you can use GitHub Packages.

Use it!

Given JSON:

{
  "fields": [
    {"column": "field1"},
    {"column": "field2", "alias": "test"}
  ],
  "from": [
    {"table": "table1", "schema": "schema"}
  ],
  "where": {
    "or": [
      { "eq": {"fieldName": "field3", "value": "5"} },
      { "eq": {"fieldName": "field4", "value": "3"} }
    ]
  }
}

use library:

Query selectQuery = new SelectQuery(jsonString);
String query = selectQuery.getQuery();
// query = SELECT field1, field2 AS test FROM schema.table1 WHERE (field3 = 5 OR field4 = 3)

You can find more examples here.

License

JsonSQL4J is open-source project, and distributed under the MIT license