Over a million developers have joined DZone.

New Raw Query Result for the Java SDK

Couchbase's new SDK introduces the RawQueryExecutor. Read on to find out what it's all about and how to use it.

· Database Zone

Sign up for the Couchbase Community Newsletter to stay ahead of the curve on the latest NoSQL news, events, and webinars. Brought to you in partnership with Coucbase.

The latest version of our Java SDK (2.3.3 at the time of writing) introduces a new class: RawQueryExecutor. It gives you the direct result of a N1QL or FTS query as a JSON String or JsonObject, just like if you were using the REST API directly. The answer is not wrapped in rows. As such you can pass the result of the method directly to your client. No need for additional mapping or anything.

This is particularly useful for N1QL queries as it allows you to query exactly what you need through the SELECT clause. It is very efficient combined with the right covering indexes.

Here's the asynchronous code sample:

AsyncRawQueryExecutor asyncRawQueryExecutor= new AsyncRawQueryExecutor("default", "", bucket.core());
Observable<String> result = asyncRawQueryExecutor.n1qlToRawJson(N1qlQuery.simple("Select name, abv, ibu, style FROM `beer-sample` WHERE ibu IS NOT MISSING ORDER BY ibu LIMIT 10 OFFSET 10"));


And the synchronous one:

RawQueryExecutor rawQueryExecutor = new RawQueryExecutor("default", "", bucket.core(), bucket.environment());
String jsonString = rawQueryExecutor.n1qlToRawJson(N1qlQuery.simple("Select name, abv, ibu, style FROM `beer-sample` WHERE ibu IS NOT MISSING ORDER BY ibu LIMIT 10 OFFSET 10"));

I would love to know if you find it useful and if you want this also for simpler operations. Tell us what you think!

The Getting Started with NoSQL Guide will get you hands-on with NoSQL in minutes with no coding needed. Brought to you in partnership with Couchbase.

Topics:
result ,mapping ,query ,json ,api ,n1ql ,rows ,java ,couchbase

Published at DZone with permission of Laurent Doguin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}