如何使用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
- 向本地主机请求远程服务器获取预检请求'Access-Control-Allow-Origin'
- 如何在App-Engine上运行的基于快速的Node JS应用程序中获取远程客户端的IP地址
- AngularJS不拦截地址栏的直接请求
- 如何将数据块发送到AWS
- 用nodejs组织文件夹结构和数据库查询,使用MVC模式expressionmongoose
- 使用Sequelize进行集成testing
- 查找某些字段与MongoDB和Node.js中的对象具有完全相同元素的文档
- 将节点上传的文件stream式传输到Azure blob存储
- 如何确认是否为MongoDB for ReactJS + NodeJS Express创build了数据库?