koa + sequelize ,到底该怎么结合? 有前辈用过么?
求推荐可以用在koa里的orm… 但找过一些例子,发现他们用sequelize就是直接yield就行了的… 我初始化如下 connect.js
exports = module.exports;
var Sequelize = require('sequelize');
var sequelize = new Sequelize('mysql://root:[email protected]:3306/dev', {
define: {
timestamps: false,
freezeTableName : true
}
});
var Models = require('../models');
exports.Invite = Models.Invite(sequelize,Sequelize);
exports.client = sequelize;
在koa的route里…
var a = yield connect.Invite.findOne({where:{Mobile: '13800138000'}});
console.log(a);
报错
var a = yield connect.Invite.findOne({where:{Mobile: '13800138000'}});
^^^^^^^
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
同样的位置, 官方demo的用法是ok的
var a = connect.Invite.findOne({where:{Mobile: '13800138000'}}).then(function(res) {
console.log(res.get());
});
console.log(a);