2

I'm using the linq2indexedDB wrapper to work with IndexedDB. I'm working in TypeScript but I don't think that's really relevant to the issue - it should just explain the slightly odd syntax. I create my DB and add a number of object stores and indices (code shortened to keep to the point):

var databaseDefinition = [{
        version: config.version,
        objectStores: [
            { name: "Regions", objectStoreOptions: { autoIncrement: false, keyPath: "ID" } },
            { name: "Countrys", objectStoreOptions: { autoIncrement: false, keyPath: "ID" } }
            // etc.
        ],
        indexes: [
            { objectStoreName: "Countrys", propertyName: "RegionID", indexOptions: { unique: true, multirow: false } }
            // etc.
        ]
    }];

This works, and by inspecting my db structure in chrome F12 tools I can see the expected objectStores. I then try a simple insert operation:

    var region = serverData.Regions[0];
    this.db.linq.from("Regions").insert(region, region.ID).then((args) => {
        tracer.Trace("Insert success: " + args);
    }, (args) => {
        tracer.Trace("Insert failure: " + args);
    });

This fails, but the args object returned is undefined, so I have no idea of why. Can anyone explain what the issue might be and how I can go about tracing it?

EDIT (Removed additional code as it wasn't strictly relevant to the issue. Turning on logging, as described in Kristof's answer below, helped track down the issue, which is resolved in my own answer below).

Jude Fisher
  • 11,138
  • 7
  • 48
  • 91

2 Answers2

2

Not 100% sure what the issue is, but there is no need to provide a key when a keypath is defined and a value for the keypath is present in the object.

I can't see all of your code, but did you create a new instance of the linq2indexeddb object?

if you did you can do the following:

var db = window.linq2indexedDB("dbName", dbConfig, true);

The last parameter will enable logging and all log results will be printed in the console output.

Another way is

linq2indexedDB.prototype.utilities.debug(true);

If you have any other questions regarding the linq2indexeddb, let me know. I wrote it ;)

Kristof Degrave
  • 4,142
  • 22
  • 32
  • Kristof - thanks for your response. I've fixed the keypath / key issue and turned on logging. The entire code and log error output are above. I'm getting a `TypeError` on the insert operation. What might cause this? – Jude Fisher Mar 08 '13 at 11:22
  • I'm working in chrome, btw, although the same error is present in IE10. I wonder if this is relevant: http://stackoverflow.com/questions/9738364/chrome-indexeddb-implementation-issues – Jude Fisher Mar 08 '13 at 11:25
  • Not really an idea, I really need to release a new version of my lib. I have improved error handling on that. Can you provide more information except the type of the error, maybe an error code or something? – Kristof Degrave Mar 08 '13 at 11:49
  • Found it: `IDBTransaction.READ_WRITE` is deprecated, or at least doesn't work in latest Chrome. Replacing this with `'readwrite'` fixes the issue, and the insert completes as expected. – Jude Fisher Mar 08 '13 at 11:55
  • Ah - did I miss downloading something? – Jude Fisher Mar 08 '13 at 11:57
  • I don't think so. Everything is in one file, I'll have to take a look at it :) – Kristof Degrave Mar 08 '13 at 11:58
  • Fine. I just did a find/replace of the constants and it works great. Thanks for your work on the library - it looks tremendously useful. – Jude Fisher Mar 08 '13 at 11:59
1

This turned out to be a small issue in the version of linq2indexedDB that I am using. The constants IDBTransaction.READ_ONLY and IDBTransaction.READ_WRITE are deprecated (ref). A quick search and replace, substituting the above with the strings 'readonly' and 'readwrite' respectively, fixed the issue for me.

Kristof mentions there may also be a shim to take care of this, but I don't seem to have that in the most recent version downloaded from codeplex.

Jude Fisher
  • 11,138
  • 7
  • 48
  • 91