# Again! SQLite in Ionic 2.2.0, How to Use It?

**URL:** <https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969>\
**Category:** ionic-v3\
**Created:** [March 15, 2017, 12:24am UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969 "2017-03-15T00:24:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GJVVU](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gjvvu/32/107969_2.png) [@GJVVU](https://forum.ionicframework.com/u/GJVVU)\
**Post date:** [March 15, 2017, 12:24am UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/1 "2017-03-15T00:24:27Z")

</div>

Hi folks,

I’ve been googling around and cannot find a decent step by step tutorial on how to use SQLite in Ionic 2. The tutorials are out of date, I followed the Ionic 2 docs and tutorial here:

> **[Use SQLite In Ionic 2 Instead Of Local Storage](https://www.thepolyglotdeveloper.com/2015/12/use-sqlite-in-ionic-2-instead-of-local-storage/)**
>
> Use SQLite instead of local storage in your Ionic 2 Android and iOS application with the Storage and SqlStorage dependencies.

I still cannot make it work. There are a few confusions I need someone to clarify for me:

1. In order to see SQLite in action, do I need to add platform while making a new project?
2. If I use web browser to test the app (using “ionic serve” command), the SQLite will not work?
3. The “Cordova-SQLite-Storage” is just a plugin for Ionic 2 in order to use SQLite, which is on the actual device or emulator?
4. If the database does not exist, then I follow the instruction here: [http://ionicframework.com/docs/v2/native/sqlite/](http://ionicframework.com/docs/v2/native/sqlite/), will it create a new database for me?
5. I actually followed the docs, installed everything, but when I run the app in browser, it keeps giving me the following error:  
Native: tried accessing the SQLite plugin but it’s not installed.  
Install the SQLite plugin: ‘ionic plugin add cordova-sqlite-storage’

Could someone please show me how to use SQLite in Ionic 2? Thank you.

GJ Wu

---

<div class="post-metadata">

**Author:** ![pciseran](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pciseran](https://forum.ionicframework.com/u/pciseran)\
**Post date:** [March 21, 2017, 8:53pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/2 "2017-03-21T20:53:53Z")

</div>

Hi GJ Wu,  
You will not be able to test ths sqlite plugin on your browser as this is a native plugin so… using android or IOS OS.  
Try with your device or emulator…  
and the database will be created if doesn’t exists, normally:wink:

---

<div class="post-metadata">

**Author:** ![VibeThemes](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vibethemes/32/106128_2.png) [@VibeThemes](https://forum.ionicframework.com/u/VibeThemes)\
**Post date:** [March 22, 2017, 7:39am UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/3 "2017-03-22T07:39:44Z")

</div>

Thanks, I was also looking for the same thing. But to be unable to test in browser sucks, Ionic team must do something about this to make app development easier.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [March 22, 2017, 8:05pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/4 "2017-03-22T20:05:23Z")

</div>

> [@VibeThemes](#):
>
> Ionic team must do something about this to make app development easier.

[They kinda did](https://ionicframework.com/docs/v2/storage/).

---

<div class="post-metadata">

**Author:** ![GJVVU](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gjvvu/32/107969_2.png) [@GJVVU](https://forum.ionicframework.com/u/GJVVU)\
**Post date:** [March 22, 2017, 8:48pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/5 "2017-03-22T20:48:31Z")

</div>

Hi folks,

It seems that Ionic team is making changes to their docs, I found that since two or three days ago, maybe they are making changes for the upcoming framework update. Keep an eye on it, I hope everything works beautifully later. Meanwhile, I am using PouchDB with SQLite adapter, it seems that they have some issues for adapter information returned from [database.info](http://database.info), even if I uploaded the app to my phone, it does not show the true type of storage I use. I am waiting for the update. I hope this will help.

---

<div class="post-metadata">

**Author:** ![jmrkl](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@jmrkl](https://forum.ionicframework.com/u/jmrkl)\
**Post date:** [April 2, 2017, 4:31pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/6 "2017-04-02T16:31:28Z")

</div>

Hi folks,

im trying to use the SQLite Storage but it doesn’t work. I’ve followed all the steps in the docs, but when I try to run nothing happens.

I’ve installed the ionic-native/storage via npm. And added the plugin to my App.  
In my app.module.ts:  
…  
import { SQLite } from ‘@ionic-native/sqlite’;  
…  
providers: [  
SQLite,  
…

I need help!!! Thanks

---

<div class="post-metadata">

**Author:** ![ruialves\_programming](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ruialves_programming/32/96340_2.png) [@ruialves\_programming](https://forum.ionicframework.com/u/ruialves_programming)\
**Post date:** [April 3, 2017, 2:53pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/7 "2017-04-03T14:53:47Z")

</div>

This is what i have tried last night. I updated my repository [Ionic 2 pre-populated example](https://github.com/iursevla/ionic2-PreDB) (repository now up to date with last version of ionic. It uses cordova-sqlite-ext but the code is similar to what you will need for cordova-sqlite-storage )

My **home.ts** :

```
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  private options = { name: "data.db", location: 'default', createFromLocation: 1 };
  private queryDatabase= "SELECT * FROM tableName";

  constructor(public navCtrl: NavController, private sqlite: SQLite) {
    this.sqlite.create(this.options).then((db: SQLiteObject) => {
      db.executeSql(this.queryDatabase, {}).then((data) => {
        //Do Something with your data here
      })
    });
  }
}

```

Also you need to have a database on your www folder or if you don’t want to use a pre-populated database you don’t need to have one.

---

<div class="post-metadata">

**Author:** ![saghari](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@saghari](https://forum.ionicframework.com/u/saghari)\
**Post date:** [August 28, 2017, 7:50pm UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/8 "2017-08-28T19:50:23Z")

</div>

Hi ruialves\_programming  
[1.Is](http://1.Is) this code working in browser (ionic serve) fore easy debugging ?  
2. why you didn’t check for “platform.ready” before opening database !?

---

<div class="post-metadata">

**Author:** ![ruialves\_programming](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ruialves_programming/32/96340_2.png) [@ruialves\_programming](https://forum.ionicframework.com/u/ruialves_programming)\
**Post date:** [August 29, 2017, 10:09am UTC](https://forum.ionicframework.com/t/again-sqlite-in-ionic-2-2-0-how-to-use-it/82969/9 "2017-08-29T10:09:17Z")

</div>

Hi,

> 1.Is this code working in browser (ionic serve) fore easy debugging ?

As far as i know sqlite won’t work in the browser because it needs Cordova to work. But you can use an emulator like Genymotion. For easy debugging you could create a mookup service that would replace sqlite when you are working in the browser.

> 1. why you didn’t check for “platform.ready” before opening database !?

I’m not sure (because it was a long time ago) but i think it was because the [App Component](https://github.com/iursevla/ionic2-PreDB/blob/master/prePopulated/src/app/app.component.ts) already is checking platform.ready.
