Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/components/command-bar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/components/sqlime-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SqlimeEditor extends HTMLElement {

render() {
this.contentEditable = "true";
this.spellcheck = false;
}

listen() {
Expand Down
17 changes: 17 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import locator from "./locator.js";
import manager from "./sqlite/manager.js";
import storage from "./storage.js";
import timeit from "./timeit.js";
import dumper from "./sqlite/dumper.js";

import { actionButton } from "./components/action-button.js";
import { ActionController } from "./controllers/actions.js";
Expand Down Expand Up @@ -36,6 +37,7 @@ const actions = {
showTables: showTables,
showTable: showTable,
visit: visit,
downloadSnippet: downloadSnippet,
};

const shortcuts = {
Expand Down Expand Up @@ -157,6 +159,21 @@ function execute(sql) {
}
}

// Downloads the current snippet as a .sql file, with DB name and
// the current time
function downloadSnippet(){
const anchorBlob = document.createElement('a');
const dump = dumper.toSql(database, ui.editor.query);
const query = ui.editor.query;
const textBlob = new Blob([`${dump}\n${query}`], {type: 'text/plain'});
anchorBlob.href = window.URL.createObjectURL(textBlob);
//make filenames shell- and fs-friendly
anchorBlob.download = `${ui.name.value}_${(new Date()).toISOString().replaceAll(':', '_')}.sql`;
anchorBlob.click();
console.log(ui);
return Promise.resolve();
}

// askAi queries the AI assistant using the contents of the editor
// as a query and prints the answer.
function askAi() {
Expand Down