Giter Site home page Giter Site logo

Comments (6)

digaresc avatar digaresc commented on May 25, 2024

Updated to node v6.9.1 and now I get this error:

Error: Property not allowed { undefined } for ClientApp Entity
    at Object.keys.forEach (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/model.js:879:37)
    at Array.forEach (native)
    at ModelInstance.validate (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/model.js:856:38)
    at Promise (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/schema.js:60:23)
    at ModelInstance.fn (/Users/digaresc/t/src/sdk-backend/node_modules/gstore-node/lib/schema.js:58:20)
    at ModelInstance.next (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:109:44)
    at Promise (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:116:29)
    at ModelInstance.wrapper [as save] (/Users/digaresc/t/src/sdk-backend/node_modules/promised-hooks/hooks.js:71:20)
    at create (/Users/digaresc/t/src/sdk-backend/controllers/clientApp.controller.js:19:15)
    at Layer.handle [as handle_request] (/Users/digaresc/t/src/sdk-backend/node_modules/express/lib/router/layer.js:95:5)

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Hi,
I can't spot the error so let me write how it "should" work and see from there.
You need node > 4 (so 6.9.1 is perfect)

// server.js
// This is your main starting file
var datastore = require('@google-cloud/datastore')({
    projectId: 'tttttttt',
    keyFilename: './keyfile.json'
});

var gstore = require('gstore-node');
gstore.connect(datastore);

// ... rest of your initial setup
// client-app.model.js

var gstore = require('gstore-node');
var uuid = require('uuid');
var Schema = gstore.Schema;

var schema = new Schema({
    appName: {
        type: 'string',
        required: true,
        read: false
    },
    androidBundleId: {
        type: 'string',
        required: true,
        read: false
    },
    iosBundleId: {
        type: 'string',
        required: true,
        read: false
    },
    modified: {
        type: 'boolean',
        default: false,
        read: false,
        write: false
    },
    createdOn: {
        type: 'datetime',
        default: gstore.defaultValues.NOW,
        write: false,
        read: false
    },
    appKey: {
        type: 'string',
        default: uuid.v4(), // careful as this value will be "static" for all instance. I will add a fix to that soon
        write: false
    }
});

schema.virtual('timestamp').get(function() {
    // the scope (this) is the entityData object
    return this.createdOn;
});

var ClientAppModel = gstore.model('ClientApp', schema); // don't suffix "Model" to the entity kind.

module.exports = ClientAppModel;
// client-app.controller.js
var ClientAppModel = require('../models/client-app.model.js');

function create(req, res) {
    var data = ClientAppModel.sanitize(req.body);
    var clientApp = new ClientAppModel(data, data.appName);
    delete data.appName; // You probably don't need it anymore as it is now the 'id'

    clientApp.save().then(function() {
        res.json(this.plain());
    }).catch((err) => {
        console.log(err);
        res.status(400).json(err);
    });
}

module.exports = {
    create: create
};

from gstore-node.

digaresc avatar digaresc commented on May 25, 2024

Same problem.

Do you want me do do something else?

If I do a:

console.log(clientapp.entityData)

I got this, isn't there something strange?

I have been following all the the steps.

{ appName: 'Yikes',
 androidBundleId: 'com.yikes.android',
 iosBundleId: 'com.yikes.ios',
 modified: false,
 createdOn: 2016-12-02T19:41:49.885Z,
 appKey: '51a22620-92b3-4c21-8125-0c6e7b3b98c0',
 undefined:
  Key {
    namespace: undefined,
    name: 'Yikes',
    kind: 'ClientApp',
    path: [Getter] } }

Thanks in advance.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Where do you do this console.log? If you did it inside the resolve of the Promise, it means that it did work and the entity should be saved in the datastore.

Also, have you tried saving a 'ClientApp' entity without gstore-node? Like in the example here: https://github.com/GoogleCloudPlatform/google-cloud-node#preview-2 to make sure your settings are ok.

from gstore-node.

digaresc avatar digaresc commented on May 25, 2024

Found the problem. The problem was that I had installed an older version of google datastore and I installed on top gstore-node. After I removed the older version everything worked perfect.
Probably because I started with one of the GoogleCloudPlatform/nodejs-docs-samples that had an older version. My bad.

Thanks for the fast support.
Happy to help around here.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Great, happy you found the solution.

PS: just one thing about your example. For now, gstore does not "render" what is set in the "default" value. I will add this feature soon. So your default to uuid.v4() will be the same value for all your entities... If you want this, great, otherwise for now you have to manually set it before saving.

from gstore-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.