How to set the SQLite file in a specific location

I am using SQLite as suggested from this page
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?

1 Like

*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 ( 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 = new SQLite();

Open database and execute a simple query (my DB contains a table called stations) => {'SELECT * FROM stations', {}).then((res) => {console.log(JSON.stringify(res))}, (err) => { 
    console.error('Unable to execute sql: ', err);
1 Like

What version of Ionic are you using? In Ionic 4 did not work because it recreates the folder www.

In that case it was Ionic 2. I haven’t used Ionic since Ionic 2. I have an example with Ionic 3 in Github ionic3-PreDB. But i haven’t updated it in a while.

Thanks man, I saw this example that you posted. But for me only version 4 same.

Did you ever figure this out? I am a little lost and would love some help.