Skip to content

Provide helper methods on entity.Key for Kind, parent, name, and ID #574

Closed
@jgeewax

Description

@jgeewax

(In reference to https://github.com/GoogleCloudPlatform/gcloud-node/blob/412598cad200198caaac5dbe83700fd1665b2102/lib/datastore/entity.js#L54)

It'd be really nice if we had some helper methods on the Key class, so that you could do the following...

var gcloud = require('gcloud');
var dataset = gcloud.datastore.dataset({...});

Auto-generated ID example:

entity = {
  key: dataset.key('Person').
  data: {name: 'Jim'}
};

dataset.save(entity, function(err, entity) {
  var key = entity.key;
  console.log('kind is', key.kind); // 'Person'
  console.log('id is', key.id);  // 1234567 (auto-generated ID in this case)
  console.log('name is', key.name); // undefined or null
  console.log('parent is', key.parent); // undefined or null
});

Specific name and parent example

entity = {
  key: dataset.key(['Person', 'mom', 'Person', 'jim']).
  data: {name: 'Jim'}
};

dataset.save(entity, function(err, entity) {
  var key = entity.key;
  console.log('kind is', key.kind); // 'Person'
  console.log('id is', key.id);  // undefined or null
  console.log('name is', key.name); // 'jim'
  console.log('parent is', key.parent); // {key object}
  console.log('parent kind is', key.parent.kind); // 'Person'
  console.log('parent id is', key.parent.id); // undefined or null
  console.log('parent name is', key.parent.name); // 'mom'
  console.log('parent parent is', key.parent.parent); // undefined or null
});

Is this a reasonable request?

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions