Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datastore: Adding support for embedding keys and filtering by keys #106

Merged
merged 2 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ function valueToProperty(v) {
});
return p;
}
if (v instanceof Key) {
p.keyValue = keyToKeyProto(v);
return p;
}
if (v instanceof Object && Object.keys(v).length > 0) {
var properties = {};
Object.keys(v).forEach(function(k) {
// TODO: Detect keys?
properties[k] = valueToProperty(v[k]);
});
p.entityValue = { properties: properties };
Expand Down
22 changes: 22 additions & 0 deletions regression/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ describe('datastore', function() {

});

it('should be able to save keys as a part of entity and query by key',
function(done) {
var personKey = datastore.key('Person', 'name');
ds.save({
key: personKey,
data: {
fullName: 'Full name',
linkedTo: personKey // himself
}
}, function(err) {
assert.ifError(err);
var q = ds.createQuery('Person')
.filter('linkedTo =', personKey);
ds.runQuery(q, function(err, results) {
assert.ifError(err);
assert.strictEqual(results[0].data.fullName, 'Full name');
assert.deepEqual(results[0].data.linkedTo, personKey);
ds.delete(personKey, done);
});
});
});

describe('querying the datastore', function() {

var keys = [
Expand Down