use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method query.
/**
* Performs a N1QL query with custom {@link QueryOptions}.
*
* @param statement the N1QL query statement as a raw string.
* @param options the custom options for this query.
* @return the {@link QueryResult} once the response arrives successfully.
*/
public CompletableFuture<QueryResult> query(final String statement, final QueryOptions options) {
notNull(options, "QueryOptions", () -> new ReducedQueryErrorContext(statement));
final QueryOptions.Built opts = options.build();
JsonSerializer serializer = opts.serializer() == null ? environment.get().jsonSerializer() : opts.serializer();
return queryAccessor.queryAsync(queryRequest(statement, opts), opts, serializer);
}
use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.
the class AsyncQueryIndexManager method exec.
private CompletableFuture<QueryResult> exec(QueryType queryType, CharSequence statement, CommonOptions<?>.BuiltCommonOptions options, String spanName, String bucketName, JsonArray parameters) {
QueryOptions queryOpts = toQueryOptions(options).readonly(requireNonNull(queryType) == READ_ONLY);
if (parameters != null && !parameters.isEmpty()) {
queryOpts.parameters(parameters);
}
RequestSpan parent = cluster.environment().requestTracer().requestSpan(spanName, options.parentSpan().orElse(null));
parent.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
if (bucketName != null) {
parent.attribute(TracingIdentifiers.ATTR_NAME, bucketName);
}
queryOpts.parentSpan(parent);
return cluster.query(statement.toString(), queryOpts).exceptionally(t -> {
throw translateException(t);
}).whenComplete((r, t) -> parent.end());
}
use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.
the class QueryCollectionIntegrationTest method performsAdhocQuery.
@Test
void performsAdhocQuery() {
Scope scope = cluster.bucket(config().bucketname()).scope(SCOPE_NAME);
Collection collection = scope.collection(COLLECTION_NAME);
String id = insertDoc(collection);
QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS);
QueryResult result = scope.query("select * from `" + COLLECTION_NAME + "` where meta().id=\"" + id + "\"", options);
assertEquals(QueryStatus.SUCCESS, result.metaData().status());
assertEquals(1, result.rowsAsObject().size());
ReactiveScope reactiveScope = cluster.bucket(config().bucketname()).reactive().scope(SCOPE_NAME);
ReactiveQueryResult reactiveResult = reactiveScope.query("select * from `" + COLLECTION_NAME + "` where meta().id=\"" + id + "\"", options).block();
assertEquals(QueryStatus.SUCCESS, reactiveResult.metaData().block().status());
assertEquals(1, reactiveResult.rowsAsObject().blockLast().size());
}
use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.
the class QueryIntegrationTest method blockingPositionalParameterizedSelectQuery.
@Test
void blockingPositionalParameterizedSelectQuery() {
String id = insertDoc();
QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonArray.from(id));
QueryResult result = cluster.query("select " + bucketName + ".* from " + bucketName + " where meta().id=$1", options);
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertEquals(1, rows.size());
assertEquals(FOO_CONTENT, rows.get(0));
}
use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.
the class QueryIntegrationTest method reactiveNamedParameterizedSelectQuery.
@Test
void reactiveNamedParameterizedSelectQuery() {
String id = insertDoc();
QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonObject.create().put("id", id));
Mono<ReactiveQueryResult> result = cluster.reactive().query("select * from " + bucketName + " where meta().id=$id", options);
List<JsonObject> rows = result.flux().flatMap(ReactiveQueryResult::rowsAsObject).collectList().block();
assertNotNull(rows);
assertEquals(1, rows.size());
}
Aggregations