seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
351 stars 32 forks source link

Promise support #25

Closed soullivaneuh closed 2 years ago

soullivaneuh commented 2 years ago

Is your feature request related to a problem? Please describe. For complex requests implementation, like for data migration, I need to fetch data from many databases and use them to update others.

Using the current callback system is quite limiting, forcing me to chain the data fetch callbacks until the update one.

Describe the solution you'd like

Instead of callback, make this library embracing promises.

Using promises also allow us to use the async/await keywords to have a more imperative code structure that can be easier to read and understand on some cases. For example:

const user = await models.users.findOne(...);
await model.orders.update({ _id: 42 }, { customerId: user._id });

Describe alternatives you've considered I don't see any alternative.

Additional context

This was a subject already evoked on the original project (https://github.com/louischatriot/nedb/issues/673) but without any official answer.

arantes555 commented 2 years ago

@soullivaneuh I think you may have missed it, but this version of NeDB has supported a Promise-based interface for months. See https://github.com/seald/nedb/blob/master/CHANGELOG.md#300---2022-03-16

soullivaneuh commented 2 years ago

Oh my god, I indeed come from directly the old NeDB project with my old implementation.

Sorry for this stupid move, and thanks for the quick answer!