How to set the SQLite file in a specific location


#1

I am using SQLite as suggested from this page http://ionicframework.com/docs/v2/native/sqlite/
but how do I know where is the *.db file location, since it set as default?
How to set a specific db file path to location?


#2

*but how do I know where is the .db file location, since it set as default?

The default location is the www folder, so you don’t need to do anything other than placing your db file on www folder and setting location='defalut' on SQLite. Image showing my DB inside www folder



In my case i’m using a pre-populated database , don’t know if it’s what you want.
The plugin i’m using is (https://github.com/litehelpers/cordova-sqlite-ext). Install with ionic plugin add cordova-sqlite-ext --save

Basically this what i do:

First import SQLite

import { SQLite } from ‘ionic-native’;

Options to open database, name is the name of the database i already have, if you don’t have any database it should be the name to give to your DB.

let options = { name: “MTS.db”, location: ‘default’, createFromLocation: 1 };

Create the connection

this.storage = new SQLite();

Open database and execute a simple query (my DB contains a table called stations)

this.storage.openDatabase(options).then((su) => {
  this.storage.executeSql('SELECT * FROM stations', {}).then((res) => {console.log(JSON.stringify(res))}, (err) => { 
    console.error('Unable to execute sql: ', err);
});