首页 > 解决方案 > sqlite read DB - reference sql.js library with locate file

问题描述

I was using this answer to read my db, but this solution is not working any more. It returns now Promise { <state>: "pending" } > . I tried to replace locateFile parameter like this inside promise:

locateFile: file => `dist/${file}`

where dist is folder in initial directory,but no success. Complete code:

  <html>
    <head>
      <script src='dist/sql-wasm.js'></script>
      <script type="module">
        const sqlPromise = initSqlJs({
          locateFile: file => `dist/${file}`
        });
        const dataPromise = fetch("http://localhost/jsons/wind_prev.db").then(res => res.arrayBuffer());
        const [SQL, buf] = await Promise.all([sqlPromise, dataPromise])
        const db = new SQL.Database(new Uint8Array(buf));
        console.log(db)

      </script>
    </head>
  </html>

I believe this has to do something with removing library from https://sql.js.org/dist, but im not sure if i can refrence it within local folder without installing additional packages?

Any help is appreceated.

标签: javascripthtmlsqlitesql.js

解决方案


推荐阅读