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

feat: Properly store with objects in SqlStorage

Open leonsas opened this issue 10 years ago • 4 comments

Type: feat

Ionic Version: 2.x

Platform: all

Right now if you store objects through SqlStorage, they get stored as a string "[object Object]". I think it would be super helpful and developer-friendly to allow arbitrary json storage. Basically serializing and deserializing it for users. I'm sure there's a lot of considerations to make that practical so maybe you guys already discarded that use case. If that's the case, then you should document that somewhere or even log a warning when a call to .set is passing an object as the value.

    var options = {};
    let storage = new Storage(SqlStorage, options);
    storage.set('myobj', {name:'myname'});
    storage.get('myobj').then((myobj) => {
      console.log(myobj);// this logs "[object Object]"
    });

leonsas avatar Feb 15 '16 22:02 leonsas

when logging objects in the console try doing

console.dir(myobj)

more on this

https://developer.chrome.com/devtools/docs/console-api#consoledirobject

cyprusglobe avatar Feb 16 '16 14:02 cyprusglobe

Yes, I'm aware, same thing happens (I actually even did debugger to confirm the situation). I think WebSQL simply calls .toString() on objects, which would lead to this. Haven't tested on SQLite.

leonsas avatar Feb 17 '16 15:02 leonsas

+1

I have the exact same issue with Local Storage

lbickston avatar Mar 11 '16 02:03 lbickston

Hello all! We are currently refactoring the storage module to not use webSQL any more as it is a deprecated technology and is not supported any more in iOS 10 and is soon to be removed from chrome too. IndexedDB is the future of complex web storage and is what we are moving too. Because of all this I am going to be closing this issue for now. Thanks for using Ionic!

jgw96 avatar Aug 24 '16 21:08 jgw96