Comments (14)
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.
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.
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.
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.
Yes, this would be very helpful. Are there any updates on this topic?
from ionic-storage.
We have forEach
https://github.com/driftyco/ionic-storage/blob/master/src/storage.ts#L144
from ionic-storage.
thanks, I see.
from ionic-storage.
This would be great feature.
from ionic-storage.
Yes very important for me as well for same reasons explained by @hozkok Any chance to implement that?
from ionic-storage.
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.
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.
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.
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.
I believe v3 coming in a few weeks fixes this, will see
from ionic-storage.
Related Issues (20)
- Need help configuring the storage manager
- (question) rationale behind IndexedDB being the 1st driver in driversOrder ?
- The NgModule 'IonicStorageModule' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
- IOS app doesn't retain state after ionic/storage version(3.0.6) upgrade for ionic app HOT 1
- Not working when re opening the app in OFFLINE mode HOT 1
- Angular 15 updates in source code not available in npm HOT 5
- Angular 16 support HOT 22
- iOS 16.1 SDK update clears ionic storage HOT 2
- Unable to use SQLite for native storage (Android) but only IndexDB and localstorage works ,Error: No available storage method found HOT 2
- Error: No available storage method found when using CordovaSQLiteDriver with Ionic Storage HOT 1
- SQLite Installation HOT 1
- localForage-CordovaSQLiteDriver maintenance
- Storage access blocks the main ui HOT 2
- ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[AuthGuard -> StorageService -> Storage -> Storage]: NullInjectorError: No provider for Storage! HOT 2
- Method get is not working HOT 3
- Angular 16 upgrading HOT 3
- Random data losses on iOS HOT 4
- Update README for Angular users HOT 1
- Cannot find Driver enum. HOT 1
- switched args in storage.forEach documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionic-storage.