I get a error when using from sql.js. file is not a database

43 Views Asked by At

I have a mbtiles file and I want to read that. In addition, I used sql.js v1.10.2, when I create a new Database, it won't return an error but if I want to use a prepare method it returns an error.

async function (buffer: ArrayBuffer) {
   try {
      const SQL = await initSqlJs({
         locateFile: (file) => `/src/assets/sql/${file}`,
      });

      const db = new SQL.Database(new Uint8Array(buffer));

      const stmt = db.prepare(
         "SELECT tile_column FROM map WHERE zoom_level = :z AND tile_column = :x AND tile_row = :y"
      ); // --> I have an error when running this line.

   } catch (ex) {
      console.log(ex);
   }
}

I can create an empty database and run a raw query to create a new table but I can't create a database from mbtiles file.

when I run prepare method, get file is not a database error

0

There are 0 best solutions below