Ionic 2 Beta.8 + Storage + SqlStorage

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?

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);
  });
});

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

Encountered this awhile ago. Try assigning a dbname

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

1 Like

Ohh, thank you!
It works!

It’s good to hear.

You’re welcome :slight_smile:

1 Like