Comments (5)
As with all asynchronous functions - you simply put your code which needs to run into the callback - something like this
db.loadDatabase(function (err) {
if (err)
console.log(err);
else {
// database is loaded - do your thing here...
}
});
It's crucial that you design your applications around this 'cascading' or 'waterfall' model - that each operation's success triggers the next (and that a failure causes everything to die in a manageable way).
from nedb.
Yes, of course I'm aware of this solution :)
But that's not the problem. The problem is that when my application want to get some data before database was loaded (and it does) I will have to implement some "deferred operations queue" or "stop the world until loaded" functionalities, when delegating this task to database engine make much more sense to me.
And by the way current behaviour (returning empty list without any warning) is actually kind of bug.
It would be very neat if database engine could simply accept all incoming requests, but execute them after "fully loaded" (what is perfectly ok, because database queries are asynchronous anyway).
from nedb.
Hello,
I'm still not quite sure about the need for that. It is not especially hard to do but it will take some time, so I want to be sure it's useful. Could you explain a situation where your app wants data before database was loaded ?
If I were to do it, I think it would be in the form of an "autoload" where the database is loaded as soon as it is created but that comes with the drawback that a query executed during the load will take longer to execute.
from nedb.
When all data accessors are ready to work just after instantiation (are not asynchroneous) you don't have to implement init state and init view in application, you can just jump to important stuff :).
So it's just a matter of convenience and ease of development. Of course you can live without it.
from nedb.
This is now done (as of v0.7.14).
Summary of the relevant part in the docs: if you use a persistent database, no operation will be executed unless you either call loadDatabase
manually or create the datastore using the autoload
option. In the latter case, loadDatabase
will automatically be called and any command issued before it finished will be buffered and be executed when load is finished.
For now the default for autoload
is false since it could produce unexpected behavior for people who actually want to control when db is loaded. The default will be true in the future.
from nedb.
Related Issues (20)
- NeDB datastore Model needs to be provided
- update the version of underscore dependence! HOT 1
- How to search multiple feilds' "$and"? HOT 4
- Add link to "official" fork HOT 8
- "this library is no longer maintained" HOT 7
- Insert doesn't take place immediately HOT 2
- How to catch abort if the capacity of storage is full??
- $setOnInsert is not work??????
- high vulnerabilities for this package HOT 2
- Error: Cannot create a string longer than 0x1fffffe8 characters HOT 1
- Please update dependency underscore HOT 4
- files
- Data Loss HOT 1
- Request to move repo under NW Userland
- PLEASE !!! Fork this project and create a new one HOT 1
- How to use expireAfterSeconds?
- i have a probleme to photo to nedb db HOT 1
- Regarding the issue of writing permissions
- Update creates a duplicate with exact same _id HOT 3
- How to switch to mongo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nedb.