Ionic 2 storage doesn’t have query method
I'm updating my app to Ionic 2 rc0 and using import {Storage} from "@ionic/storage"; But it doesn't have query method. It was there in beta 11 to query SQLite. How to query SQLite in rc0?
Try it
import { SQLite } from 'ionic-native';
let db = new SQLite(); db.openDatabase({ name: 'data.db', location: 'default' // the location field is required }).then(() => { db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
}, (err) => { console.error('Unable to execute sql: ', err); }); }, (err) => { console.error('Unable to open database: ', err); });
@bergmito Storage uses SQLite behind the scenes so why not query method because it was available in beta 11. I don't see any reason to remove it in rc0.
@aggarwalankush clearly something has changed in beta 11 i used to do:
import { SqlStorage, Storage } from 'ionic-angular';
...
storage = new Storage(SqlStorage);
But after rc0 upgrade am getting following error:
/node_modules/ionic-angular/index"' has no exported member 'SqlStorage'.
@jgw96 did you guys get rid of SqlStorage ?
@okonon I also used to do same but now we have @ionic/storage which automatically uses Sqlite behind the scenes, I don't know where is query method? @mlynch implemented that in this commit, maybe he can answer 👍
+1 - was using Storage.query() heavily!
I'm having the same problem. In my app I have a "service" with a lot of queries that access and change data in my database (sqlite). I use the query method and return promises (it isn't working anymore too), will I have to change all my code because of this change?
Same here. I'm using the query method for everything.
Hi everyone,
I have passed this info along to the team and will keep you posted on this.
Thanks, Dan
Additional Error (ionic rc 0)
When using example code from:
http://ionicframework.com/docs/v2/native/sqlite/
Got these errors (already try it on browser, emulator, ios device.. all the same) :
ERROR: ReferenceError: sqlitePlugin is not defined at http://localhost:8100/build/main.js:78458:13 at new t (http://localhost:8100/build/polyfills.js:3:15614) at SQLite.openDatabase (http://localhost:8100/build/main.js:78457:16) at new PCounter (http://localhost:8100/build/main.js:79945:24) at DebugAppView._View_HomePage_Host0.createInternal (HomePage_Host.ngfactory.js:20:24) at DebugAppView.AppView.create (http://localhost:8100/build/main.js:10658:21) at DebugAppView.create (http://localhost:8100/build/main.js:10870:44) at ComponentFactory.create (http://localhost:8100/build/main.js:6276:36) at NavControllerBase._viewInit (http://localhost:8100/build/main.js:46701:44) at NavControllerBase._transition (http://localhost:8100/build/main.js:46686:18)
I got the same - looking forward to hearing what we need to do!
Yes agreed, rightly or wrongly I was relying on Storage as an abstraction later to interact with a DB using .query - It would nicely abstract to websql or sqlite depending on whether I was working with "ionic serve" in the browser or against an actual device.
Another project broken here. Following this decision, how should we be abstracting queryable storage to work in both browser (for debugging with ionic serve) and the device environments?
This seems like a pretty fundamental bit of functionality that Ionic 2 just lost :(
I hope they will restore it ASAP - a lot of projects are using that functionality.
@bergmito have you tried that code in RC.0 ? I have tried it (straight from the docs) and it doesn't work for me?
This is urgent. RC0 is useless without Storage query method :/
Hi All,
I can't upgrade to rc0 😢 because of unavailability of query method so I'm unsure about below issue.
Following issue is not regarding query method, it's regarding get and set methods
Till beta 11, storage was in ionic-angular and it used to use kv as table name. https://github.com/driftyco/ionic/commit/f817ac0f6087e35e76086817e3a55c5c1b3fc4c1#diff-7e4a48359dfcc9528da611464b28ec11L87
Now from rc, storage has been moved @ionic/storage and as per my understanding, it uses _ionickv as table name https://github.com/driftyco/ionic-storage/blob/master/src/storage.ts#L42
But my app is in production with beta 11 and there would be lot of user data in kv table. So after upgrading to rc, how do I migrate kv table data to _ionickv?
Let me know if I can provide more details. @jgw96 @danbucholtz @mlynch
-Thanks
I'm having to downgrade to beta 11 to get this method back. I can't use a simple key/value store in my app sadly.
This is a important issue to solve!
@richardshergold yes. Here worked!! You add
providers: [
Storage
]
in app.module.ts?
I tried replace by SQLite, but it's not working here. An error related to NgModule :(