module.exports = { plugin: 'mysql-store', params: { name: 'test11', host: 'localhost', user: 'root', password: 'root', port: 3306, auto_increment:true } };
seneca-entity的save$的代碼分析mysql
var update = !!ent.id
若是有id,則會用update,不然用insertsql
if (ent.id$) { ent.id = ent.id$ query = QueryBuilder.savestm(ent) return done(null, {query: query, operation: 'save'}) } if (autoIncrement) { query = QueryBuilder.savestm(ent) return done(null, {query: query, operation: 'save'}) }
若是實體上有id$,則用它來做爲實體的id,不然檢查是不是自增的,自增的配置是在plugin的參數中指定,auto_increment:trueui
不然會調rem
seneca.act({role: actionRole, hook: 'generate_id', target: args.target}, function (err, result) {
來生成一個uuid,注意:這個uuid是36位,不是咱們經常使用的32位get