Comments (10)
Hey ya,
I'm a bit confused about your question, specifically:
Whenever I use load, it always returns err as false, which means it never loads the data initially
Any stored data is loaded into the collection and the call to load() then tells the callback if an error occurred (which almost always will be false - which is expected behaviour).
which means it never loads the data initially
Returning err = false doesn't mean the data isn't loaded.
from forerunnerdb.
Okay, so it appears that collection.load() just check to see if the collection exists and if it does, it loads it. However, how would you recommend handling my scenario? I want to load the local collection not only if it exist but it contains data (particularly the case when a user changes the route (SPA)). However, if the collection is empty, it needs to be loaded.
from forerunnerdb.
The .load() method will only return an error if it actually fails, not if persistent storage data exists or not. I can add an operation summary as data in the second returned parameter in the callback if you like that will describe if data was found and if so, how many records were found.
I think that would solve your problem.
It would be something like this:
db.collection('test').load(function (err, response, op) {
if (!op.foundData) {
// Load our data from the API
} else if (op.rowCount < someExpectedNumberOfDocs) {
// Load data again as we are missing some since last time the app was loaded
}
});
If that would solve your problem let me know!
from forerunnerdb.
Please clone the dev branch and let me know if that solves your issue as usage is described above.
from forerunnerdb.
Thanks for working on this. I grabbed dist/fdb-core+persist.js from your dev branch and attempted to use it. It doesn't appear to have the new code. Which one should I use?
from forerunnerdb.
Hmm, it should do! But try using fdb-all.js first. That definitely has it as it is an "all modules enabled" build.
core+persist should be ok though...
from forerunnerdb.
Oops, looks like my example above was incorrect, the operation data comes back in the third argument of the callback, not the second. I've updated the example above.
from forerunnerdb.
Just to say I came across this issue as I wanted to load the data at app startup from persistent storage, falling to network request if data not found. The callback params are perfect to check this out. As this could be very useful (IMHO), I suggest you to include in the documentation for the collection.load
method.
I found response
and op
to have the same content (not the same == object), BTW.
cheers
from forerunnerdb.
I believe the API has been updated since this issue was raised. The callback now contains:
callback(err, tableStats, metaStats);
The err is obvious, either falsy for no error or something non-falsy for an error.
The other two are:
tableStats - The details about the data loaded for the collection.
metaStats - The details about the data loaded for the collection's meta data (meta data includes stuff like last change timestamp for the collection etc).
I will update the load method docs to reflect this. :)
from forerunnerdb.
OK, I've updated the docs on the edge branch as per the commit shown above.
from forerunnerdb.
Related Issues (20)
- Clarity about find(); HOT 2
- upsert that resolves to update does not update fields that start with '$' HOT 5
- TypeError: http.IncomingMessage.prototype is not an object or null HOT 6
- Support for $not operator HOT 3
- Interactive Demo HOT 1
- index not used when using query operator
- collection.load is very slow HOT 1
- Loading JSON file into forrunner db file and vice versa ? HOT 8
- Duplicate data when setData and ensureIndex HOT 1
- Adding event listener with an ID does not work HOT 2
- Dropping condition does not remove memory reference
- $replace with new documents?
- How does load work? HOT 2
- using Date query with $gte and $lte operators. HOT 3
- Typescript is outdated HOT 3
- Where can i find the database file?
- Weird query behavior when using elemMatch
- WebWorker import ForerunnerDB
- ⚠️ Web SQL is deprecated
- How to query condition on comparing 2 fields?
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 forerunnerdb.