Cloud Spanner Client - Class KeyRange (1.86.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
Name Description
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
Type Description
array|null

setStart

Set the range start.

Example:

$range->setStart(KeyRange::TYPE_OPEN, ['Bob']);
Parameters
Name Description
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
Type Description
void

end

Get the range end.

Example:

$end = $range->end();
Returns
Type Description
array

setEnd

Set the range end.

Example:

$range->setEnd(KeyRange::TYPE_CLOSED, ['Jill']);
Parameters
Name Description
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
Type Description
void

types

Get the start and end types

Example:

$types = $range->types();
Returns
Type Description
array An array containing `start` and `end` keys.

keyRangeObject

Returns an API-compliant representation of a KeyRange.

Returns
Type Description
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
Name Description
key array

The key to match against.

Returns
Type Description
Google\Cloud\Spanner\KeyRange

static::fromArray

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

Parameter
Name Description
range array

An array of KeyRange data.

Returns
Type Description
Google\Cloud\Spanner\KeyRange

Constants

TYPE_OPEN

Value: 'open'

TYPE_CLOSED

Value: 'closed'