Skip to content

Commit 8614669

Browse files
author
Burcu Dogan
committed
Merge pull request #21 from silvolu/master
Fixed type checks for Boolean and Number primitive types in valueToProperty
2 parents 1ef6202 + 01e782f commit 8614669

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ TODO
101101
Get operations require a valid key to retrieve the key identified entity from Datastore. Skip to the "Querying" section if you'd like to learn more about querying against Datastore.
102102

103103
~~~~ js
104-
ds.get(['Company', 123], function(err, obj) {
104+
ds.get(['Company', 123], function(err, key, obj) {
105105

106106
});
107107
// alternatively, you can retrieve multiple entities at once.
108-
ds.getAll([key1, key2, ...], function(err, objs) {
108+
ds.getAll([key1, key2, ...], function(err, keys, objs) {
109109

110110
});
111111
~~~~

lib/datastore/entity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports.entityFromEntityProto = entityFromEntityProto;
180180
*/
181181
function valueToProperty(v) {
182182
var p = {};
183-
if (v instanceof Boolean) {
183+
if (v instanceof Boolean || typeof v === 'boolean') {
184184
p.booleanValue = v;
185185
return p;
186186
}
@@ -192,7 +192,7 @@ function valueToProperty(v) {
192192
p.doubleValue = v.get();
193193
return p;
194194
}
195-
if (v instanceof Number) {
195+
if (v instanceof Number || typeof v === 'number') {
196196
if (v % 1 === 0) {
197197
p.integerValue = v;
198198
} else {

test/datastore.entity.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ describe('entityToEntityProto', function() {
182182
name: 'Burcu',
183183
desc: 'Description',
184184
count: new entity.Int(6),
185+
primitiveCount: 6,
186+
legit: true,
185187
date : now,
186188
bytes: new Buffer("Hello"),
187189
list: ['a', new entity.Double(54.7)],
@@ -193,6 +195,8 @@ describe('entityToEntityProto', function() {
193195
assert.equal(proto.properties.name.stringValue, 'Burcu');
194196
assert.equal(proto.properties.desc.stringValue, 'Description');
195197
assert.equal(proto.properties.count.integerValue, 6);
198+
assert.equal(proto.properties.primitiveCount.integerValue, 6);
199+
assert.equal(proto.properties.legit.booleanValue, true);
196200
assert.equal(proto.properties.date.dateTimeValue, now);
197201
assert.equal(proto.properties.bytes.blobValue, 'SGVsbG8=');
198202
assert.equal(proto.properties.list.listValue[0].stringValue, 'a');

0 commit comments

Comments
 (0)