Using Query Interface of App42 Storage API

App42 Cloud Storage API is now equipped with the power of Query interface using which you can perform simple to complex queries on your stored JSON documents in the cloud.

For example if you have stored JSON document which has userId,name,email and state of your users as shown in following document

1
{ 'userId':1, 'name':'app42user','email':'app42@shephertz.com','isActive':true, 'age':30}

For applying the query on your document you have to tell the key name and value associated with key to query interface. For example if you want to fetch the document for the users whose name has ‘app42′ in his name, you can do it using the following java snippet

1
2
ServiceAPI sp = new ServiceAPI("", "");
StorageService storage = sp.buildStorageService();
1
2
Query q1 = QueryBuilder.build("name","app42", Operator.LIKE);
Storage storageObj = storage.findDocumentsByQuery("", "",q1);
1
ArrayList docList = storageObj.getJsonDocList();

Now if you want to fetch the documents based on compound query like finding the documents having ‘name’ like ‘app42′ AND ‘isActive’ to true. You can do this by applying the following java snippet

1
Query q1 = QueryBuilder.build("name", "app42", Operator.LIKE);
1
Query q2 = QueryBuilder.build("isActive", true, Operator.EQUALS);

//Apply AND operator between q1 and q2 using compoundOperator method

1
Query q3 = QueryBuilder.compoundOperator(q1, Operator.AND, q2);
1
2
Storage storageObj = storage.findDocumentsByQuery("", "",q3);
ArrayList docList = storageObj.getJsonDocList();

Query interface of storage api is pretty dynamic and you can apply nested compound query on it using operators AND/OR.

In above example if you want to apply fetch the users whose age is greater then 30 along with above applied query, you can do it by putting another compound query operator as shown below

1
Query q4 = QueryBuilder.build("age", 30, Operator.GREATER_THAN);

//Now apply OR oerator between q3 and q4

1
2
3
Query q5 = QueryBuilder.compoundOperator(q3, Operator.OR, q4);
Storage storageObj = storage.findDocumentsByQuery("", "",q5);
ArrayList docList = storageObj.getJsonDocList();

Storage API also comes with the facility of applying paging and order by operator on your result set. For example fetching result in ascending order based on age of users can be done with the help of following operation

1
2
3
Storage storageObj = storage.findDocsWithQueryPagingOrderBy(
"", "", q5, , , "age",
OrderByType.ASCENDING);

If you don’t want to apply the paging and just want to fetch the result in ascending order you have to just pass negative value in maxresult and offset parameter.

8046709a 9a4d 4fc3 910a a3e6abc0436f Using Query Interface of App42 Storage API   8931e3f4 f630 47a3 9675 fa5b55cf7e24 Using Query Interface of App42 Storage API


twitter Using Query Interface of App42 Storage APIfacebook Using Query Interface of App42 Storage APIgoogle Using Query Interface of App42 Storage APIlinkedin Using Query Interface of App42 Storage APIpinterest Using Query Interface of App42 Storage APIreddit Using Query Interface of App42 Storage APIstumbleupon Using Query Interface of App42 Storage APItumblr Using Query Interface of App42 Storage API
Follow Us
Facebook twitter linkedin google