Giter Site home page Giter Site logo

Comments (14)

hozkok avatar hozkok commented on August 22, 2024 9

Hi Max. I think you misunderstood the issue.

The problem is not forEach support, but multiple instances.

In ionic storage, there is no multiple instances support so if we have a list of items of different data models, we have to iterate through every item in the whole database.

Let's say we have 100 different conversations and we try to iterate messages in one conversation, we have to iterate through all the messages in all the conversations if we do not have multiple instances.

But if we just create new instance for that particular conversation, we can just iterate through these messages.

from ionic-storage.

bergben avatar bergben commented on August 22, 2024 8

Any news on this?
The solution from @ahoebeke works but I think it would be cleaner to have a function for this wrapper that uses createInstance from localForage. That would be really great and shouldn't be much work I guess?

from ionic-storage.

ahoebeke avatar ahoebeke commented on August 22, 2024 5

I wanted to use separate storage databases.
mlynch's link to the source code helped me, it is easy enough to see how the Storage class prepares and returns a new storage object so I adapted that :

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage } from '@ionic/storage';

// import * as localforage from "localforage";
// import {SQLite} from "@ionic-native/sqlite";
//const win: any = window;

/*
  Generated class for the ApiServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ApiServiceProvider {

  private contacts: Array<Object>;
  private media: Array<Object>;

  private contactsDb : any;
  private mediaDb : any;

  //storage = new Storage();

  constructor(public http: Http /*, private contactStorage: Storage, private mediaStorage: Storage*/ ) {
    console.log('Hello ApiServiceProvider Provider');

    // this.contactsDb = storage.createInstance({
    //   name: "nameHere"
    // });

    this.contactsDb = new Storage({
      name: '__my_custom_db',
      storeName: '_contacts',
      driverOrder: ['sqlite', 'indexeddb', 'websql', 'localstorage']
    });
    this.mediaDb = new Storage({
      name: '__my_custom_db',
      storeName: '_media',
      driverOrder: ['sqlite', 'indexeddb', 'websql', 'localstorage']
    });

    this.contactsDb.get("contacts").then((result) => {
      this.contacts = result ? <Array<Object>> result : [];
      console.log("Contacts found: ", this.contacts);
    }, (error) => {
      console.log("ERROR: ", error);
    });

    this.mediaDb.get("media").then((result) => {
      this.media = result ? <Array<Object>> result : [];
      console.log("Media found: ", this.media);
    }, (error) => {
      console.log("ERROR: ", error);
    });
  }

  public addDemoContact() {
    let contact = {
      firstname: 'Jack',
      lastname: 'Johnson',
      emails: [
        '[email protected]',
        '[email protected]'
      ],
      phones: []
    };

    this.contacts.push(contact);
    this.contactsDb.set("contacts", this.contacts);
    console.log("Saved contact to database");
  }

  public addDemoMedia() {
    let media = {
      type: 'video',
      url: '#'
    };

    this.media.push(media);
    this.mediaDb.set("media", this.media);
    console.log("Saved media to database");
  }

}

from ionic-storage.

GuilhermeBCC avatar GuilhermeBCC commented on August 22, 2024 1

This is a security problem. I noticed that different users using the same machine are accessing information from each other. I have changed the DB names for each user but it is clear that there is a problem here.

from ionic-storage.

Apro123 avatar Apro123 commented on August 22, 2024 1

Yes, this would be very helpful. Are there any updates on this topic?

from ionic-storage.

mlynch avatar mlynch commented on August 22, 2024

We have forEach https://github.com/driftyco/ionic-storage/blob/master/src/storage.ts#L144

from ionic-storage.

mlynch avatar mlynch commented on August 22, 2024

thanks, I see.

from ionic-storage.

kesozjura avatar kesozjura commented on August 22, 2024

This would be great feature.

from ionic-storage.

brunodeprez avatar brunodeprez commented on August 22, 2024

Yes very important for me as well for same reasons explained by @hozkok Any chance to implement that?

from ionic-storage.

Fitzchev avatar Fitzchev commented on August 22, 2024

I'm currently using @ahoebeke method to create multiple instances, but my issue now is to drop either a specific objectStore or a database. I cannot find a way - I need the implementation of dropInstance() https://localforage.github.io/localForage/#multiple-instances-dropinstance

I can clear an objectStore, but it will stay there forever which is definitively not a good.

from ionic-storage.

Fitzchev avatar Fitzchev commented on August 22, 2024

I found a way to access LocalForage via ready() - thanks to my colleague! - and so you can have access to createInstance and dropInstance

myDB.ready().then(localForage => {
      localForage.createInstance(...)
      localForage.dropInstance(...)
});

If it can help...

from ionic-storage.

vishwas097 avatar vishwas097 commented on August 22, 2024

This is a security problem. I noticed that different users using the same machine are accessing information from each other. I have changed the DB names for each user but it is clear that there is a problem here.

How did you give different db names?

from ionic-storage.

rathodkaran07 avatar rathodkaran07 commented on August 22, 2024

Any update on this?

I have a little different case, but looks like this can solve my problem.

I am creating backup of db after every specific interval. On app uninstall I am trying to restore the db but an instance to default is created before copying the backup to its original place.

Can someone help with this?
@mlynch @Fitzchev @ahoebeke

from ionic-storage.

mlynch avatar mlynch commented on August 22, 2024

I believe v3 coming in a few weeks fixes this, will see

from ionic-storage.

Related Issues (20)

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.