Class Key

Build a Datastore Key object.

Param

Configuration object.

Param

Key path.

Param

Optional namespace.

Example

//-
// Create an incomplete key with a kind value of `Company`.
//-
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key('Company');

Example

//-
// Create a complete key with a kind value of `Company` and id`123`.
//-
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key(['Company', 123]);

Example

//-
// If the ID integer is outside the bounds of a JavaScript Number
// object, create an Int.
//-
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key([
'Company',
datastore.int('100000000000001234')
]);

Example

const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
// Create a complete key with a kind value of `Company` and name `Google`.
// Note: `id` is used for numeric identifiers and `name` is used otherwise.
const key = datastore.key(['Company', 'Google']);

Example

//-
// Create a complete key from a provided namespace and path.
//-
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key({
namespace: 'My-NS',
path: ['Company', 123]
});

Example

Serialize the key for later re-use.

const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key({
namespace: 'My-NS',
path: ['Company', 123]
});
// Later...
const key = datastore.key(key.serialized);

Hierarchy

  • Key

Constructors

Properties

Accessors

Constructors

  • Parameters

    • options: KeyOptions

    Returns Key

Properties

id?: string
kind: string
name?: string
namespace?: string
parent?: Key
path: (string | number)[]

Accessors

  • get serialized(): {
        namespace: undefined | string;
        path: (string | Int)[];
    }
  • Access the serialized property for a library-compatible way to re-use a key.

    Returns {
        namespace: undefined | string;
        path: (string | Int)[];
    }

    • namespace: undefined | string
    • path: (string | Int)[]

    Example

    const key = datastore.key({
    namespace: 'My-NS',
    path: ['Company', 123]
    });

    // Later...
    const key = datastore.key(key.serialized);

Generated using TypeDoc