Description
I use the key identifier extensively throughout my app as my "id". The namespace and kind doesn't change. Is it possible to return the key identifier inline with the data returned from queries or should I just include the identifier as a property on the entity ?
For example, if you look at this simple example of an entity returned by a query:
[ { key: { namespace: 'mynamespace', path: [Object] },data: { name: 'My Entity'} }]
What I would like is for my data object to look like:
data:{id:XXXXX,name:'My Entity}
At the moment to include the key identifier with my data object I need to do something like:
var dao = entity.data
dao.id = entity.key.path.pop()
NOTE - I use pop() here since it's in the examples but I think it's a bad idea. Poping the identifier removes it from the path array. If I go on to reuse the key, it's incomplete (e.g. if I did a get and update). I think entity.key.path[entity.key.path.length - 1] is a better idea.
Anyway, if I am returning thousands of entities I can write (using async.js) something like:
ds.runQuery(query, function(err,entities){
async.map(entities,DAO,callback);
});
function DAO(entity,callback) {
var dao = entity.data;
dao.id = entity.key.path.pop();
callback(null, dao);
}
The problem I have is that (1) this is quite cumbersome (2) I haven't benchmarked but I'm sure there is a performance hit.
Is there a better way to do this ?