3 ms·
> I spent some of this weekend playing with IndexedDB, its very hard to get into at the moment, mostly due to the different implementations across mozilla / chr
by MatthewPhillips 15y ago
> I spent some of this weekend playing with IndexedDB, its very hard to get into at the moment, mostly due to the different implementations across mozilla / chrome, but there is some complexity that doesnt look easily solved by a wrapper, just understanding what is meant by onupgradeneeded / setversion seems needlessly complex.
This is definitely an annoyance but it is pretty easy to overcome:
const DB_VERSION = 1;
req.onupgradeneeded = function(e)...
req.onsuccess = function(e) {
var db = e.target.result;
if(db.setVersion && Number(db.version) !== DB_VERSION) {
var dbReq = db.setVersion(DB_VERSION);
dbReq.onsuccess = function(e) {
req.onupgradeneeded(e);
req.onsuccess(e);
};
return;
}
// You can use db now.
};
> Other problems include "Indexed DB is not available in private browsing mode", how are people supposed to build offline webapps when the applications can easily be prevented from accessing their own data?
Good point, are there any queues to the developer that the browser is running in private mode? If so I think we just need to inform the user.
> IndexedDB is nice, but its quite opinionated and complex, I think browser vendors needs to think about what lower level constructs can be given to developers in order to create their own databases, and as much as I dislike the thought of SQL client side, I think it was probably a mistake to shoot websql so early on, sqlite is the standard of embedded databases.
There are going to be a lot of IndexedDB libraries once it becomes supported (in the modern spec) by all browsers. There will be libraries that give you a simple key/value store like localStorage does today (I'm working on one of these), there will be libraries that let you write SQL, and probably every other paradigm that people enjoy.