Skip to content

Commit

Permalink
feat: prevent execute misfires
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Feb 26, 2024
1 parent a6c7352 commit 2dbe39c
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions examples/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,52 @@ <h2>Results</h2>
// then execute the query
document.getElementById("execute").onclick = async () => {
document.getElementById("results").innerHTML = "";
const executeButton = document.getElementById("execute");
executeButton.disabled = true;

const editorContent = editor.getValue();

if (window.activeEditor === "json") {
console.log("window is in json")

const queryJson = JSON.parse(editor.getValue());

try {
const fields = await db.fields();
Appendable.validateQuery(queryJson, fields)
const queryJson = JSON.parse(editorContent);

const query = await db.query(queryJson);
await bindQuery(query);
try {
const fields = await db.fields();
Appendable.validateQuery(queryJson, fields)

const query = await db.query(queryJson);
await bindQuery(query);
} catch (error) {
console.log("error: ", error);
document.getElementById("results").innerHTML = error.message;
executeButton.disabled = false;
}
} catch (error) {
console.log("error: ", error);
document.getElementById("results").innerHTML = error.message;
executeButton.disabled = false;
}
} else if (window.activeEditor === "javascript") {
console.log("window is in javascript");
try {
const query = await eval(editorContent);

if (query) {
await bindQuery(query);
}
await bindQuery(query);
} catch (error) {
console.log("error: ", error);
document.getElementById("results").innerHTML = error.message;
executeButton.disabled = false;
}
}
};

document.getElementById("results").innerHTML = "";
const query = await db.query(JSON.parse(editor.getValue()));
await bindQuery(query);

try {
const query = await db.query(JSON.parse(editor.getValue()));
await bindQuery(query);
} catch (error) {
document.getElementById("results").innerHTML = error.message;
executeButton.disabled = false;
}
});

async function bindQuery(query) {
Expand All @@ -169,6 +179,7 @@ <h2>Results</h2>
for (let i = 0; i < 10; i++) {
await appendResult();
}
document.getElementById("execute").disabled = false;
while (true) {
document.getElementById("next").disabled = false;
await new Promise(
Expand Down

0 comments on commit 2dbe39c

Please sign in to comment.