Ionic Vue + SQLite (capacitor-community/sqlite)

does anyone has experience with Ionic Vue and capacitor SQLite like with this package for example?
it only works on Android. iOS and Electron which makes it slow to debug and so far I couldn’t get it to run since I always get the exception TypeError: db.isExists is not a function . however I am using the example code from the git. the db connections looks like created correctly with

const db = await sqlite.createConnection("testNew", false, "no-encryption", 1);
but then the above error is thrown in any function which is called on db. however db is actually an successfully created db object

I don’t know how to progress. has anyone a working sample of Ionic Vue + SQLite with a query functionality or knows my problem? are there alternatives?
I am using Vue3 + capacitor-community/sqlite@2.9.9 + vue-sqlite-hook@1.0.0

I forgot to register the plugin in my main android activity (see package description). it looks like it works now. looking forward working with the package

2 Likes

Hello farfalla,
Could you please share your piece of code.
i didn’t find any resources for ionic vue sqlite and i’m struggling now
Thanks

see my first post. the package site is a very good way to start your Ionic Vue sqlite project. it also has a starter app project up on GitHub which you can download and some How To instructions and an API manual

What do you mean by “register the function”? Can you post a code sample of what you put into the Main Activity?

whole free preview from my course on vuejs and sqlite - Ionic Framework with VueJS: Build a CRUD App Using SQLite - (1) Introduction - YouTube

2 Likes

check out this section of the @capacitor-community/sqlite package site

Android

  • On Android, register the plugin in your main activity:
import com.getcapacitor.community.database.sqlite.CapacitorSQLite;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {
          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(CapacitorSQLite.class);
          }
        }
      );
  }
}

Hello @farfalla in the link that you share, it states: “On Android, no further steps needed.” can you share where exactly you get this info? please I’m having this error too

I think the package and package description has changed because of the new @capacitor-community/sqlite master branch for capacitor 3 and its newest version 3.0.0-rc.2 - with that apparently no further steps are needed

if you are for some reason still want or need to use the older version like 2.9.16 I think you need the above code on Android to register the plugin in your main activity. I hope that helps