Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
71552aa243 | |||
ce3878e18b |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.26.2",
|
"version": "0.26.4",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -80,7 +80,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|||||||
if(persists.storage?.constructor.name == 'Database') {
|
if(persists.storage?.constructor.name == 'Database') {
|
||||||
(<Database>persists.storage).createTable({name: persists.key, key: <string>this.key}).then(table => {
|
(<Database>persists.storage).createTable({name: persists.key, key: <string>this.key}).then(table => {
|
||||||
if(key) {
|
if(key) {
|
||||||
table.set(key, this.get(key));
|
table.set(this.get(key), key);
|
||||||
} else {
|
} else {
|
||||||
table.clear();
|
table.clear();
|
||||||
this.all().forEach(row => table.add(row));
|
this.all().forEach(row => table.add(row));
|
||||||
|
@ -166,8 +166,11 @@ export class Table<K extends IDBValidKey = any, T = any> {
|
|||||||
return this.tx(this.name, store => store.getAllKeys(), true);
|
return this.tx(this.name, store => store.getAllKeys(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
put(key: K, value: T): Promise<void> {
|
put(value: T, key?: string): Promise<void> {
|
||||||
return this.tx(this.name, store => store.put(value, key));
|
return this.tx(this.name, store => {
|
||||||
|
if (store.keyPath) return store.put(value);
|
||||||
|
return store.put(value, key);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
read(): Promise<T[]>;
|
read(): Promise<T[]>;
|
||||||
@ -177,8 +180,9 @@ export class Table<K extends IDBValidKey = any, T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set(value: T, key?: K): Promise<void> {
|
set(value: T, key?: K): Promise<void> {
|
||||||
if(!key && !(<any>value)[this.key]) return this.add(value);
|
if(key) (<any>value)[this.key] = key;
|
||||||
return this.put(key || (<any>value)[this.key], value);
|
if(!(<any>value)[this.key]) return this.add(value);
|
||||||
|
return this.put(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
update = this.set;
|
update = this.set;
|
||||||
|
Reference in New Issue
Block a user