Cloud Spanner Client - Class KeyRange (1.67.0)

Reference documentation and code samples for the Cloud Spanner Client class KeyRange.

Represents a Cloud Spanner KeyRange.

Example:

use Google\Cloud\Spanner\SpannerClient;

$spanner = new SpannerClient();

// Create a KeyRange for all people named Bob, born in 1969.
$start = $spanner->date(new \DateTime('1969-01-01'));
$end = $spanner->date(new \DateTime('1969-12-31'));

$range = $spanner->keyRange([
    'startType' => KeyRange::TYPE_CLOSED,
    'start' => ['Bob', $start],
    'endType' => KeyRange::TYPE_CLOSED,
    'end' => ['Bob', $end]
]);

Namespace

Google \ Cloud \ Spanner

Methods

__construct

Create a KeyRange.

Parameters
NameDescription
options array

Configuration Options.

↳ startType string

Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness. Defaults to KeyRange::TYPE_OPEN.

↳ start array

The key with which to start the range.

↳ endType string

Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness. Defaults to KeyRange::TYPE_OPEN.

↳ end array

The key with which to end the range.

start

Get the range start.

Example:

$start = $range->start();
Returns
TypeDescription
array|null

setStart

Set the range start.

Example:

$range->setStart(KeyRange::TYPE_OPEN, ['Bob']);
Parameters
NameDescription
type string

Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness.

start array

The start of the key range.

Returns
TypeDescription
void

end

Get the range end.

Example:

$end = $range->end();
Returns
TypeDescription
array

setEnd

Set the range end.

Example:

$range->setEnd(KeyRange::TYPE_CLOSED, ['Jill']);
Parameters
NameDescription
type string

Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness.

end array

The end of the key range.

Returns
TypeDescription
void

types

Get the start and end types

Example:

$types = $range->types();
Returns
TypeDescription
arrayAn array containing `start` and `end` keys.

keyRangeObject

Returns an API-compliant representation of a KeyRange.

Returns
TypeDescription
array

static::prefixMatch

Returns a key range that covers all keys where the first components match.

Equivalent to calling KeyRange::__construct() with closed type for start and end, and the same key for the start and end.

Example:

$range = KeyRange::prefixMatch($key);
Parameter
NameDescription
key array

The key to match against.

Returns
TypeDescription
Google\Cloud\Spanner\KeyRange

static::fromArray

Create a KeyRange from an array created by Google\Cloud\Spanner\KeyRange::keyRangeObject().

Parameter
NameDescription
range array

An array of KeyRange data.

Returns
TypeDescription
Google\Cloud\Spanner\KeyRange

Constants

TYPE_OPEN

Value: 'open'

TYPE_CLOSED

Value: 'closed'