jensarps / idbwrapper Goto Github PK
View Code? Open in Web Editor NEWA cross-browser wrapper for IndexedDB
Home Page: http://jensarps.github.io/IDBWrapper/
License: MIT License
A cross-browser wrapper for IndexedDB
Home Page: http://jensarps.github.io/IDBWrapper/
License: MIT License
Limit on iterate() does not work in minified version
Works fine on non-minified
Hi.
Do someone try to use library for cordova android application ?
In mobile and desctop browsers all right. But IDBWrapper doesn't work for my android 4.1.2.
Is it possible use library for cordova ?
Thanks.
Hi there,
4 days ago, I got interested in IndexedDB and I came to use IDBWrapper for some tests (and also because it's a remarkable work)
Since then, Chrome 21 was released, and now, IDBWrapper doesn't seem to be working anymore (you have to delete manually your local databases to see it not working). I get this error :
Uncaught Error: InvalidStateError: DOM IDBDatabase Exception 11
When I check IndexedDB databases, i get this :
Security origin:http://jensarps.github.com
Name:appdb
Version:
It seems Chrome finally adopted some of the new "standards" (read this here https://groups.google.com/a/chromium.org/d/topic/chromium-html5/8C-NWF2FajA/discussion ) about the setVersion
or onupgradeneeded
methods
Do you know what needs to be corrected ?
Thanks again for your work !
The library doesn't seem to work in IE 11.
setting autoContune=false
throws an error if you don't iterate through all of the items.
To duplicate:
Deprecated Warning:
Numeric transaction modes are deprecated in IDBDatabase.transaction. Use "readonly" or "readwrite".
Just a simple forewarning if you weren't already aware.
when using compound indexes indexComplies will always fail (test in chrome). The problem appears to be here, expected[key]
will be an array and actual[key]
will be a DOMStringList.
I am unable to use the examples in Firefox 10, OSX. Works fine in Chrome.
[11:43:07.579] uncaught exception: [Exception... "This error occurred because an operation was not allowed on an object. A retry of the same operation would fail unless the cause of the error is corrected." code: "2" nsresult: "0x80660002 (NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR)" location: "http://jensarps.github.com/IDBWrapper/IDBStore.js Line: 60"]
Hi and thank you for your wrapper :D
I am building a mobile app where I am querying the local database.
I made fake range as lower and upper value are the same, and it works fine for object properties that are integer and strings but fails on boolean.
Error: DataError: DOM IDBDatabase Exception 0
Error: The data provided does not meet requirements.
at Object.IDBStore.makeKeyRange (http://myip/src/assets/libs/IDBWrapper-master/idbstore.js:949:36).
I have no idea how to solve it, I looked over Internet and found no example using query on boolean property, maybe you could provide a basic one. :)
Thanks
it would be nice to build a basic localStorage failover for non IndexedDB browsers that allows for basic index creation and querying by filtering the results.
var customers = new IDBStore({
dbVersion: 1,
storeName: 'customer',
keyPath: 'id',
autoIncrement: true,
onStoreReady: function(){
console.log('Store ready!');
}
});
var customers = localSorage['customer'][1] = {keyPath:'id',indexes:[{name:'firstname'},records:{}]};
Observed in Chrome (from version 25)
example:
http://jensarps.github.com/IDBWrapper/example/index/
Sometimes the entry doesn't get removed after action is made.
occures when:
I'm not sure when they added it, but as of Firefox 29 at least, autoIncrement
works fine: https://bugzilla.mozilla.org/show_bug.cgi?id=701772. So you should be able to get rid of the mozIndexedDB
sniffing.
Hiya, I'm trying to figure out why I'm getting a DataError
when writing this data to .batch
:
[
{ type: 'put', key: 'foobatch1', value: 'bar1' },
{ type: 'put', key: 'foobatch2', value: 'bar2' },
{ type: 'put', key: 'foobatch3', value: 'bar3' }
]
One thing I noticed is that batchTransaction.objectStore(this.storeName)
inside of the .batch
implementation returns an objectStore that has autoIncrement: true
and keyPath: "id"
(which is likely the cause of the DataError
above)
For my use case I need to totally disable keyPath and autoIncrement, so I"m using these options when initializing the IDBStore:
{
autoIncrement: false,
keyPath: ""
}
I also tried keyPath: false
and keyPath: null
but still got the same errors. Do you know if IndexedDB lets you control/influence the autoIncrement/keyPath on transaction objectStores? If not, do you have any suggestions on how I can write the above data in a batch transaction?
On the section that explain the members of the object provided to the IDBStore constructor, the line about indexes appears two time
create a IDBStore with 2 indexes. Increment dbVersion and remove one index. The index doesnt get deleted from the database
Null values can be successfully inserted via put()
.
However, in get()
, there is no difference between a missing key and one with value null
.
Do you think it is feasible to add an API to differentiate, or better add a second parameter to the get
onSuccess
callback to differentiate in this particular case?
This is needed to support the latest leveldown interface Level/level-js#41
I went to the examples site and it failed to save any information. Errors appear in the chrome console log concerning the native API. I'm on Chrome 49 desktop.
We should never get here.
Great. How do I debug this? I can't replicate it locally
Not sure if you've run into this but put() with a Uint8Array key results in a DataError
when we use the iterate ,we always need two indexes, but from the implementation,we can't do it, expect to support this new feature,thanks!
current API:
customers.iterate(onItem, {
index: 'lastname',
keyRange: IDBKeyRange,
order: 'ASC',
filterDuplicates: false,
writeAccess: false,
onEnd: onEndCallback,
onError: onErrorCallback
});
new API expect:
customers.iterate(onItem, {
[{
index: 'lastname',
keyRange: IDBKeyRange,
order: 'ASC'},
{
index: 'date',
keyRange: IDBKeyRange,
order: 'ASC'
}
],
filterDuplicates: false,
writeAccess: false,
onEnd: onEndCallback,
onError: onErrorCallback
});
can we do that ?
On latest firefox I get a 'DataError: Data provided to an operation does not meet requirements'.
var options = {
dbVersion: 1,
storePrefix : myprefix-',
storeName: 'settings',
keyPath: 'id',
autoIncrement : true,
onStoreReady : storeReadyFunc
};
idbs_settings = new IDBStore(options);
Later on I try a batch insert:
function saveSettings(options){
var operations = [];
for (var prop in options) {
if (options.hasOwnProperty(prop)){
var obj = {
id: parseInt(prop),
value: options[prop]
};
operations.push({
type : "put",
value : obj
});
}
}
idbs_settings.batch(operations,function(result){
_logger.log(result);
});
}
This works on Chrome and IE10, still not tested on Safari.
Can you please publish latest version to npm?
Thanks
Hello,
I have the issue with IDBWrapper functionality in Safari (Private Window) and in the iframe on iOS.
Error message: "TypeError: null is not an object (evaluating 'a')".
In another browsers and devices, everything works well.
I have used 1.6.0 version. In the latest version (1.7.1) I have the same issue.
How can I solve this issue? Do you have any suggestions?
Please check the simple code example below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/idbwrapper/1.6.0/idbstore.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Test</h1>
</body>
</html>
var customers = new IDBStore({
dbVersion: 1,
storeName: 'customer',
keyPath: 'id',
autoIncrement: true,
onStoreReady: function(){
console.log('Store ready!');
}
});
You can check it on this page: https://gist.github.com/jensarps/1391434#file-index-html
Thanks!
Here is usage example:
var dude = {
firstname: 'John',
lastname: 'Doe',
age: 52,
emails: [
'[email protected]',
'[email protected]'
]
};
var onsuccess = function(id){
console.log('Yeah, dude inserted! insertId is: ' + id);
}
var onerror = function(error){
console.log('Oh noes, sth went wrong!', error);
}
customers.put(dude).done(onsuccess).fail(onerror)
$.when(customers.put(dude), customers.put(dude), customers.put(dude)).done(function() {alert('awesome');});
We're experiencing the following in Internet Explorer 11 on Windows 8.1. We're creating an IDBStore with the following config:
var IdbWrapper = require("idb-wrapper"); // we're using npm and browserify
new IdbWrapper({
"storePrefix": "XX-",
"dbVersion": 2,
"indexes": [{"name":"user.id","keyPath":"user.id","unique":false,"multiEntry":true}],
"keyPath":"activityId",
"storeName":"activities"
});
We bumped the dbVersion to 2, because this is the first time we're changing the schema by adding an index to this database. In Internet Explorer now the following happens: We clear all IndexedDB files through the Settings, then refresh the application in the browser, click through functionality that uses this database, everything is fine. Then we refresh the application again, and this time, when the IDBStore is initialised, we get the following error:
ERROR initializing idbWrapper
Cannot modify index "user.id" for current version. Please bump version number to 3."
If we then bump the version to 3, the same thing happens again, after second refresh it asks us to bump to 4, etc.
Any idea why this might be happening?
Thanks a lot.
Hey :)
I just downloaded your code trying to run it, but it doesn't work on my Firefox 10, as I supposed.
I think it depends on Mozilla's IndexedDb last changing specs, so I opened a topic about this issue, that you can read here: https://support.mozilla.org/it/questions/919121
Best regards,
Mathew.
Is it possible to load from store only certain fields of an item not a whole data piece?
It is possible to disable "Allow websites caches and databases" e.g. in IE10/11.
If databases are disabled this.idb
is null
. This should be handled in the openDB
function.
new Date() when called quickly twice gives the same id thus the keys are not random.
Use something like https://github.com/dominictarr/monotonic-timestamp instead
When I go to the console in your Quick Test example in Chrome, I type in:
x = new IDBStore({storeName: "x"})
Then I type:
y = new IDBStore({storeName: "y"})
I get a "Failed to set version" error.
Hi,
Would it be possible to publish this module to npm without the closure compiler jar and the examples?
I tried looking around but didn't see where closure is used.. maybe I missed it.
Thanks
Yaniv
Hi,
Is there a way to set a limit
/offset
when using the query
method? It seems that the only way to configure the query is makeKeyRange
, but unless I am missing something it doesn't let you set a offset or limit.
Thanks
Regards
Looking through the closed issues (like #65), am I correct in assuming that this doesn't work with Apple's version of IndexedDB? Asking because there are still environments like WKWebView where not only is IndexedDB broken (due to Apple's bugs), but WebSQL is disabled too, so you can't shim it.
It would be nice to have a putAll method to iterate over an array of objects and put them
I am getting this error(Error: undefined is not an object (evaluating 'this.store.query')) from https://github.com/mWater/minimongo/blob/master/dist/minimongo.js#L832
When I install https://github.com/axemclion/IndexedDBShim
I see here https://github.com/jensarps/IDBWrapper/blob/master/idbstore.js#L47 that this shim should be supported?
I am working on iOS WKWebView. It is a cordova app and all the research that I can turn up says that iOS has botched the implementation bad. But the shim claims to be able to fix it. And it does get me past the original error from within minimongo which was db = undefined.
indexeddbshim/IndexedDBShim#244
So I originally created an issue in the shim repo thinking that installing it broke something with IDBStore making the query method disappear. But then I got digging deeper and saw that IDBWrapper seems to be intending to coexist with the shim as is.
Is there a specific version that works better? Or is this a real bug? Or is the assumed support not really there? Any suggestions otherwise?
Don't throw or log errors.
Have a callback for errors preferably the one I pass to IDBWrapper and pass them an error there
var store = IDBWrapper(opts, function (err) {
if (err) { /* I handle it */ }
// store is ready
})
in function get (line 266 in the source file at this moment), at line:
var getTransaction = this.db.transaction([this.storeName], this.consts.READ_ONLY);
In Chromium (Linux) works fine, on Firefox 14.0.1, Linux, I got the error, after a Shift-F5, full reload of the page and next attempt, everything works ok. So I presume it's a bug related only to the first time opening (creating) of the database file.
Teo
Hey, I love your library.
Does it work with any of the polyfills? I want to use it on Safari.
var myStore = new IDBStore({
storeName: 'Store',
storePrefix: 'IDBWrapper-',
})
Will create database IDBWrapper-Store and object store Store inside, I don't see how to have more then one store in one db, why?
Hello,
I have an issue on FF 47 (at least). When we open two times the same page using IDBWrapper,
the database seems to corrupt itself. I get this error : 'Object store couldn't be created' even after rebooting FF.
To solve the problem i must clear IDB files in firefox folders. :(
Do you have an idea of what can be the problem?
Thank you very much.
The only thing keeping me from using this library is line 42:
this.dbName = 'IDBWrapper-' + this.storeName;
Why are you adding a prefix (that isn't even configurable) to the store name?
I tried to run the examples in FF15 and Chrome Version 23.0.1270.0 canary. Example JS errors:
ff:
InvalidStateError: A mutation operation was attempted on a database that did not allow mutations.
http://jensarps.github.com/IDBWrapper/IDBStore.js
Line 253
chrome:
Uncaught TypeError: Type error
new safari supports indexeddb (supposedly) but ive heard this wrapper does not work with it. anyone test this?
Hi.
I didn't know if I should send you an email or submit an issue on GitHub, so there it is. I'm not familiar with GitHub, so tell me if I'm doing anything wrong :]
As I'm starting to play around with IDBWrapper, I tried to create an index for my objectStore (I'm using your "basic" example) :
(I'm using Chrome 21 & 22. FF is kinda lame for debugging IndexedDB right now)
function init() {
// create a store ("table") for the customers
customers = new IDBStore({
dbName: 'appdb',
storeName: 'customer',
keyPath: 'customerid',
autoIncrement: true,
onStoreReady: storeIsReady
});
/// ... ///
}
function storeIsReady() {
customers.createIndex('lastname', 'lastname', true);
refreshTable();
}
I instantly get this (now infamous) error :
Uncaught Error: InvalidStateError: DOM IDBDatabase Exception 11
This error occurs in the createIndex
function, when enterMutationState
enters in the onSuccess event.
Line 357 (on the last commit)
var result = evt.target.result;
So after working around the file and reading this discussion (https://groups.google.com/a/chromium.org/forum/?fromgroups#!topic/chromium-html5/RQFrG9SDPTI), I modified the createIndex
, setVersion
and enterMutationState
functions :
enterMutationState: function (onSuccess, onError, options) {
if (this.newVersionAPI) {
this.dbVersion++;
var openRequest = this.idb.open(this.dbName, this.dbVersion, this.dbDescription);
openRequest.onupgradeneeded = onSuccess;
openRequest.onsuccess = onError;
openRequest.onerror = onError;
openRequest.onblocked = onError;
} else {
this.setVersion(onSuccess, onError, options);
}
},
/// ... ///
setVersion: function (onSuccess, onError, options) {
options || (options = {});
onError || (onError = function (error) {
console.error('Failed to set version.', error);
});
var versionRequest = this.db.setVersion(this.dbVersion);
versionRequest.onerror = onError;
versionRequest.onblocked = onError;
versionRequest.onsuccess = function (evt) {
if (options.waitForTransactionEnd) {
var transaction = versionRequest.result;
transaction.oncomplete = onSuccess;
} else {
onSuccess();
}
};
},
///...///
createIndex: function (indexName, propertyName, isUnique, onSuccess, onError) {
onError || (onError = function (error) {
console.error('Could not create index.', error);
});
onSuccess || (onSuccess = noop);
propertyName || (propertyName = indexName);
var options = {waitForTransactionEnd:true};
var that = this;
this.enterMutationState(hitch(this, function (evt) {
var result = evt.target.db;
var index;
if (result.objectStore) { // transaction
index = db.objectStore(this.storeName).createIndex(indexName, propertyName, { unique: !!isUnique });
} else { // db
var putTransaction = result.transaction([that.storeName] /* , this.consts.READ_WRITE */);
var store = putTransaction.objectStore(that.storeName);
index = store.createIndex(indexName, propertyName, { unique: !!isUnique });
}
onSuccess(index);
}), onError, options);
},
So right now, everything's a little smoother, but I still get the same error, only now occuring on this line :
index = store.createIndex(indexName, propertyName, { unique: !!isUnique });
I can't inquiry further today, but I guess something goes wrong with the transaction. Maybe I took a wrong approach on this problem ?
I tried this library... doesnt work.. You'll get this error right from the start..... Unable to get property 'transaction' of undefined or null reference : line 466 in IDBStore.js
Hi, I was wondering if there is any lib that you guys use so this tool can work on ie9?
levelup has a nice batch api which basically means run the set of puts and removes in a single IDB transaction.
It would allow you to basically run multiple things in one transaction
msIndexedDB
according to their demo app: http://ie.microsoft.com/testdrive/HTML5/Cookbook/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.