2.0.8 • Published 5 years ago

indexed-db2-storage v2.0.8

Weekly downloads
5
License
MIT
Repository
-
Last release
5 years ago

Indexed DB

This is simple Indexed DB storage packege which can be used to store information in the form of object. You can use this packege instead of localStorage or sessionStorage.

Installation instruction

Please follow below steps to utilize functions of indexed db.

Step-1 npm install rxjs --save
Step-2 npm install rxjs-compat --save
Step-3 npm install indexed-db2-storage --save

Instruction to use the package

How to use?

Please follow below instruction to implement indexed db in your angular application.

// In your component ts file

import { IndexedDBService } from 'indexed-db2-storage';

First way to utilize service

// Extend the service to utilize its functions

export class AppComponent extends IndexedDBService {

    constructor() {
        super();
    }

    ngOnInit() {
        // Give Indexed Database Name
        this.setDBName('DatabaseName');

        // Create table. Here you can create multiple tables under single database
        //e.g let arrDB = [{ name: "Demo" }, { name: "Demo1" }]
        let arrDB = [{ name: "Table Name" }];
        this.createDB(arrDB).subscribe( result => {
            console.log('result', result);
        });

        // Add value to table
        this.post('TableName', { country : 'India' }).subscribe( result => {
          console.log('result', result);
        });

        // Update value to table
        this.put('TableName', { country : 'USA' }).subscribe( result => {
            console.log('result', result);
        });

        // Return value from table by id
        this.getById('TableName', 1).subscribe( result => {
            console.log('result', result);
        });

        // Return all records from table
        this.getAll('TableName').subscribe( result => {
            console.log('result', result);
        });

        // Remove value from table by id
        this.remove('TableName', 1).subscribe( result => {
            console.log('result', result);
        });

        // Return count of total records from table
        this.count('TableName').subscribe( result => {
            console.log('result', result);
        });

        // Remove / Clear databse
        this.clear().subscribe( result => {
            console.log('result', result)
        });
    }
}

Second way to utilize service

// Initilize the service to the constructor

export class AppComponent {

    constructor(private indexedDBService: IndexedDBService) {
        //TODO:
    }

    ngOnInit() {

        // Give Indexed Database Name
        this.indexedDBService.setDBName('DatabaseName');

        // Create table. Here you can create multiple tables under single database
        // e.g let arrDB = [{ name: "Demo" }, { name: "Demo1" }]
        let arrDB = [{ name: "Table Name" }] 
        this.indexedDBService.createDB(arrDB).subscribe( result => {
            console.log('result', result);
        });

        // Add value to table
        this.indexedDBService.post('TableName', { country : 'India' }).subscribe( result => {
          console.log('result', result);
        });
        
        // Update value to table
        this.indexedDBService.put('TableName', { country : 'USA' }).subscribe( result => {
            console.log('result', result);
        });

        // Return value from table by id
        this.indexedDBService.getById('TableName', 1).subscribe( result => {
            console.log('result', result);
        });

        // Return all records from table
        this.indexedDBService.getAll('TableName').subscribe( result => {
            console.log('result', result);
        });

        // Remove value from table by id
        this.indexedDBService.remove('TableName', 1).subscribe( result => {
            console.log('result', result);
        });

        // Return count of total records from table
        this.indexedDBService.count('TableName').subscribe( result => {
            console.log('result', result);
        });

        // Remove / Clear databse
        this.indexedDBService.clear().subscribe( result => {
            console.log('result', result)
        });
    }
}
2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago