SQLite - Capacitor Community

This is my first post to the forums and it comes in the form of a cry for help!
I have been trying to use SQLite with an existing database in an App. It is literally driving me crazy. Apologies to the Capacitor community but I cannot figure out how the sample app on the Git repository works (GitHub - capacitor-community/sqlite: Community plugin for native & electron SQLite databases).
I have also reviewed a number of YouTube videos (on both Cordova SQLite and Capacitor SQLite) but the comments on these all lead to the same conclusion: an update broke the samples and they no longer work.
My ask to this community, does anyone have a pointer to a reasonably comprehensible tutorial or example that works?
I wish to update my published app Apple / Google with the ability for the user to add new questions to the existing question bank.


I’ve had a good experience with this plugin for Capacitor 3, Ionic 5 and Vue 3. Can’t speak for other platforms.

What may be an issue for you is where the db is expected to live on the file system. This has been an ongoing challenge for me, between iOS and Android, and their respective updates. A little trick that’s helped me is to write a test file to disk to verify where it gets installed.

import { Directory, Filesystem, Encoding } from '@capacitor/filesystem'

const config = {} // Details about device and such here

  path: 'test_file',
  data: 'hello world!',
  directory: Directory.Documents,
  encoding: Encoding.UTF8
}).then((res) => {

      const { uri } = res
      const path = config.isIos ? uri.replace('file://', '').split('/') : uri.split('/')
      config.folder = path.join('/') + '/'

That way you have the current file system path printed out, and available in the config object (which I store with Capacitor Storage) to make it easier to explore the disk of the simulator on your machine while working.

For the iOS simulator at least, the actual location on your local file system changes between each run, so it is difficult to test caching (of downloaded files) on disk. The SQLite plugin seems to handle this well, though.

The SQLite plugin can handle reading db’s from disk from my experience, and the local of files on disk above can help you pinpoint where your existing db is, so you can give the correct path to the SQLite plugin to read.

Here are the app starters linked from the repo for Capacitor 3 (of which the Vue app starter has been a nice introduction for me to learn from):

Thanks so much @codeluggage. I appreciate your response. I will play a little more with this and hopefully share some code back here when I have a useful prototype :slight_smile:
Thanks again,

1 Like