Skip to content

Commit

Permalink
Use SQL wasm to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yuraj11 committed Jan 16, 2024
1 parent 576c3de commit ffb7a69
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 225 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h4 class="mb-0">SQLite Viewer</h4>

<script src="js/jquery-3.7.1.min.js"></script>
<script src="js/filereader.js"></script>
<script src="js/sql.js?v=190"></script>
<script src="js/sql-wasm.js?v=1100"></script>
<script src="js/select2.min.js?v=4013"></script>
<script src="js/ace/ace.js?v=1323"></script>
<script src="js/bootstrap.bundle.min.js?v=532"></script>
Expand Down
24 changes: 11 additions & 13 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function initialize() {
onKeyDown(e);
})

if (typeof FileReader === "undefined") {
if (typeof FileReader === "undefined" || typeof WebAssembly === "undefined") {
$('#dropzone, #dropzone-dialog').hide();
$('#compat-error').toggleClass("d-none", false);
} else {
Expand Down Expand Up @@ -100,7 +100,7 @@ function loadDB(arrayBuffer) {

resetTableList();

initSqlJs().then(function(SQL){
initSqlJs({ locateFile: file => `/js/${file}` }).then(function(SQL){
let tables;
try {
db = new SQL.Database(new Uint8Array(arrayBuffer));
Expand Down Expand Up @@ -378,17 +378,15 @@ function renderQuery(query) {
return;
}

let addedColumns = false;
while (sel.step()) {
if (!addedColumns) {
addedColumns = true;
const columnNames = sel.getColumnNames();
for (let i = 0; i < columnNames.length; i++) {
const type = columnTypes[columnNames[i]];
thead.append('<th><span data-bs-toggle="tooltip" title="' + type + '">' + columnNames[i] + "</span></th>");
}
}
let isEmptyTable = true;
const columnNames = sel.getColumnNames();
for (let i = 0; i < columnNames.length; i++) {
const type = columnTypes[columnNames[i]];
thead.append('<th><span data-bs-toggle="tooltip" title="' + type + '">' + columnNames[i] + "</span></th>");
}

while (sel.step()) {
isEmptyTable = false;
const tr = $('<tr>');
const s = sel.get();
for (let i = 0; i < s.length; i++) {
Expand All @@ -397,7 +395,7 @@ function renderQuery(query) {
tbody.append(tr);
}

if (!addedColumns) {
if (isEmptyTable) {
infoBox.text("No data for given select.")
infoBox.show();
}
Expand Down
Loading

0 comments on commit ffb7a69

Please sign in to comment.