Ionic 2 Beta.8 + Storage + SqlStorage


#1

Hi Guys,

I am trying to use SqlStorage to set some values, but for some reason after set a value, when I try to get the value again is always empty.

let storage = new Storage(SqlStorage);
storage.set('name', 'Max');
storage.get('name').then((name) => {
    console.log(name); // is always undefined!!!!
});

And I’ve added the plugin: cordova-sqlite-storage, spec="~1.4.1".

I don’t really understand whats is wrong.

Any help?


#2

set is an asynchronous operation. You’re not guaranteed that anything has happened until its return promise has resolved.

storage.set('name', 'Max').then(() => {
  storage.get('name').then((name) => {
    console.log(name);
  });
});

#3

Well, this example is not my case
As I am setting the value in one view
and trying to get the value in another view or even closing the app and opening again
and still is empty

I can say I’ve added the sql plugin too

so, I don’t quite understand whats wrong


#4

Encountered this awhile ago. Try assigning a dbname

this.storage = new Storage(SqlStorage, { name: 'myDB' });


#5

Ohh, thank you!
It works!


#6

It’s good to hear.

You’re welcome :slight_smile: