Tag:

续集QueryChainer语法

与Sequelize QueryChainer有一些困难。 通常我不需要这样做,但是我决定尽早处理自己的关联,而不是使用build立在关联pipe理中的模块(事实certificate这是相当惩罚的)。 我正在写出我的REST例程,并试图删除一些基于已经提取或需要提取的logging的logging。 而不是有4-5嵌套的callback,我决定了QueryChainer和一个串行运行将是适当的。 在这个例子中,我带着一个用户,如果find了一个用户,我想拼凑一行查询来处理删除特定的关联。 我遇到的问题主要是在使用模型EventEmitting方法之外理解chainer的语法。 // Find user, destroy it and associations db.Models.user.find({ where: {STUID: id} }) .success(function (user) { if (!user) { res.locals.err = { status: 'FAILED', message: 'Could not delete user', reason: 'No user resource found' } } else { chain = new db._sqlize.Utils.QueryChainer(); chain.add(user.destroy()) // Check and destroy author association […]

如何浏览模块ethereumjs-tx?

我有这个演示代码我想broserify: var Tx = require('ethereumjs-tx') var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex') var rawTx = { nonce: '0x00', gasPrice: '0x09184e72a000', gasLimit: '0x2710', to: '0x0000000000000000000000000000000000000000', value: '0x00', data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' } var tx = new Tx(rawTx) tx.sign(privateKey) var serializedTx = tx.serialize() console.log(serializedTx.toString('hex')) 我几乎成功地安装了ethereum-tx: npm install -g ethereumjs-tx … npm WARN enoent ENOENT: no such file or directory, open […]

链接承诺与mongoose(mPromises)

我正在寻找如何链接使用nodejs / mongoose(mPromise)“fin或创build”function的承诺, 我目前尝试过: var findExistingUsername = function(value){ console.log('existusername'); return mongoose.models["User"].findOne({username: value}) .lean() .exec(); }; var findExistingEmail= function(value){ console.log('existusername'); return mongoose.models["User"].findOne({email: value}) .lean() .exec(); }; var validateEmail = function(value){ console.log('existusername'); var emailRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; console.log('Email valido?:' + emailRegex.test(email)); return emailRegex.test(email); }; var addUser = function(data){ console.log('existusername'); return mongoose.models["User"].create(data); }; UserSchema.methods = { validateAndAddUser: function(req, res) […]

蓝鸟承诺绑定链

我使用蓝鸟承诺,并试图允许链调用,但使用.bind()似乎并不工作。 我正进入(状态: TypeError:sample.testFirst(…)。testSecond不是函数 第一种方法是正确调用,并启动承诺链,但我还没有能够得到实例绑定工作。 这是我的testing代码: var Promise = require('bluebird'); SampleObject = function() { this._ready = this.ready(); }; SampleObject.prototype.ready = function() { return new Promise(function(resolve) { resolve(); }).bind(this); } SampleObject.prototype.testFirst = function() { return this._ready.then(function() { console.log('test_first'); }); } SampleObject.prototype.testSecond = function() { return this._ready.then(function() { console.log('test_second'); }); } var sample = new SampleObject(); sample.testFirst().testSecond().then(function() { […]