fix(sql-format): format source and DDL with proper dialects
This commit is contained in:
1 parent
ed35164828
commit
ff810f3058
7 files changed
+136
-56
No files matched your search
@@ -100,6 +100,7 @@ import {
|
||||
import { buildRenameObjectSql, supportsObjectRename, type RenameableObjectType } from "@/lib/objectRenameSql";
|
||||
import { buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/objectSourceEditor";
|
||||
import { buildViewDdl } from "@/lib/viewDdl";
|
||||
import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sqlFormatter";
|
||||
import DdlViewDialog from "@/components/objects/DdlViewDialog.vue";
|
||||
import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities";
|
||||
import { codeMirrorSqlDialect, connectionObjectTreeNodeSchema, connectionObjectTreeQuerySchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, tableStructureDatabaseTypeForConnection } from "@/lib/jdbcDialect";
|
||||
@@ -1278,7 +1279,8 @@ async function generateDdlTemplate() {
|
||||
source: result.source,
|
||||
});
|
||||
}
|
||||
openSqlTemplateTab(node.connectionId, node.database, node.schema, ddl, `DDL - ${node.label}`);
|
||||
const formatted = await formatSqlForDisplay(ddl, sqlFormatDialectForDbType(currentDatabaseType()), settingsStore.editorSettings.sqlFormatter);
|
||||
openSqlTemplateTab(node.connectionId, node.database, node.schema, formatted, `DDL - ${node.label}`);
|
||||
} catch (e: any) {
|
||||
toast(e?.message || String(e), 5000);
|
||||
}
|
||||
@@ -1452,6 +1454,10 @@ const ddlDialect = computed(() => {
|
||||
if (!ddlTarget.value?.connectionId) return "mysql";
|
||||
return codeMirrorSqlDialect(effectiveDatabaseTypeForConnection(connectionStore.getConfig(ddlTarget.value.connectionId)));
|
||||
});
|
||||
const ddlFormatDialect = computed(() => {
|
||||
if (!ddlTarget.value?.connectionId) return "generic";
|
||||
return sqlFormatDialectForDbType(effectiveDatabaseTypeForConnection(connectionStore.getConfig(ddlTarget.value.connectionId)));
|
||||
});
|
||||
const showCreateDatabaseDialog = ref(false);
|
||||
const createDatabaseName = ref("");
|
||||
const createDatabaseCharset = ref("utf8mb4");
|
||||
@@ -1619,7 +1625,8 @@ function viewObjectSource() {
|
||||
})
|
||||
.then(async (result) => {
|
||||
const tabId = queryStore.createTab(node.connectionId!, node.database!, `Source - ${node.label}`);
|
||||
queryStore.updateSql(tabId, result.source);
|
||||
const formatted = await formatSqlForDisplay(result.source, sqlFormatDialectForDbType(currentDatabaseType()), settingsStore.editorSettings.sqlFormatter);
|
||||
queryStore.updateSql(tabId, formatted);
|
||||
if (objectType !== "SEQUENCE") {
|
||||
queryStore.setObjectSource(tabId, {
|
||||
schema,
|
||||
@@ -1653,8 +1660,9 @@ function viewObjectDdl() {
|
||||
name: node.label,
|
||||
source: result.source,
|
||||
});
|
||||
const formatted = await formatSqlForDisplay(ddl, sqlFormatDialectForDbType(effectiveDatabaseTypeForConnection(connection)), settingsStore.editorSettings.sqlFormatter);
|
||||
const tabId = queryStore.createTab(node.connectionId!, node.database!, `DDL - ${node.label}`);
|
||||
queryStore.updateSql(tabId, ddl);
|
||||
queryStore.updateSql(tabId, formatted);
|
||||
})
|
||||
.catch((e: any) => {
|
||||
toast(e?.message || String(e), 5000);
|
||||
@@ -4432,7 +4440,7 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
|
||||
<DangerConfirmDialog v-model:open="showDropSchemaConfirm" :title="t('contextMenu.confirmDropSchemaTitle')" :message="t('contextMenu.confirmDropSchemaMessage', { name: node.label })" :sql="dropSchemaPreviewSql" :confirm-label="t('contextMenu.dropSchema')" @confirm="confirmDropSchema" />
|
||||
|
||||
<DdlViewDialog v-if="ddlTarget" :connection-id="ddlTarget.connectionId!" :database="ddlTarget.database!" :schema="ddlTarget.schema" :table-name="ddlTarget.label" :dialect="ddlDialect" v-model:open="showDdlDialog" />
|
||||
<DdlViewDialog v-if="ddlTarget" :connection-id="ddlTarget.connectionId!" :database="ddlTarget.database!" :schema="ddlTarget.schema" :table-name="ddlTarget.label" :dialect="ddlDialect" :format-dialect="ddlFormatDialect" v-model:open="showDdlDialog" />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in new issue
Block a user