gpt4 book ai didi

javascript - 低db : queries are synchronous or asynchronous?

转载 作者:行者123 更新时间:2023-12-02 14:05:02 26 4
gpt4 key购买 nike

我在 Node.js 中使用 lowdb:

https://github.com/typicode/lowdb

我不明白这句话:

the execution of methods is lazy, that is, execution is deferred until .value() is called.

如果我有这个代码:

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

我可以在该行之后使用 post 吗?

最佳答案

是的,看起来是这样。

这句话的意思是添加 .get().find() 方法只会细化最终的查询,但通过调用 .value() 查询实际上被执行。

鉴于示例代码,似乎 .value() 实际上为您提供了一个值,而不是对值或类似内容的 Promise。

关于javascript - 低db : queries are synchronous or asynchronous?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40123106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com