-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ionic 2 storage doesn’t have query method #8269
Comments
Try itimport { SQLite } from 'ionic-native'; let db = new SQLite(); }, (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:
But after rc0 upgrade am getting following error: |
+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, |
Additional Error (ionic rc 0) |
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 Now from rc, storage has been moved @ionic/storage and as per my understanding, it uses But my app is in production with beta 11 and there would be lot of user data in 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: [ in app.module.ts? |
I tried replace by SQLite, but it's not working here. An error related to NgModule :( |
try replacing
you need two variables: |
@aldo-roman ReferenceError: sqlitePlugin is not defined. |
@drantunes did you add the plugin? |
@NickStemerdink yes. The |
I guess you are missing the abstraction layer in your example. See gist in this comment #8269 (comment) for more information. That will take care of initializing the correct database. The other methods will just refer to that database. So after implementing the code from the gist, your code would look like:
|
NickStemerdink, thanks. |
@NickStemerdink: Thanks, very helpful of you. Good man. |
I don't want to create another issue, but at the same time i hope it's not offtopic. |
To build on top of @NickStemerdink's epic work, if anybody needs a batch function you can add it to the sql service like this:
Usage:
|
Its works!!!!! Thanks @NickStemerdink |
@NickStemerdink I agree with @mlynch and the ionic team for reasons in taking this out. Sql is a such a common solution and is the main storage engine for both ios/android I think while some apps use key/value stores it definitely is not applicable to all applications and I don't think that the framework should be that opinionated to not have a good sql interface available for both in browser and app testing. |
Agree with @seand88 this would be quite valuable for when we've otherwise coded our apps to be testable in the browser but direct SQLite makes the most sense for the persistence model on the actual device. There just aren't alternatives with comparable secondary indexing performance that work seamlessly on the browser and the device—it's all on top of SQLite (or flat files that get rewritten wholesale...) in the device anyway, typically implementing interfaces that are really meant for massively parallel computing environments and not a mobile device. (For instance, the PouchDB developers themselves would tell you not to use PouchDB if you're not syncing with a CouchDB backend.) Naturally the browser performance in this case would not be so critical since we'd be tuning for performance on the device; it seems we mainly just want the ability to functionally test in the browser that we don't get with the "more native" platforms. Perhaps this could be done as a community effort? Conversely, could this just be a matter of not being "good enough" at testing/debugging exclusively through emulators/devices? Maybe we just need to see the light and wouldn't miss the ability to test and debug in the browser? |
@jkobylec I placed it in a repo here. Havent published an ionic module before but I will be working on integrating sql.js for the browser testing then can publish it as a module. This should be a drop in replacement of one file for anyone else having issues with this. See the readme in the repo for instructions. |
Thanks @seand88! One thing I'd definitely want to set up in the build process if going the sql.js route in the future is to only include sql.js for the browser using |
@jkobylec |
Dears, Example:
on real devices success is called on success cases and fail is called on failure, but on browser fail is called for success and success is called on failure !!!!!!11 Am i misunderstood something ? |
@baffleinc Your solution about batch query works well on mobile devices, not in browser cause WebSQL doesn't support batch queries. I modified the function like this:
|
Hey, that will work but is not true batchSQL. you will notice significant I actually have an abstractor that does the above if on desktop, and uses
|
Hi, Why SQLite calls transaction method has only one input param while cordova plugin (https://github.com/litehelpers/Cordova-sqlite-storage) also has success and error callbacks
|
How did you get |
ionic-native has this - see https://ionicframework.com/docs/v2/native/sqlite/ |
Are You guys really thinking that most of the people using sql database with their apps are glad to implement this or similar kind of "tune-up" in their code instead of importing Storage and SqlStorage plugin? If You answered no, then I would like to know why didn't You also remove the |
SQLite not work on browser Question : how do you make typescript accept "window.openDatabase" and "window.sqlitePlugin" because when I compile it keep saying error property is undefined ? |
@anrtero Thanks it definitely save my day :) |
I updated sql example gist to wait for platform ready event. Without it, my production apps were unintentionally using WebSQL because sqlitePlugin is not available before platform ready event. |
any solution? I want to keep using the query method! |
@martingra I placed it in a repo here. This will work fine for now testing in browser until chrome removes websql. |
@seand88 you solutions might suffer race condition. You should wait for platform.ready event before checking win.sqliteplugin liked I did here https://gist.github.com/aggarwalankush/0b700328e797e22a1d9994cb35afdf09#file-sql-ts-L15 |
@aggarwalankush Its working fine. Can this code work in native ? |
@hiranivipul yes it will use sqlite in physical device and WebSQL in browser. Just remember to install cordova sqlite plugin with following command-
|
@aggarwalankush Your example is awesome. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
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?
The text was updated successfully, but these errors were encountered: