class ViewQuery implements ViewQueryEncodable (View source)

Represents regular Couchbase Map/Reduce View query

Constants

UPDATE_BEFORE

Force a view update before returning data

UPDATE_NONE

Allow stale views

UPDATE_AFTER

Allow stale view, update view after it has been accessed.

ORDER_ASCENDING

ORDER_DESCENDING

Methods

static ViewQuery
from(string $designDocumentName, string $viewName)

Creates a new Couchbase ViewQuery instance for performing a view query.

fromSpatial(string $designDocumentName, string $viewName)

Creates a new Couchbase ViewQuery instance for performing a spatial query.

array
encode()

Returns associative array, representing the View query.

limit(int $limit)

Limits the result set to a specified number rows.

skip(int $skip)

Skips a number o records rom the beginning of the result set

consistency(int $consistency)

Specifies the mode of updating to perorm before and after executing the query

order(int $order)

Orders the results by key as specified

reduce(bool $reduce)

Specifies whether the reduction function should be applied to results of the query.

group(bool $group)

Group the results using the reduce function to a group or single row.

groupLevel(int $groupLevel)

Specify the group level to be used.

key(mixed $key)

Restict results of the query to the specified key

keys(array $keys)

Restict results of the query to the specified set of keys

range(mixed $startKey, mixed $endKey, bool $inclusiveEnd = false)

Specifies a range of the keys to return from the index.

idRange(string $startKeyDocumentId, string $endKeyDocumentId)

Specifies start and end document IDs in addition to range limits.

custom(array $customParameters)

Specifies custom options to pass to the server.

Details

static ViewQuery from(string $designDocumentName, string $viewName)

Creates a new Couchbase ViewQuery instance for performing a view query.

Parameters

string $designDocumentName

the name of the design document to query

string $viewName

the name of the view to query

Return Value

ViewQuery

static SpatialViewQuery fromSpatial(string $designDocumentName, string $viewName)

Creates a new Couchbase ViewQuery instance for performing a spatial query.

Parameters

string $designDocumentName

the name of the design document to query

string $viewName

the name of the view to query

Return Value

SpatialViewQuery

array encode()

Returns associative array, representing the View query.

Return Value

array

object which is ready to be serialized.

ViewQuery limit(int $limit)

Limits the result set to a specified number rows.

Parameters

int $limit

maximum number of records in the response

Return Value

ViewQuery

ViewQuery skip(int $skip)

Skips a number o records rom the beginning of the result set

Parameters

int $skip

number of records to skip

Return Value

ViewQuery

ViewQuery consistency(int $consistency)

Specifies the mode of updating to perorm before and after executing the query

Parameters

int $consistency

use constants UPDATE_BEFORE, UPDATE_NONE, UPDATE_AFTER

Return Value

ViewQuery

See also

ViewQuery::UPDATE_BEFORE
ViewQuery::UPDATE_NONE
ViewQuery::UPDATE_AFTER

ViewQuery order(int $order)

Orders the results by key as specified

Parameters

int $order

use contstants ORDER_ASCENDING, ORDER_DESCENDING

Return Value

ViewQuery

ViewQuery reduce(bool $reduce)

Specifies whether the reduction function should be applied to results of the query.

Parameters

bool $reduce

Return Value

ViewQuery

ViewQuery group(bool $group)

Group the results using the reduce function to a group or single row.

Important: this setter and groupLevel should not be used together in the same ViewQuery. It is sufficient to only set the grouping level only and use this setter in cases where you always want the highest group level implictly.

Parameters

bool $group

Return Value

ViewQuery

See also

ViewQuery::groupLevel

ViewQuery groupLevel(int $groupLevel)

Specify the group level to be used.

Important: group() and this setter should not be used together in the same ViewQuery. It is sufficient to only use this setter and use group() in cases where you always want the highest group level implictly.

Parameters

int $groupLevel

the number of elements in the keys to use

Return Value

ViewQuery

See also

ViewQuery::group

ViewQuery key(mixed $key)

Restict results of the query to the specified key

Parameters

mixed $key key

Return Value

ViewQuery

ViewQuery keys(array $keys)

Restict results of the query to the specified set of keys

Parameters

array $keys

set of keys

Return Value

ViewQuery

ViewQuery range(mixed $startKey, mixed $endKey, bool $inclusiveEnd = false)

Specifies a range of the keys to return from the index.

Parameters

mixed $startKey
mixed $endKey
bool $inclusiveEnd

Return Value

ViewQuery

ViewQuery idRange(string $startKeyDocumentId, string $endKeyDocumentId)

Specifies start and end document IDs in addition to range limits.

This might be needed for more precise pagination with a lot of documents with the same key selected into the same page.

Parameters

string $startKeyDocumentId

document ID

string $endKeyDocumentId

document ID

Return Value

ViewQuery

ViewQuery custom(array $customParameters)

Specifies custom options to pass to the server.

Note that these options are expected to be already encoded.

Parameters

array $customParameters parameters

Return Value

ViewQuery

See also

https://developer.couchbase.com/documentation/server/current/rest-api/rest-views-get.html Getting Views Information