feat: add new duck db command

This commit is contained in:
Nybkox
2025-04-08 18:56:17 +02:00
parent ca18994092
commit b8d86518e7
5 changed files with 46 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ module.exports = ({ editMenu, isMac }) => [
submenu: [ submenu: [
{ command: 'new.connection', hideDisabled: true }, { command: 'new.connection', hideDisabled: true },
{ command: 'new.sqliteDatabase', hideDisabled: true }, { command: 'new.sqliteDatabase', hideDisabled: true },
{ command: 'new.duckdbDatabase', hideDisabled: true },
{ divider: true }, { divider: true },
{ command: 'new.query', hideDisabled: true }, { command: 'new.query', hideDisabled: true },
{ command: 'new.queryDesign', hideDisabled: true }, { command: 'new.queryDesign', hideDisabled: true },

View File

@@ -435,6 +435,22 @@ module.exports = {
return res; return res;
}, },
newDuckdbDatabase_meta: true,
async newDuckdbDatabase({ file }) {
const duckdbDir = path.join(filesdir(), 'duckdb');
if (!(await fs.exists(duckdbDir))) {
await fs.mkdir(duckdbDir);
}
const databaseFile = path.join(duckdbDir, `${file}.duckdb`);
const res = await this.save({
engine: 'duckdb@dbgate-plugin-duckdb',
databaseFile,
singleDatabase: true,
defaultDatabase: `${file}.duckdb`,
});
return res;
},
dbloginWeb_meta: { dbloginWeb_meta: {
raw: true, raw: true,
method: 'get', method: 'get',

Binary file not shown.

View File

@@ -46,6 +46,7 @@ import { openImportExportTab } from '../utility/importExportTools';
import newTable from '../tableeditor/newTable'; import newTable from '../tableeditor/newTable';
import { isProApp } from '../utility/proTools'; import { isProApp } from '../utility/proTools';
import { openWebLink } from '../utility/simpleTools'; import { openWebLink } from '../utility/simpleTools';
import { _t } from '../translations';
// function themeCommand(theme: ThemeDefinition) { // function themeCommand(theme: ThemeDefinition) {
// return { // return {
@@ -389,12 +390,12 @@ registerCommand({
category: 'New', category: 'New',
icon: 'img sqlite-database', icon: 'img sqlite-database',
name: 'SQLite database', name: 'SQLite database',
menuName: 'New SQLite database', menuName: _t('command.new.sqliteDatabase', { defaultMessage: 'New SQLite database' }),
onClick: () => { onClick: () => {
showModal(InputTextModal, { showModal(InputTextModal, {
value: 'newdb', value: 'newdb',
label: 'New database name', label: _t('command.new.sqliteDatabase', { defaultMessage: 'New SQLite database' }),
header: 'Create SQLite database', header: _t('command.new.sqliteDatabase.header', { defaultMessage: 'Create SQLite database' }),
onConfirm: async file => { onConfirm: async file => {
const resp = await apiCall('connections/new-sqlite-database', { file }); const resp = await apiCall('connections/new-sqlite-database', { file });
const connection = resp; const connection = resp;
@@ -404,6 +405,26 @@ registerCommand({
}, },
}); });
registerCommand({
id: 'new.duckdbDatabase',
category: 'New',
icon: 'img sqlite-database',
name: 'DuckDB database',
menuName: _t('command.new.duckdbDatabase', { defaultMessage: 'New DuckDB database' }),
onClick: () => {
showModal(InputTextModal, {
value: 'newdb',
label: _t('command.new.duckdbDatabase', { defaultMessage: 'New DuckDB database' }),
header: _t('command.new.duckdbDatabase.header', { defaultMessage: 'Create DuckDB database' }),
onConfirm: async file => {
const resp = await apiCall('connections/new-duckdb-database', { file });
const connection = resp;
switchCurrentDatabase({ connection, name: `${file}.duckdb` });
},
});
},
});
registerCommand({ registerCommand({
id: 'tabs.changelog', id: 'tabs.changelog',
category: 'Tabs', category: 'Tabs',

View File

@@ -26,6 +26,10 @@
"command.datagrid.undo": "Undo", "command.datagrid.undo": "Undo",
"command.datagrid.viewJsonDocument": "View row as JSON document", "command.datagrid.viewJsonDocument": "View row as JSON document",
"command.datagrid.viewJsonValue": "View cell as JSON document", "command.datagrid.viewJsonValue": "View cell as JSON document",
"command.new.duckdbDatabase": "New DuckDB database",
"command.new.duckdbDatabase.header": "Create DuckDB database",
"command.new.sqliteDatabase": "New SQLite database",
"command.new.sqliteDatabase.header": "Create SQLite database",
"command.tabs.addToFavorites": "Add current tab to favorites", "command.tabs.addToFavorites": "Add current tab to favorites",
"command.tabs.closeAll": "Close all tabs", "command.tabs.closeAll": "Close all tabs",
"command.tabs.closeTab": "Close tab", "command.tabs.closeTab": "Close tab",
@@ -51,7 +55,6 @@
"connection.newQuery": "New Query (server)", "connection.newQuery": "New Query (server)",
"connection.refresh": "Refresh", "connection.refresh": "Refresh",
"connection.serverSummary": "Server summary", "connection.serverSummary": "Server summary",
"connection.sqlRestore": "Restore/import SQL dump",
"connection.viewDetails": "View details", "connection.viewDetails": "View details",
"error.driverNotFound": "Invalid database connection, driver not found", "error.driverNotFound": "Invalid database connection, driver not found",
"importExport.sourceFiles": "Source files", "importExport.sourceFiles": "Source files",
@@ -61,6 +64,7 @@
"schema.delete": "Delete schema", "schema.delete": "Delete schema",
"schema.resetToDefault": "Reset to default", "schema.resetToDefault": "Reset to default",
"schema.schemaName": "Schema name", "schema.schemaName": "Schema name",
"settings.behaviour.jsonPreviewWrap": "Wrap json in preview",
"settings.localization": "Localization", "settings.localization": "Localization",
"tab.administration": "Administration", "tab.administration": "Administration",
"widget.databaseContent": "Database content", "widget.databaseContent": "Database content",