Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.49k stars 589 forks source link

"TypeError: SQLiteAdapter is not a constructor" when using Svelte(Kit) and CapacitorJS #1755

Closed bluepuma77 closed 5 months ago

bluepuma77 commented 6 months ago

I admit it, it's a really complicated setup with Svelte (issue) and CapacitorJS. (template 1, template 2)

Any idea why I am receiving this error?

TypeError: SQLiteAdapter is not a constructor

Source:

import { Database } from '@nozbe/watermelondb'
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite'

import schema from './model/schema'
import migrations from './model/migrations'
import Post from './model/Post'

// First, create the adapter to the underlying database:
export const adapter = new SQLiteAdapter({
                           ^^^
  schema,
  // (You might want to comment it out for development purposes -- see Migrations documentation)
  migrations,
  // (optional database name or file system path)
  // dbName: 'myapp',
  // (recommended option, should work flawlessly out of the box on iOS. On Android,
  // additional installation steps have to be taken - disable if you run into issues...)
  jsi: true, /* Platform.OS === 'ios' */
  // (optional, but you should implement this method)
  onSetUpError: error => {
    // Database failed to load -- offer the user to reload the app or log out
  }
})

// Then, make a Watermelon database from it!
export const database = new Database({
  adapter,
  modelClasses: [
    Post,
  ],
})
bluepuma77 commented 6 months ago

It seems this is a way to use sqlite from CapacitorJS (source):

    import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite";
    const sqlite = new SQLiteConnection(CapacitorSQLite);
    let db
    try {
        db = await sqlite.retrieveConnection("db1", false);
    } catch (err) {
        db = await sqlite.createConnection("db1", false, "no-encryption", 1, false);
    }
    console.log('db', db)

But how would I connect this to WatermelonDB?

radex commented 5 months ago

There's no SvelteKit/CapacitorJS adapter for WatermelonDB. Here's the guide for how to create new db adapters: https://watermelondb.dev/docs/Implementation/DatabaseAdapters