Comments (9)
I finally found the time to test your data. I spot the error, the regex I was using to validate is not correct. I will release a fix this week-end. thanks for reporting!
from gstore-node.
You're right gstore could validate and convert to geoPoint such object. I will add it to the next release. Thanks for reporting!
from gstore-node.
Hi, just released v0.9.0 with this feature. Could you please test and tell me if it does validate correctly? thanks!
from gstore-node.
As per the other issue, this seems to be resolved for the global gstore.save()
method. But for the regular Entity.save()
method I'm still getting a validation error.
from gstore-node.
That's strange. Could you please share the "schema" and "data" you try to save so I can try it?
from gstore-node.
Sure, here's the schema I'm trying to write to:
const schema = new gstore.Schema({
country: {
type: 'string',
},
localityUrlMapping: {
type: 'string',
},
location: {
type: 'geoPoint',
},
placeName: {
type: 'string',
excludeFromIndexes: true,
},
subLocalityUrlMapping: {
type: 'string',
},
sublocality: {
type: 'boolean',
},
sublocalityParentId: {
type: 'string',
},
updatedDate: {
type: 'datetime',
default: gstore.defaultValues.NOW,
},
});
const TestLocalityUrlMapping = gstore.model('TestLocalityUrlMapping', schema);
export default TestLocalityUrlMapping;
I'll show you the code that works first:
I'm trying to transfer data over from an entity called LocalityUrlMapping
to TestLocalityUrlMapping
- they shared exactly the same schema structure, as above. Its a little strange, but I wanted to test out re-saving entities before I ran it on my real data.
const query = LocalityUrlMapping.query().limit(50);
const result = await query.run({ readAll: true, format: gstore.Queries.formats.JSON });
const response = result[0];
const resaveEntities = [];
for (let i = 0; i < response.entities.length; i += 1) {
const data = Object.assign({}, response.entities[i]);
delete data.id;
const entity = new TestLocalityUrlMapping(data, response.entities[i].id);
resaveEntities.push(entity);
}
await gstore.save(resaveEntities);
So, that works fine. But this does not:
const query = LocalityUrlMapping.query().limit(50);
const result = await query.run({ readAll: true, format: gstore.Queries.formats.JSON });
const response = result[0];
const resaveEntities = [];
for (let i = 0; i < response.entities.length; i += 1) {
const data = Object.assign({}, response.entities[i]);
delete data.id;
const entity = new TestLocalityUrlMapping(data, response.entities[i].id);
resaveEntities.push(entity.save());
}
await Promise.all(resaveEntities);
Basically, what should be happening here is that every single Promise in the resaveEntities
array should be run and resolved- but I get a validation error before it gets anywhere, like this:
(node:5876) Warning: a promise was rejected with a non-error: [object Error]
(node:5876) Warning: a promise was rejected with a non-error: [object Error]
(node:5876) Warning: a promise was rejected with a non-error: [object Error]
Unhandled rejection ValidationError: [object Object]
at ValidationError.GstoreError (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\error.js:9:26)
at ValidationError (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\error.js:29:13)
at Object.keys.forEach (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\model.js:953:37)
at Array.forEach (native)
at ModelInstance.validate (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\model.js:873:38)
at Promise (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\schema.js:62:23)
at ModelInstance.fn (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\schema.js:60:20)
at ModelInstance.next (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:109:44)
at Promise (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:116:29)
at ModelInstance.wrapper [as save] (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:71:20)
at _callee$ (d:/Dev/_Projects/Vibescout/vibescout-web-v3/src/server/gcloud/datastore/interactions/reindexing/AnyEntity.js:41:32)
at tryCatch (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\regenerator-runtime\runtime.js:64:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\regenerator-ru[...]
I have tried this out with only one entity too and its the same.
This is what the data
variable looks like within the loop above. As you can see location
is just a regular object before saving.
from gstore-node.
Mmm not seeing the error. Could you try to just save 1 entity with the data you have here? Also add a catch on the Promise (or inside a try catch with await) to get the exact error returned.
Note: you don't have to specify format: gstore.Queries.formats.JSON
, it's the default value
from gstore-node.
Okay cool, I tried with just one entity returned from a query now.
This is the test function I'm running:
export async function testDatastoreSave() {
const query = TestLocalityUrlMapping.query().limit(1);
const result = await query.run({ readAll: true });
const response = result[0];
const data = Object.assign({}, response.entities[0]);
const id = response.entities[0].id;
delete data.id;
log.json(data);
const entityToSave = new TestLocalityUrlMapping(data, id);
try {
await entityToSave.save();
} catch (e) {
log.error(e.stack);
}
log.info("Completed saving");
}
For log.json(data)
I get (prettified JSON):
sublocality: false
location:
longitude: 174.76333618164062
latitude: -36.84846115112305
placeName: Auckland
localityUrlMapping: auckland
updatedDate: Mon Dec 12 2016 13:13:35 GMT+0200 (South Africa Standard Time)
subLocalityUrlMapping: null
sublocalityParentId: null
country: NZ
And for the log.error(e.stack)
:
error: ValidationError: [object Object]
at ValidationError.GstoreError (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\error.js:9:26)
at ValidationError (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\error.js:29:13)
at Object.keys.forEach (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\model.js:953:37)
at Array.forEach (native)
at ModelInstance.validate (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\model.js:873:38)
at Promise (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\schema.js:62:23)
at ModelInstance.fn (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\gstore-node\lib\schema.js:60:20)
at ModelInstance.next (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:109:44)
at Promise (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:116:29)
at ModelInstance.wrapper [as save] (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\promised-hooks\hooks.js:71:20)
at _callee$ (d:/Dev/_Projects/Vibescout/vibescout-web-v3/src/server/gcloud/datastore/interactions/testing/testingMethods.js:23:24)
at tryCatch (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\regenerator-runtime\runtime.js:64:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (d:\Dev\_Projects\Vibescout\vibescout-web-v3\node_modules\regenerator-run[...]
from gstore-node.
Actually I was interested in the error object itself to see the message :) not so much the stack.
But could you try, just to save your data (no query before).
Something like:
const data = {
sublocality: false,
location: {
longitude: 174.76333618164062,
latitude: -36.84846115112305,
},
placeName: "Auckland",
localityUrlMapping: "auckland",
updatedDate: new Date(), // you might have a problem here in the validation with your date from the query
subLocalityUrlMapping: null,
sublocalityParentId: null,
country: "NZ"
}
const entityToSave = new TestLocalityUrlMapping(data);
try {
await entityToSave.save();
} catch (e) {
log.error(e.stack);
}
from gstore-node.
Related Issues (20)
- query filter on nested property value. HOT 5
- tsc error: Could not find a declaration file for module 'nsql-cache' HOT 3
- could not get data filter by entity key
- Support for @google-cloud/datastore version 5 HOT 2
- Support for custom validators (AJV)
- bulk insert? HOT 2
- Cannot read property 'Symbol(KEY)' when body is null or undefined HOT 1
- Typescript Compile Error HOT 2
- Support for HABTM
- Could not find gstore instance with id "${id}" HOT 2
- How to validate a value agains another property? HOT 1
- Datastore Key type error when using cache HOT 7
- Update method doesn't clear cache HOT 6
- Add Transaction support to `findOne` option HOT 1
- Support filtering for a missing optional property. HOT 1
- New query operators HOT 1
- @google-cloud/datastore version 7 support HOT 1
- could not get data filter by entity key HOT 1
- Migrate Travis CI builds to Circle CI
- Gstore node 7.2.8 TypeError: OptionalDataloader is not a constructor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gstore-node.