ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Ionic 2 storage doesn’t have query method

Open aggarwalankush opened this issue 10 years ago • 98 comments

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?

aggarwalankush avatar Sep 28 '16 20:09 aggarwalankush

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 avatar Sep 28 '16 20:09 bergmito

@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 avatar Sep 28 '16 20:09 aggarwalankush

@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 avatar Sep 28 '16 21:09 okonon

@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 👍

aggarwalankush avatar Sep 28 '16 22:09 aggarwalankush

+1 - was using Storage.query() heavily!

baffleinc avatar Sep 29 '16 03:09 baffleinc

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?

stephanowallace avatar Sep 29 '16 03:09 stephanowallace

Same here. I'm using the query method for everything.

rafaelss95 avatar Sep 29 '16 03:09 rafaelss95

Hi everyone,

I have passed this info along to the team and will keep you posted on this.

Thanks, Dan

danbucholtz avatar Sep 29 '16 04:09 danbucholtz

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)

chmdznr avatar Sep 29 '16 12:09 chmdznr

I got the same - looking forward to hearing what we need to do!

richardshergold avatar Sep 29 '16 12:09 richardshergold

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.

danielabbatt avatar Sep 29 '16 13:09 danielabbatt

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 :(

davidnmbond avatar Sep 29 '16 13:09 davidnmbond

I hope they will restore it ASAP - a lot of projects are using that functionality.

edismooth avatar Sep 29 '16 13:09 edismooth

@bergmito have you tried that code in RC.0 ? I have tried it (straight from the docs) and it doesn't work for me?

richardshergold avatar Sep 29 '16 14:09 richardshergold

This is urgent. RC0 is useless without Storage query method :/

aldo-roman avatar Sep 29 '16 17:09 aldo-roman

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

aggarwalankush avatar Sep 29 '16 18:09 aggarwalankush

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.

larssn avatar Sep 29 '16 18:09 larssn

This is a important issue to solve!

drantunes avatar Sep 29 '16 19:09 drantunes

@richardshergold yes. Here worked!! You add

providers: [
Storage
]

in app.module.ts?

bergmito avatar Sep 29 '16 20:09 bergmito

I tried replace by SQLite, but it's not working here. An error related to NgModule :(

drantunes avatar Sep 29 '16 20:09 drantunes