Skip to content

Commit

Permalink
0.0.848
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Oct 28, 2024
1 parent 6bf65fb commit 7ef9935
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion env/BaseIndexedDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class BaseIndexedDB {
request.onupgradeneeded = (event) => {
this.#db = event.target.result;
if (!this.#db.objectStoreNames.contains(this.storeName)) {
this.#db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
this.#db.createObjectStore(this.storeName, this.dbOptions);
}
};
request.onsuccess = async (event) => {
Expand Down
6 changes: 4 additions & 2 deletions env/BaseIndexedDB.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export class BaseIndexedDB{
export abstract class BaseIndexedDB{
#db: any;
get db(){
return this.#db;
}
constructor(public dbName: string, public storeName: string, public version: number){}

abstract get dbOptions(): IDBObjectStoreParameters;

async openDB(){
let version = 1;
Expand All @@ -27,7 +29,7 @@ export class BaseIndexedDB{
request.onupgradeneeded = (event: any) => {
this.#db = event.target.result;
if (!this.#db.objectStoreNames.contains(this.storeName)) {
this.#db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
this.#db.createObjectStore(this.storeName, this.dbOptions);
}
};

Expand Down
3 changes: 3 additions & 0 deletions env/IndexedDBTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { BaseIndexedDB } from './BaseIndexedDB.js';
export class IndexedDBTable extends BaseIndexedDB {
get dbOptions() {
return { keyPath: 'id', autoIncrement: true };
}
async addRow(data) {
return await this.idbAction('add', data);
}
Expand Down
4 changes: 3 additions & 1 deletion env/IndexedDBTable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {BaseIndexedDB} from './BaseIndexedDB.js';
export class IndexedDBTable<TItem> extends BaseIndexedDB {


get dbOptions(){
return { keyPath: 'id', autoIncrement: true }
}

async addRow(data: TItem) {
return await this.idbAction('add', data) as number;
Expand Down

0 comments on commit 7ef9935

Please sign in to comment.