jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.29k stars 353 forks source link

storing jsonld with idb #213

Closed scenaristeur closed 3 years ago

scenaristeur commented 3 years ago

Hi , i would like to use idb to store json-ld like https://json-ld.org/

{
  "@context": "https://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

but it seems that keyPath does not accept '@id'

    const db = await openDB('Contacts', 11, {
      upgrade(db) {
        // Create a store of objects
        const store = db.createObjectStore('contacts', {
          // The 'id' property of the object will be the key.
          keyPath: '@id',
          // If it isn't explicitly set, create a value by auto incrementing.
         autoIncrement: true,
        });
        // Create an index on the 'date' property of the objects.
        store.createIndex('date', 'date');
      },

    });

Is there a way to use keyPath : '@id' ?

image image

jakearchibald commented 3 years ago

Unfortunately keypath must be a valid identifier https://w3c.github.io/IndexedDB/#valid-key-path