Mark Mark - 9 months ago 78
Node.js Question

lowdb: queries are synchronous or asynchronous?

I'm using

lowdb
in
Node.js
:

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.


If I have this code:

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


may I use
post
just after that line?

Answer Source

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.

Given the example code, it seems like .value() actually gives you a value, and not a Promise to a value or anything like that.