qq = (db, { describe = false, prompt = "db>", ...options } = {}) => {
const t = Inputs.text({ label: prompt, ...options });
d3.select(t).style("margin-bottom", "7px");
const d = d3.create("div");
const desc = d3.create("div");
const err = d3
.create("div")
.style("font-family", "sans-serif")
.style("font-size", "10px")
.style("color", "brown");
if (describe)
db.describe()
.then((description) => {
err.html("");
desc.html("").append(() => description);
})
.catch((e) => err.html(e));
if (options.value != null) run_query(options.value);
t.addEventListener("input", async () => {
if (t.value === "") err.html("");
else run_query(t.value);
});
const a = html`<div>${t}${d.node()}${err.node()}${desc.node()}</div>`;
return a;
function run_query(q) {
db.query(q)
.then((data) => {
err.html("");
d.html("").append(() => Inputs.table(data));
a.value = data;
a.dispatchEvent(new CustomEvent("input"));
})
.catch((e) => err.html(e));
}
}