Skip to content

Latest commit

 

History

History
69 lines (57 loc) · 1.34 KB

README.md

File metadata and controls

69 lines (57 loc) · 1.34 KB

simple-async-indexeddb

Javascript IndexedDb wrapper, promise based, very simple and lightweight

Usage

Create Service:

let dbService = new IndexedDbService();

Initialize service

Parameters

-databaseName: each service instance manages 1 databese -dataTables: array of objects with properties name, keyPath and index names

await dbService.init("MyDatabase", [
    { name: "DataTable1", keyPath: "id", indexes: ["name"] },
    { name: "DataTable2", keyPath: "id", indexes: ["name"] },
]);

Insert Data

await dbService.updateOrCreate("DataTable1", {id:1, name:"Name1"});

Update Data

await dbService.updateOrCreate("DataTable1", {id:1, name:"Name2"});

Update Data By Index

await dbService.updateOrCreate("DataTable1", {name:"Name2", newProp:"Some Value"});

Get By Id

Parameters

-tableName -value (id)

let data = await dbService.get("DataTable1", 1);

Get By Index

Parameters

-tableName -value -indexName

let data = await dbService.get("DataTable1", "Name2", "name");

Delete

Parameters

-tableName -value (id)

await dbService.delete("DataTable1", 1);

Delete By Index

Parameters

-tableName -value -indexName

await dbService.delete("DataTable1", "Name2", "name");