如何使用Google数据存储创build模式(在JavaScript中)?

我正在编写使用Google数据存储的Nodejs应用程序。 我只是想知道如何设置架构与谷歌数据存储authentication过程。 基本上,我怎样才能做下面的代码与Google数据存储:

var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); var userSchema = mongoose.Schema({ local : { email : String, password : String, } }); // generating a hash userSchema.methods.generateHash = function(password) { return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); }; // checking if password is valid userSchema.methods.validPassword = function(password) { return bcrypt.compareSync(password, this.local.password); }; // create the model for users and expose it to our app module.exports = mongoose.model('User', userSchema); 

我刚开始使用Nodejs和Google Datastore,所以我很抱歉如果这个问题看起来很基本。

你用gstore-node库的例子几乎和Mongoose一样:

 // The connection should probably done in your server.js start script // ------------------------------------------------------------------ var ds = require('@google-cloud/datastore') var gstore = require('gstore-node'); gstore.connect(ds); // In your user.model.js file // -------------------------- var gstore = require('gstore-node'); var bcrypt = require('bcrypt-nodejs'); var Schema = gstore.Schema; var userSchema = new Schema({ email : {type: 'string', validate:'isEmail'}, password : {type: 'string'}, }); // custom methods (https://github.com/sebelga/gstore-node#custom-methods) // generating a hash userSchema.methods.texts = function(password) { return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); }; // checking if password is valid userSchema.methods.validPassword = function(password) { return bcrypt.compareSync(password, this.get('password')); }; // create the model for users and expose it to our app module.exports = gstore.model('User', userSchema); 

看看这个图书馆,我刚开始自己​​,这是迄今为止我发现最接近: https : //github.com/sebelga/gstore-node