2019-02-05 04:51:50 +05:30
|
|
|
import QueryTarget from "./query-target.js";
|
2019-02-07 05:50:27 +05:30
|
|
|
import { reqAsPromise } from "./utils.js";
|
2019-06-27 01:30:50 +05:30
|
|
|
import { StorageError } from "../common.js";
|
|
|
|
|
|
|
|
class QueryTargetWrapper {
|
|
|
|
constructor(qt) {
|
|
|
|
this._qt = qt;
|
|
|
|
}
|
2019-09-15 15:54:27 +05:30
|
|
|
|
|
|
|
supports(methodName) {
|
|
|
|
return !!this._qt[methodName];
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
|
|
|
|
openKeyCursor(...params) {
|
2019-09-15 15:54:46 +05:30
|
|
|
// not supported on Edge 15
|
|
|
|
if (!this._qt.openKeyCursor) {
|
|
|
|
return this.openCursor(...params);
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
try {
|
|
|
|
return this._qt.openKeyCursor(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("openKeyCursor failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openCursor(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.openCursor(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("openCursor failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
put(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.put(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("put failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.add(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("add failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.get(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("get failed", err);
|
|
|
|
}
|
|
|
|
}
|
2019-07-27 14:10:56 +05:30
|
|
|
|
|
|
|
getKey(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.getKey(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("getKey failed", err);
|
|
|
|
}
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
|
2019-07-27 01:33:57 +05:30
|
|
|
delete(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.delete(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("delete failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-27 01:30:50 +05:30
|
|
|
index(...params) {
|
|
|
|
try {
|
|
|
|
return this._qt.index(...params);
|
|
|
|
} catch(err) {
|
|
|
|
throw new StorageError("index failed", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
|
|
|
export default class Store extends QueryTarget {
|
2019-06-27 02:01:36 +05:30
|
|
|
constructor(idbStore) {
|
|
|
|
super(new QueryTargetWrapper(idbStore));
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
get _idbStore() {
|
|
|
|
return this._target;
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
index(indexName) {
|
|
|
|
return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName)));
|
|
|
|
}
|
2019-02-07 05:50:27 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
put(value) {
|
|
|
|
return reqAsPromise(this._idbStore.put(value));
|
|
|
|
}
|
2019-02-07 05:50:27 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
add(value) {
|
|
|
|
return reqAsPromise(this._idbStore.add(value));
|
|
|
|
}
|
2019-07-27 01:33:57 +05:30
|
|
|
|
|
|
|
delete(keyOrKeyRange) {
|
|
|
|
return reqAsPromise(this._idbStore.delete(keyOrKeyRange));
|
|
|
|
}
|
2019-06-27 01:30:50 +05:30
|
|
|
}
|