npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-simple-indexeddb

v2.0.2

Published

Easy way to implement Indexeddb

Downloads

2

Readme

NGX-SIMPLE-INDEXEDDB

This library aims to give you one better way to implement IndexedDB in Angular and more easy

Version 2.0.2

  • Was optimized code
  • Added new features
    • Now you can create database after initialize
    • Now you can export database or just one table

Install

npm install ngx-simple-indexeddb

Setup

Step 1 Add the module in your application inside on imports

....
import { NgxSimpleIndexeddbModule } from  'ngx-simple-indexeddb';
....

const databases = [
  {
    dbName: 'BD1', 
    dbVersion: 5,
    dbStoresMetaData: [{
      store: 'languages',
      storeConfig: { 
        autoIncrement: false 
      },
      storeIndexes: [
        { name: 'name', keyPath: 'name', options: { unique: false } }
      ]
    }, {
      store: 'companies',
      storeConfig: { 
        autoIncrement: true 
      },
      storeIndexes: [
        { name: 'name', keyPath: 'name', options: { unique: true } },
        { name: 'antique', keyPath: 'antique', options: { unique: true } },
      ]
    }]
  }
];


@NgModule({
	declarations: [
	...
	],
	imports: [
		...,
		NgxSimpleIndexeddbModule.forRoot(databases),
		...
	]
})
export  class  AppModule { }

Step 2

  • Call service when you need to use it
  • Inject in constructor
import { NgxSimpleIndexeddbService } from  'ngx-simple-indexeddb';

....

constructor(
	private _sIDB: NgxSimpleIndexeddbService
) { }

...

ngOnInit(): void {
	/*This subscription listen events like save, update, delete, delete store, delete DB, you can apply your logic inside the this block subscription*/
	this._sIDB.eventsIndexedObs.subscribe(res => console.log(res));
}

Step 3 Execute operation needed

addItems

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true| |data|any||Data to save| true |

  • Create record(s) with autoincrement true
this._sIDB.addRecords('BD1', 'companies', {name: 'AWS', antique: 25})
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });
  • Create record(s) with autoincrement false (is necessary add to each item pk attribute)
//With pk
const  data = [
	{pk: 1, name:  'Java'}, 
	{pk: 2, name:  'Dart'},
	{pk: 3, name:  'C#'}
];
this._sIDB.addItems('BD1', 'languages', data)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

getItem

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true| |key|string|number||Key object to find| true| |indexName|string||Key Name index| false|

  • Get record without index
this._sIDB.getRecord('BD1', 2)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });
  • Get record with index
this._sIDB.getItem('BD1', 'languages', 'AWS' 'name')
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

getRecords

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true| |withKeys|boolean|false|If you set this attribute in true, the response of query will return the primary key of each object and value| false|

  • Get list records without primaryKey
this._sIDB.getRecords('BD1', 'languages')
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });
  • Get list records with primaryKey
this._sIDB.getRecords('BD1', 'languages', true)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

updateRecord

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true| |key|string|number||Key object to find| true| |newValue|any||Object to save| true|

  • Update record
const data = {pk: 3, name: 'Rust'};
this._sIDB.updateRecord('BD1', 'languages', 3, data)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

deleteRecord

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true| |key|string|number||Key object to delete| true|

  • Delete record
this._sIDB.deleteRecord('BD1', 'languages', 2
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

countRecords

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true|

  • Delete record
this._sIDB.countRecords('BD1', 'languages')
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

clearObjStore

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true|

  • Delete object store
this._sIDB.clearObjStore('BD1', 'languages')
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

deleteObjStore

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true| |storeName|string||Name of Object Store|true|

  • Delete object store
this._sIDB.deleteObjStore('BD1', 'companies')
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

removeDB

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of Database|true|

  • Remove database
this._sIDB.removeDB(database)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

addDatabase

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|IDBSchema||Schema of new database|true|

  • Create database
const newDatabase = {
  dbName: 'BD2', 
  dbVersion: 5,
  dbStoresMetaData: [{
    store: 'cars',
    storeConfig: { 
      autoIncrement: true 
    },
    storeIndexes: [
      { name: 'name', keyPath: 'name', options: { unique: false } }
    ]
  }]
};

this._sIDB.addDatabase(newDatabase)
    .subscribe({
        next: (data) => console.log(data),  
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

exportToJSON

| Attribute |Type |Default | Description | Required | |-----------|-----|--------|-------------|----------| |database|string||Name of database|true| |storeName|string||Name of Object Store|false| |withKeys|boolean|false|If you set this attribute in true, the response of query will return the primary key of each object and value| false|

  • Export database or table
this._sIDB.exportToJSONDatabase(newDatabase)
    .subscribe({
        next: (data) => console.log(data), //Observable return data exported
        error: (error) => console.error(error),
        complete: () => console.log("Complete")
      });

Catalog Objects and Interfaces

This interface contain the data structure when observable emit data: ResponseStoreIndexedDB

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |event |string|Emitted event executed|true| |dbName |string|Name of database|true| |storeName |string|Name of store|false| |data |any |Emitted data result of execution|false|

This class contain the main structure to build database IDBSchema

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |dbName|string|Name database|true| |dbVersion |number|Number version|false| |dbStoresMetaData |Array<StoreMetaDataConfig> |Contains config stores|true|

This class contain the structure of store StoreMetaDataConfig

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |store|string|Name store|true| |storeConfig |StoreConfig|Config store|true| |storeIndexes |Array<IndexObj> |Contains indexes of stores|false|

This interface contain the structure of store StoreConfig

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |keyPath|string|Name key path|false| |autoIncrement |boolean|Set if key is autoincrement|true|

This interface contain the structure when you needed add to store indexes IndexObj

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |id|string|Id index|true| |keyPath |string|Name of key path|true| |options |OptionsIndex |Set options index|true|

This interface contain the structure of options to each index OptionsIndex

| Attribute |Type |Description |Required | |-----------|-----|------------|------------| |unique|boolean|Set if data is unique|true|