ngx-indexed-database
v0.0.40
Published
<div align="center"> <img src="https://w3c.github.io/IndexedDB/logo-db.svg" width="120"/> </div> <h1 align="center">ngx-indexed-database</h1>
Downloads
25
Maintainers
Readme
Usage
NgxIndexedDatabase module
import { NgxIndexedDatabaseModule } from "ngx-indexed-database";
@NgModule({
...
imports: [ NgxIndexedDatabaseModule, ... ],
...
})
NgxIndexedDatabase service
import { NgxIndexedDatabaseService } from "ngx-indexed-database";
...
export class XYZComponent {
constructor(private _ngxIndexedDBService: NgxIndexedDBService) {}
}
const ngxIndexedDBService = NgxIndexedDBService.getInstance();
Create
import { IndexedDBKeysDataType, IndexedDBStoreSchema, NgxIndexedDatabaseService } from "ngx-indexed-database";
...
const dbName = 'ngx-indexed-database';
const storeName = 'users';
const storeSchema: IndexedDBStoreSchema = {
id: { primary: true, unique: true, datatype: IndexedDBKeysDataType.INTEGER },
user_name: { datatype: IndexedDBKeysDataType.STRING },
email: { datatype: IndexedDBKeysDataType.STRING },
};
this._ngxIndexedDBService.createStore(dbName, storeName, storeSchema);
Delete
import { IndexedDBKeysDataType, IndexedDBStoreSchema, NgxIndexedDatabaseService } from "ngx-indexed-database";
...
const dbName = 'ngx-indexed-database';
const storeName = 'users';
this._ngxIndexedDBService.deleteStore(dbName, storeName);
NgxIndexedDatabaseStoreOperations service
import { NgxIndexedDatabaseStoreOperationsService } from "ngx-indexed-database";
...
export class XYZComponent {
constructor(private _ngxIndexedDatabaseStoreOperationsService: NgxIndexedDatabaseStoreOperationsService) {}
}
upsert
const data = { id: 1, user_name: 'test123', email: '[email protected]' };
this._ngxIndexedDatabaseStoreOperationsService.upsert(dbName, storeName, data);
delete
this._ngxIndexedDatabaseStoreOperationsService.delete(dbName, storeName, 1);
deleteBy
this._ngxIndexedDatabaseStoreOperationsService.deleteBy(dbName, storeName, "user_name", "test123");
clear
this._ngxIndexedDatabaseStoreOperationsService.clear(dbName, storeName);
find
this._ngxIndexedDatabaseStoreOperationsService.find(dbName, storeName, 1);
findBy
this._ngxIndexedDatabaseStoreOperationsService.findBy(dbName, storeName, "user_name", "test123");
findMany
this._ngxIndexedDatabaseStoreOperationsService.findMany(dbName, storeName, [1, 2, 3]);
findManyBy
this._ngxIndexedDatabaseStoreOperationsService.findManyBy(dbName, storeName, 'user_name', ['test123', 'test456']);
fetchAll
this._ngxIndexedDatabaseStoreOperationsService.fetchAll(dbName, storeName);
resetStores
this._ngxIndexedDatabaseStoreOperationsService.resetStores(dbName);
this._ngxIndexedDatabaseStoreOperationsService.resetStores(dbName, {
exclude: ['ABC']
});
this._ngxIndexedDatabaseStoreOperationsService.resetStores(dbName, {
only: ['DEF']
});
Enum
export enum IndexedDBKeysDataType {
STRING,
INTEGER,
OBJECT,
ARRAY,
BOOLEAN,
ANY
}
Interfaces
export interface IndexedDBStoreSchema {
[key: string]: {
primary?: boolean;
unique?: boolean;
datatype: IndexedDBKeysDataType
}
}