jlongster / absurd-sql

sqlite3 in ur indexeddb (hopefully a better backend soon)
MIT License
4.15k stars 101 forks source link

Export DB throw error. #75

Open portguas opened 4 months ago

portguas commented 4 months ago

I'm using absurd-sql in electron. I export the db like this.

try {
      const db = await getInstance()
      const data = db.export()
      const blob = new Blob([data], { type: 'application/octet-stream' })
      const blobHref = URL.createObjectURL(blob)

      self.postMessage({ action: 'exportedDB', blobHref })
    } catch (error) {
      console.info('sql export error, return ', error)
    }

It got error.

sql export error, return  TypeError: Cannot read properties of undefined (reading 'constructor')
    at readChunks (indexeddb-backend.js:65:20)
    at File.read (indexeddb-backend.js:248:22)
    at Object.read (index.js:101:37)
    at Object.read (sql-wasm.js:151:211)
    at Object.readFile (sql-wasm.js:154:349)
    at c.export (sql-wasm.js:88:238)
    at self.onmessage (instance.ts?type=mod…er_file? [sm]:86:23)

The error caused by const data = db.export() In indexeddb-backend.js ,the data in undefined.

 if (chunk.data.constructor.name !== 'ArrayBuffer') {
      throw new Error('Chunk data is not an ArrayBuffer');
    }

How can i resolve it. Thanks.