刚注意到代码在 node.js 节点下很丑,大家克服一下
A: 连写型
db.upsert('article', {
id : 1
, title : 'Hello world'
, poster : 'kris'
, visit : 100
}).error(function(err) {
...
}).done(function(count) {
...
})
db.remove('article', { id: 1 })
.error(function(err) {
...
})
.done(function() {
...
})
db.find('article', {poster : 'kris'})
.between('visit', 100, 200)
.range(100, 200)
.done(function(err, rows, count) {
....
})
B: 回调型
oncedb.upsert('article', {
id : 1
, title : 'Hello world'
, poster : 'kris'
, visit : 100
}, function(err) {
...
})
db.remove('article', { id: 1 }, function(err) {
...
})
db.find('article', {poster : 'kris'}, function(err, rows) {
if (err) {
console.log(err)
return
}
console.log(rows)
}, { between: ['visit', 100, 200], range: [0, 100] })
看到现在很多库都用 A,node.js 标准 API 基本上是 B,大家喜欢哪一种? 大家觉得流行风格会不会变?