mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-26 08:39:11 +01:00
28 lines
736 B
JavaScript
28 lines
736 B
JavaScript
import { useEffect } from 'react';
|
|
import { openDB } from 'idb';
|
|
import actions from './actions';
|
|
|
|
const useIdb = (dispatch) => {
|
|
useEffect(() => {
|
|
let dbName = `grafnode`;
|
|
let connection = openDB(dbName, 1, {
|
|
upgrade(db, oldVersion, newVersion, transaction) {
|
|
switch(oldVersion) {
|
|
case 0:
|
|
const collectionStore = db.createObjectStore('collection', { keyPath: 'uid' });
|
|
collectionStore.createIndex('transactionIdIndex', 'transaction_id');
|
|
}
|
|
}
|
|
});
|
|
|
|
connection.then(() => {
|
|
dispatch({
|
|
type: actions.IDB_CONNECTION_READY,
|
|
connection: connection
|
|
});
|
|
})
|
|
.catch((err) => console.log(err));
|
|
}, []);
|
|
};
|
|
|
|
export default useIdb; |