简体   繁体   English

lowdb:查询是同步还是异步?

[英]lowdb: queries are synchronous or asynchronous?

I'm using lowdb in Node.js : 我在Node.js使用lowdb

https://github.com/typicode/lowdb https://github.com/typicode/lowdb

I don't understand this sentence: 我不明白这句话:

the execution of methods is lazy, that is, execution is deferred until .value() is called. 方法的执行是懒惰的,也就是说,执行被推迟到调用.value()为止。

If I have this code: 如果我有此代码:

const post = db.get('posts').find({ id: postId }).value();

may I use post just after that line? 我可以在那行之后使用post吗?

Yes, it looks like it. 是的,看起来像它。

The sentence means that adding .get() and .find() methods only refines the eventual query, but by calling .value() the query actually gets executed. 这句话意味着添加.get().find()方法只会优化最终查询,但是通过调用.value() ,查询实际上会得到执行。

Given the example code, it seems like .value() actually gives you a value, and not a Promise to a value or anything like that. 给定示例代码,似乎.value()实际上为您提供了一个值,而不是对值或类似内容的承诺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM