Currently, I am exploring the functionality of sql.js through this resource:
My journey began with their introductory HTML example which seems to be causing a series of errors during execution.
To start off, I installed sql.js using the command: npm install sql.js
After installing sql.js, I transferred the 'dist' folder from the installation into the 'test' directory where the index.html is located.
Following the example code provided, when I attempted to open it in a browser, I was met with an error message stating:
sql-wasm.js:167 Fetch API cannot load file:///C:/dist/sql-wasm.wasm. URL scheme "file" is not supported.
Here's a snippet of the code:
<meta charset="utf8" />
<html>
<script src='C:\\Users\\Rocko\\Documents\\scripts\\AAOA\\nodetest\\dist\\sql-wasm.js'></script>
<script>
config = {
locateFile: filename => `/dist/${filename}`
}
// The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.
// We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.
initSqlJs(config).then(function(SQL){
//Create the database
const db = new SQL.Database();
// Run a query without reading the results
db.run("CREATE TABLE test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);
// Prepare a statement
const stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}
// Bind new values
stmt.bind({$start:1, $end:2});
while(stmt.step()) { //
const row = stmt.getAsObject();
console.log('Here is a row: ' + JSON.stringify(row));
}
});
</script>
<body>
Output is in Javascript console
</body>
</html>
Pictures: https://i.sstatic.net/I5CQU.png
https://i.sstatic.net/6zDfZ.png
I have been attempting to integrate my SQLite file into my test web app for approximately two weeks now. Despite following various suggestions, I still can't seem to successfully execute even the basic example.
Please feel free to share any insights or suggestions you may have.
Thank you!