hometown/app/javascript/mastodon/storage/db.js
2018-03-27 12:32:30 +02:00

29 lines
1.0 KiB
JavaScript

import { me } from '../initial_state';
export default new Promise((resolve, reject) => {
// Microsoft Edge 17 does not support getAll according to:
// Catalog of standard and vendor APIs across browsers - Microsoft Edge Development
// https://developer.microsoft.com/en-us/microsoft-edge/platform/catalog/?q=specName%3Aindexeddb
if (!me || !('getAll' in IDBObjectStore.prototype)) {
reject();
return;
}
const request = indexedDB.open('mastodon:' + me);
request.onerror = reject;
request.onsuccess = ({ target }) => resolve(target.result);
request.onupgradeneeded = ({ target }) => {
const accounts = target.result.createObjectStore('accounts', { autoIncrement: true });
const statuses = target.result.createObjectStore('statuses', { autoIncrement: true });
accounts.createIndex('id', 'id', { unique: true });
accounts.createIndex('moved', 'moved');
statuses.createIndex('id', 'id', { unique: true });
statuses.createIndex('account', 'account');
statuses.createIndex('reblog', 'reblog');
};
});