我有一个简单的lokijs设置,我试图捕获Node JS中该库发出的各种事件。根据{{3}},看来LokiJS会发出以下事件:
(请注意,这些文件似乎在任何地方都没有明确记录...)
我有以下代码,但从未收到任何已发出任何这些事件的通知。我在做什么错了?
var loki = require('lokijs');
var db = new loki('test.db', {
// Options
});
db.on('init', () => { console.log('INIT'); });
db.on('loaded', () => { console.log("LOADED"); });
db.on('flushChanges', () => { console.log('flushChanges'); });
db.on('close', () => { console.log('close'); });
db.on('changes', () => { console.log('changes'); });
db.on('warning', () => { console.log('warning'); });
var users = db.addCollection('test_list');
users.insert([{name: "sue", password: "zzzz"}, {name: "ned", password: "erp"}]);
var result = users.find({name: 'john'});
console.log(result);
result = users.find();
console.log(result);
结果:
[]
[ { name: 'sue',
password: 'zzzz',
meta: { revision: 0, created: 1540065986001, version: 0 },
'$loki': 1 },
{ name: 'ned',
password: 'erp',
meta: { revision: 0, created: 1540065986001, version: 0 },
'$loki': 2 } ]
键盘和椅子之间最有可能出现短路,但我没有看到。 :)