Created
November 3, 2022 07:01
-
-
Save kuc-arc-f/47539060582e97d90b61e030ae34dac2 to your computer and use it in GitHub Desktop.
SQLite3 WASM/JS file load sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- SQLite3 WASM/JS file load sample --> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title>SQLite</title> | |
</head> | |
<body> | |
<h3>t3.html</h3> | |
<hr /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.6.2/sql-wasm.min.js"></script> | |
<script> | |
initSqlJs({ | |
locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.6.2/${file}` | |
}).then(async function(SQL) { | |
let sqlFilePath = "/sqlite3_wasm/mydb.sqlite"; | |
const dataPromise = await fetch(sqlFilePath).then(res => res.arrayBuffer()); | |
const u8array = new Uint8Array(dataPromise); | |
const db = new SQL.Database(new Uint8Array(u8array)); | |
let query = "SELECT * FROM users"; | |
let contents = db.exec(query); | |
res = JSON.stringify(contents); | |
console.log(contents); | |
//console.log(contents[0].values[0]); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment