-
Notifications
You must be signed in to change notification settings - Fork 1
Usage examples
Wagner Leonardi edited this page Oct 11, 2019
·
3 revisions
- If you are using Gradle, Scala or Kotlin see their dependency script here
- Clojure: we have an exclusive guide here.
Example using Maven, add jsonbox in your pom.xml
:
<dependency>
<groupId>io.jsonbox</groupId>
<artifactId>jsonbox</artifactId>
<version>1.0.3</version>
</dependency>
import io.jsonbox.JsonBoxStorage;
JsonBoxStorage storage = new JsonBoxStorage("examplebox0000000000");
4. Now you can use any function from the documentation, to create, read, update and delete records in your store or collection, see examples:
String result = storage.create("{\"name\": \"john\", \"age\" : 27}");
String result = storage.read();
int pageSize = 10;
String firstPage = storage.read(0, pageSize);
String secondPage = storage.read(pageSize, pageSize);
String thirdPage = storage.read(pageSize * 2, pageSize)
String namesStartingWithJ = storage.readFiltering("name:j*");
String namesContainingA = storage.readFiltering("name:*a*");
String ageLessThan35 = storage.readFiltering("age:<35");
String nameAndAgeFiltering = storage.readFiltering("name:*a*,age:<35");
String filteringAndPagination = storage.read(5, 10,"age:<35",age:<35");
String sortedResultByName = storage.readSorting("name");
String sortedResultByNameDescending = storage.readSorting("-name");
String paginationAndSorting = storage.read(5, 10, null, "-name");
String paginationAndFilterAndSorting = storage.read(5, 10, "age:<35", "-name");
String recordId = "0000000000";
String newRecord = "{\"name\": \"john\", \"age\" : 27}";
String result = storage.update(recordId, newRecord);
String recordId = "0000000000";
String result = storage.delete(recordId);
String recordId = "0000000000";
String result = storage.deleteFiltering("age:<35");
These are basic examples, to use with a JSON parsing library please check this guide.