jakearchibald / idb

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

Can't use the new version of openDB with a transaction #106

Closed BrunoAddeo closed 5 years ago

BrunoAddeo commented 5 years ago

Hi Jake,

In the "New 4.x way", openDB changes ... openDB('db-name', 1, { upgrade(db, oldVersion, newVersion, transaction) { console.log(oldVersion); console.log(transaction); }, }); ... so i'm not able to understand the syntax in order to use a transaction (something like "db.createObjectStore('myBase', {keyPath: 'id', autoIncrement: true})") in OpenDB

Is it possible to get an example ?

jakearchibald commented 5 years ago

I don't understand the question. Can you state what you're trying to do?

BrunoAddeo commented 5 years ago

I just would like to write :

 openDb('myBase', 4, upgradeDB => {
            upgradeDB.createObjectStore('myTable', {keyPath: 'id'});
        });

with the new version of IDB sorry for my poor english :-(

jakearchibald commented 5 years ago
const db = await openDB('myBase', 4, {
  upgrade(db, oldVersion, newVersion, transaction) {
    db.createObjectStore('myTable', { keyPath: 'id' });
  }
});

Does that work?

BrunoAddeo commented 5 years ago

Yes, it's ok ! Thanks :-)

jakearchibald commented 5 years ago

No problem!