https://github.com/terma/sql-on-json
Execute SQL on top of JSON
https://github.com/terma/sql-on-json
json-query sql sql-query
Last synced: 4 months ago
JSON representation
Execute SQL on top of JSON
- Host: GitHub
- URL: https://github.com/terma/sql-on-json
- Owner: terma
- License: apache-2.0
- Created: 2017-05-01T04:16:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-04T20:55:47.000Z (over 8 years ago)
- Last Synced: 2025-10-06T04:04:15.876Z (5 months ago)
- Topics: json-query, sql, sql-query
- Language: Java
- Homepage:
- Size: 30.3 KB
- Stars: 16
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sql-on-json
[](https://travis-ci.org/terma/sql-on-json)
[](https://maven-badges.herokuapp.com/maven-central/com.github.terma/sql-on-json/)
## How to use
```java
try (Connection c = new SqlOnJson().convertPlain("{a:[{id:12000,name:\"super\"},{id:90,name:\"remta\"}]}")) {
ResultSet rs = c.prepareStatement("select * from a").executeQuery();
while (rs.next()) {
// my business logic
}
}
```
## Use non default DB
By default ```sql-on-json``` uses [HSQLDB](http://hsqldb.org/)
```java
final SqlOnJson sqlOnJson = new SqlOnJson("driver-class", "url", "user", "password");
try (Connection c = sqlOnJson.convertPlain("{a:[{id:12000,name:\"super\"},{id:90,name:\"remta\"}]}")) {
...
}
```
For example you can use [H2](http://www.h2database.com/)
```java
final SqlOnJson sqlOnJson = new SqlOnJson("org.h2.Driver", "jdbc:h2:mem:", "", "");
try (...)
```
To make DB URL unique per ```new SqlOnJson(...)``` you can use placeholder `````` in second parameter of constructor ```url```, for HSQLDB it will be ```jdbc:hsqldb:mem:sql_on_json_;shutdown=true```