Giter VIP home page Giter VIP logo

angular2-typescript-indexeddb-service's Introduction

Angular2 Typescript IndexedDB Service Example

This is a sample of IndexedDB Service written for Angular2 Typescript.

  1. How it works

    • I have created Angularjs2 Typescript IndexedDB Service sample based.
    • This is just an example how you can create your own service and start working with IndexedDB.
  2. Installation

    • Just copy paste the Service code into your project and inject it when needed. There is also an example inclided in the repository. You can run the example by following the below steps.
    • Install the latest nodejs version.
    • Clone the git repository
    • Open the command window
    • Navigate to the example folder
    • npm install
    • npm run typings install
    • gulp (may throw typings errors, but will compile. Will be fixed in the next builds)
    • npm start
    • More information at https://angular.io/docs/ts/latest/quickstart.html

Very basic unit tests included just to show how Observable object can be tested via jasmine.

angular2-typescript-indexeddb-service's People

Contributors

suleodu avatar velingeorgiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular2-typescript-indexeddb-service's Issues

How to remove all objects from a store without deleting the database

I'm trying to clear out all the records in a schema without deleting the database, and I can't quite wrap my head around it.

I'm trying this, but not only does it not work, but the second console.log (inside the return Observable block) doesn't ever fire.

Can you clarify what I'm doing wrong here?

    deleteAllRecords(source: string): Observable<any> {
        let self = this;
        console.log("deleteAllRecords:",source);

        return Observable.create((observer: any) => {
            this.open().subscribe((db: any) => {
                let tx = db.transaction(source, "readwrite");
                let store = tx(source);

                let request = store.clear();
                console.log("request:",request);

                tx = (e: any) => {
                    observer.next();
                    db.close();
                    observer.complete();
                };
                db.onerror = (e: any) => {
                    db.close();
                    self.handleError("IndexedDB error: " + e.target.errorCode);
                }
            });
        });
    };

Bug or my Problem?

Erro: Failed to execute 'createIndex' on 'IDBObjectStore': An index with the specified name already exists.

this.produtos = [
      // tslint:disable-next-line:max-line-length
      { 'cst_pis': '7', 'ncm': '48196000', 'origem_mercadoria': null, 'cest': null, 'domain_id': '99c72db39a5c41708478c5390541af9c', 'cfop': '5', 'valor_unitario': '1.99', 'codigo': '3360', 'cst_icms': null, 'descricao': 'CAIXA DE PANETONE P', 'ean': '7898455106513', 'unidade': 'UN', 'id': '00568764d66f4caaabbae663b6ab2b90', 'cst_cofins': '7', 'csosn_icms': '102' }
    ];

.......

  public updateData() {
    this.DataBase = [];
    this.DataBase.push({
      name: 'Produtos',
      // tslint:disable-next-line:max-line-length
      indexes: ['valor_unitario', 'codigo', 'descricao', 'unidade', 'id'],
      seeds: this.produtos
    });

    this.idbService.clear().subscribe(done => {
      this.idbService.create(this.DataBase).subscribe(done => {
        this.databaseCreated = true;
        this.idbService.all('Produtos').subscribe(
          itens => console.log(itens));
      });
    });
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.