Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

SchemaError on indexed objects

Open MStapelfeldt opened this issue 1 year ago • 1 comments

Hi there, I have a pretty strange Error, and I can't find out why this happens. My db.js:

export const db = new Dexie('database');
db.version(1.4).stores({
  // Table to store badges which got loaded by #list_badges
  badges: "&rfid, project_id", // , label, global_id, valid_now, allowed_areas
});

list.svelte:

      for (const key in data) {
        // key has value of rfid id and is used as primary key in DB
        if (data.hasOwnProperty(key)) {
          const entry = data[key];
          // use put to update entries and add new items
          await db.badges.put({
            rfid: key,
            // project_id is set by svelte
            project_id: project_id,
            label: entry.label,
            global_id: entry.global_id,
            valid_now: entry.valid_now,
            allowed_areas: entry.allowed_area_ids,
          });
        }
      }
      await db.badges.where(project_id).notEqual(project_id).delete();

On .delete() I get the error name: 'SchemaError', message: 'KeyPath 467 on object store badges is not indexed'. I don't get why, because on stores({}) I declared the indexes (I think). Is this an issue of dexie/indexeddb or is it me?

MStapelfeldt avatar Oct 04 '23 08:10 MStapelfeldt

Change the line:

await db.badges.where(project_id).notEqual(project_id).delete();

to

await db.badges.where('project_id').notEqual(project_id).delete();

dfahlander avatar Oct 04 '23 10:10 dfahlander