【问题标题】:WebSQL threw an error [Error: Error code 1: no such table: document-store]WebSQL 抛出错误 [错误:错误代码 1:没有这样的表:文档存储]
【发布时间】:2021-08-04 18:06:51
【问题描述】:

我们在应用程序中使用react-naive-sqlite-2RxDB 并开始偶尔出现此错误。它似乎发生在我们删除数据库之后。我很惊讶地看到这是一个 WebSQL 错误,因为我们使用的是 react-native 而 WebSQL 已被弃用。我没有很好的调试方法,但我的直觉是我们有一些代码仍在尝试访问现已失效的数据库。

这是我们用来设置数据库的代码:

import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'
import SQLite from 'react-native-sqlite-2'
import { addRxPlugin, createRxDatabase } from 'rxdb'
import { RxDBReplicationGraphQLPlugin } from 'rxdb/plugins/replication-graphql'

import type { DatabaseType } from '../generated'

/**
 * SQLITE SETUP
 */
const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
addRxPlugin(SQLiteAdapter)
addRxPlugin(require('pouchdb-adapter-http'))

/**
 * Other plugins
 */
addRxPlugin(RxDBReplicationGraphQLPlugin)

export const getRxDB = async () => {
  return await createRxDatabase<DatabaseType>({
    name: 'gatherdatabase',
    adapter: 'react-native-sqlite', // the name of your adapter
    multiInstance: false,
  })

问题发生在我们注销并尝试重新登录后。当我们注销时,我们调用removeRxDatabase。有没有人遇到过此类问题或知道如何调试?

【问题讨论】:

    标签: react-native sqlite rxdb


    【解决方案1】:

    对于后代来说,问题在于我们对状态管理库 (Zusand) 中的数据库有一个引用,该引用被保留在过去的注销中。当我们再次尝试登录时,我们的getOrCreateDatabase 函数没有创建一个新函数,但它无效,因为我们在 rxdb 中运行了database.remove()。我们最终只清除了 Zusand 数据库并在一个地方调用了 database.remove()

    export const useRxDB = create<UseRxDBType>((set, get) => ({
      database: undefined,
      /**
       * we set the database to ready in the LocalDocument store once local docs are loaded into the store
       */
      databaseIsReady: false,
      getOrCreateDatabase: async () => {
        let database = get().database
    
        if (!database) {
          database = await createRxDatabase()
    
          if (!Rx.isRxDatabase(database)) throw new Error(`database isnt a valid RxDB database.`)
    
          set({ database })
        }
    
        return database
      },
      resetDatabase: async () => {
        const database = get().database
    
        if (database) {
          await database.remove()
          set({ database: undefined })
        }
      },
    }))
    

    【讨论】:

      猜你喜欢
      • 2014-05-22
      • 2012-06-13
      • 2017-08-16
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多