Key
class
Build a Datastore Key object.
Constructor
Key
new Key(options)
Parameter |
|||||||
---|---|---|---|---|---|---|---|
options |
object Configuration object. Values in
|
Examples
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');
<caption>Create a complete key with a kind value of `Company` and id
`123`.</caption> const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key(['Company', 123]);
<caption>If the ID integer is outside the bounds of a JavaScript Number
object, create an Int.</caption> const {Datastore} =
require('@google-cloud/datastore'); const datastore = new Datastore();
const key = datastore.key([
'Company',
datastore.int('100000000000001234')
]);
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']);
<caption>Create a complete key from a provided namespace and
path.</caption> const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const key = datastore.key({
namespace: 'My-NS',
path: ['Company', 123]
});
Properties
namespace
string
path
array