style: fix formatting (oxfmt + cargo fmt)

This commit is contained in:
t8y2 2026-05-24 22:38:16 +08:00
parent 3f119cc9cf
commit 75e97001ec
8 changed files with 260 additions and 143 deletions

View File

@ -920,12 +920,12 @@ onUnmounted(() => {
@object-schema-change="(schema) => activeTab && queryStore.updateSchema(activeTab.id, schema)"
@structure-editor-saved="
activeTab &&
onStructureEditorSaved(onReloadData, toast, {
connectionId: activeTab.connectionId,
database: activeTab.database,
schema: activeTab.schema,
tableName: activeTab.structureTableName || '',
})
onStructureEditorSaved(onReloadData, toast, {
connectionId: activeTab.connectionId,
database: activeTab.database,
schema: activeTab.schema,
tableName: activeTab.structureTableName || '',
})
"
@structure-editor-close="activeTab && queryStore.closeTab(activeTab.id)"
/>

View File

@ -120,7 +120,8 @@ function tabColorStyle(tab: QueryTab) {
}
function tabIconClass(tab: QueryTab) {
if (tab.mode === "data" || tab.mode === "objects" || tab.mode === "structure") return "text-emerald-600 dark:text-emerald-400";
if (tab.mode === "data" || tab.mode === "objects" || tab.mode === "structure")
return "text-emerald-600 dark:text-emerald-400";
return "text-blue-600 dark:text-blue-400";
}

View File

@ -208,22 +208,11 @@ async function loadStructure(silent = false) {
errorMessage.value = "";
try {
await store.ensureConnected(props.connectionId);
const nextColumns = await api.getColumns(
props.connectionId,
props.database,
targetSchema.value,
props.tableName,
);
const nextColumns = await api.getColumns(props.connectionId, props.database, targetSchema.value, props.tableName);
const [nextIndexes, nextForeignKeys, nextTriggers] = await Promise.all([
api
.listIndexes(props.connectionId, props.database, targetSchema.value, props.tableName)
.catch(() => []),
api
.listForeignKeys(props.connectionId, props.database, targetSchema.value, props.tableName)
.catch(() => []),
api
.listTriggers(props.connectionId, props.database, targetSchema.value, props.tableName)
.catch(() => []),
api.listIndexes(props.connectionId, props.database, targetSchema.value, props.tableName).catch(() => []),
api.listForeignKeys(props.connectionId, props.database, targetSchema.value, props.tableName).catch(() => []),
api.listTriggers(props.connectionId, props.database, targetSchema.value, props.tableName).catch(() => []),
]);
columns.value = createColumnDrafts(nextColumns);
indexes.value = createIndexDrafts(nextIndexes);
@ -406,15 +395,7 @@ onMounted(() => {
});
watch(
[
isCreateMode,
databaseType,
() => props.schema,
() => props.tableName,
newTableName,
columns,
indexes,
],
[isCreateMode, databaseType, () => props.schema, () => props.tableName, newTableName, columns, indexes],
() => {
void refreshSqlPreview();
},
@ -442,9 +423,7 @@ watch(
</div>
<div v-if="isCreateMode" class="flex items-center gap-2">
<label class="shrink-0 text-[11px] font-medium text-muted-foreground">{{
t("structureEditor.tableName")
}}</label>
<label class="shrink-0 text-[11px] font-medium text-muted-foreground">{{ t("structureEditor.tableName") }}</label>
<Input
v-model="newTableName"
:placeholder="t('contextMenu.duplicateNamePlaceholder')"
@ -550,7 +529,9 @@ watch(
:loading-text="t('common.loading')"
:allow-custom="true"
trigger-class="h-6 w-full font-mono text-[11px]"
@update:model-value="(v: string) => column.dataType = combineDataType(v, splitDataType(column.dataType).params)"
@update:model-value="
(v: string) => (column.dataType = combineDataType(v, splitDataType(column.dataType).params))
"
/>
<Input
v-else
@ -564,7 +545,9 @@ watch(
:model-value="splitDataType(column.dataType).params"
class="h-6 min-w-16 font-mono text-[11px]"
:disabled="isColumnTypeDisabled(column)"
@update:model-value="column.dataType = combineDataType(splitDataType(column.dataType).baseType, String($event))"
@update:model-value="
column.dataType = combineDataType(splitDataType(column.dataType).baseType, String($event))
"
/>
</td>
<td class="border-b border-r px-1.5 py-1">
@ -584,7 +567,11 @@ watch(
type="checkbox"
class="h-3.5 w-3.5"
:disabled="isPrimaryKeyDisabled(column)"
@change="() => { if (column.isPrimaryKey) column.isNullable = false; }"
@change="
() => {
if (column.isPrimaryKey) column.isNullable = false;
}
"
/>
</td>
<td class="border-b border-r px-1.5 py-1">
@ -828,9 +815,7 @@ watch(
</DropdownMenuCheckboxItem>
</DropdownMenuContent>
</DropdownMenu>
<span v-else class="text-[11px] text-muted-foreground">{{
index.includedColumns.join(", ")
}}</span>
<span v-else class="text-[11px] text-muted-foreground">{{ index.includedColumns.join(", ") }}</span>
</td>
<td class="border-b border-r px-1.5 py-1">
<Input
@ -841,11 +826,7 @@ watch(
/>
</td>
<td class="border-b border-r px-1.5 py-1">
<Input
v-model="index.comment"
class="h-6 text-[11px]"
:disabled="!canEditIndexComment(index)"
/>
<Input v-model="index.comment" class="h-6 text-[11px]" :disabled="!canEditIndexComment(index)" />
</td>
<td class="border-b px-1.5 py-1">
<Badge v-if="index.isPrimary" variant="outline">{{ t("structureEditor.primary") }}</Badge>
@ -895,11 +876,7 @@ watch(
{{ t("structureEditor.emptyReadonly") }}
</div>
<div v-else class="space-y-1.5">
<div
v-for="trigger in triggers"
:key="trigger.name"
class="rounded-md border px-2 py-1.5 text-[11px]"
>
<div v-for="trigger in triggers" :key="trigger.name" class="rounded-md border px-2 py-1.5 text-[11px]">
<div class="font-medium">{{ trigger.name }}</div>
<div class="mt-1 font-mono text-muted-foreground">{{ trigger.timing }} {{ trigger.event }}</div>
</div>
@ -912,7 +889,11 @@ watch(
<div class="flex items-center justify-between border-b px-2 py-1.5 text-[11px] font-medium">
<div class="flex items-center gap-1.5">
<span>{{ t("structureEditor.sqlPreview") }}</span>
<Badge v-if="!saving && pendingStatements.length && warnings.length === 0" variant="outline" class="h-4 px-1 text-[10px]">
<Badge
v-if="!saving && pendingStatements.length && warnings.length === 0"
variant="outline"
class="h-4 px-1 text-[10px]"
>
<Check class="h-3 w-3" />
{{ t("structureEditor.ready") }}
</Badge>
@ -936,7 +917,8 @@ watch(
<pre
v-if="pendingStatements.length"
class="whitespace-pre-wrap break-words rounded-md bg-muted/40 p-2 font-mono text-[11px] leading-4"
v-html="highlightedSql" />
v-html="highlightedSql"
/>
<div v-else class="flex h-full items-center justify-center text-sm text-muted-foreground">
{{ t("structureEditor.noChanges") }}
</div>

View File

@ -126,7 +126,11 @@ export function useNavigationTargets(dialogs: {
) {
if (!context.tableName) {
try {
await connectionStore.refreshObjectListTreeNode(context.connectionId, context.database, context.schema || undefined);
await connectionStore.refreshObjectListTreeNode(
context.connectionId,
context.database,
context.schema || undefined,
);
} catch {}
return;
}

View File

@ -15,9 +15,7 @@ type ShikiHighlighter = Awaited<ReturnType<typeof import("shiki/core").createHig
let highlighterPromise: Promise<ShikiHighlighter> | undefined;
export async function createShikiSqlHighlighter(
options: ShikiSqlHighlighterOptions,
): Promise<SqlHighlighter> {
export async function createShikiSqlHighlighter(options: ShikiSqlHighlighterOptions): Promise<SqlHighlighter> {
const highlighter = await getShikiSqlHighlighter();
return (content, appearance = options.appearance()) =>
highlighter.codeToHtml(content, {
@ -33,13 +31,7 @@ function getShikiSqlHighlighter(): Promise<ShikiHighlighter> {
}
async function loadShikiSqlHighlighter(): Promise<ShikiHighlighter> {
const [
{ createHighlighterCore },
{ createJavaScriptRegexEngine },
githubDark,
githubLight,
sql,
] = await Promise.all([
const [{ createHighlighterCore }, { createJavaScriptRegexEngine }, githubDark, githubLight, sql] = await Promise.all([
import("shiki/core"),
import("shiki/engine/javascript"),
import("shiki/themes/github-dark.mjs"),

View File

@ -3,73 +3,229 @@ import type { EditableStructureColumn, EditableStructureIndex } from "./tableStr
export const DATA_TYPE_OPTIONS: Record<string, string[]> = {
mysql: [
"tinyint", "smallint", "mediumint", "int", "integer", "bigint",
"float", "double", "double precision", "real",
"decimal", "numeric",
"bit", "boolean", "bool", "serial",
"char", "varchar", "tinytext", "text", "mediumtext", "longtext",
"binary", "varbinary", "tinyblob", "blob", "mediumblob", "longblob",
"enum", "set",
"date", "datetime", "timestamp", "time", "year",
"tinyint",
"smallint",
"mediumint",
"int",
"integer",
"bigint",
"float",
"double",
"double precision",
"real",
"decimal",
"numeric",
"bit",
"boolean",
"bool",
"serial",
"char",
"varchar",
"tinytext",
"text",
"mediumtext",
"longtext",
"binary",
"varbinary",
"tinyblob",
"blob",
"mediumblob",
"longblob",
"enum",
"set",
"date",
"datetime",
"timestamp",
"time",
"year",
"json",
"geometry", "point", "linestring", "polygon", "multipoint", "multilinestring", "multipolygon", "geometrycollection",
"geometry",
"point",
"linestring",
"polygon",
"multipoint",
"multilinestring",
"multipolygon",
"geometrycollection",
],
postgres: [
"smallint", "int2", "integer", "int", "int4", "bigint", "int8",
"smallserial", "serial", "bigserial",
"decimal", "numeric", "real", "float", "float4", "double precision", "float8", "money",
"boolean", "bool",
"char", "character", "varchar", "character varying", "text",
"smallint",
"int2",
"integer",
"int",
"int4",
"bigint",
"int8",
"smallserial",
"serial",
"bigserial",
"decimal",
"numeric",
"real",
"float",
"float4",
"double precision",
"float8",
"money",
"boolean",
"bool",
"char",
"character",
"varchar",
"character varying",
"text",
"bytea",
"date", "time", "time without time zone", "time with time zone", "timetz", "timestamp", "timestamp without time zone", "timestamp with time zone", "timestamptz", "interval",
"date",
"time",
"time without time zone",
"time with time zone",
"timetz",
"timestamp",
"timestamp without time zone",
"timestamp with time zone",
"timestamptz",
"interval",
"uuid",
"json", "jsonb", "xml",
"bit", "bit varying", "varbit",
"tsvector", "tsquery",
"cidr", "inet", "macaddr", "macaddr8",
"point", "line", "lseg", "box", "path", "polygon", "circle",
"int4range", "int8range", "numrange", "tsrange", "tstzrange", "daterange",
"json",
"jsonb",
"xml",
"bit",
"bit varying",
"varbit",
"tsvector",
"tsquery",
"cidr",
"inet",
"macaddr",
"macaddr8",
"point",
"line",
"lseg",
"box",
"path",
"polygon",
"circle",
"int4range",
"int8range",
"numrange",
"tsrange",
"tstzrange",
"daterange",
"oid",
],
sqlite: [
"integer", "real", "text", "blob", "numeric",
],
sqlite: ["integer", "real", "text", "blob", "numeric"],
sqlserver: [
"bit",
"tinyint", "smallint", "int", "integer", "bigint",
"decimal", "numeric", "float", "real", "money", "smallmoney",
"char", "nchar", "varchar", "nvarchar", "text", "ntext",
"date", "time", "datetime", "datetime2", "smalldatetime", "datetimeoffset", "timestamp",
"binary", "varbinary", "image",
"uniqueidentifier", "xml", "sql_variant", "hierarchyid",
"geography", "geometry",
"tinyint",
"smallint",
"int",
"integer",
"bigint",
"decimal",
"numeric",
"float",
"real",
"money",
"smallmoney",
"char",
"nchar",
"varchar",
"nvarchar",
"text",
"ntext",
"date",
"time",
"datetime",
"datetime2",
"smalldatetime",
"datetimeoffset",
"timestamp",
"binary",
"varbinary",
"image",
"uniqueidentifier",
"xml",
"sql_variant",
"hierarchyid",
"geography",
"geometry",
],
oracle: [
"number", "integer", "float", "binary_float", "binary_double",
"char", "nchar", "varchar2", "nvarchar2",
"clob", "nclob", "long",
"date", "timestamp", "timestamp with time zone", "timestamp with local time zone",
"interval year to month", "interval day to second",
"raw", "long raw", "blob", "bfile",
"boolean", "json", "vector",
"rowid", "urowid",
"xmltype", "sdo_geometry",
"number",
"integer",
"float",
"binary_float",
"binary_double",
"char",
"nchar",
"varchar2",
"nvarchar2",
"clob",
"nclob",
"long",
"date",
"timestamp",
"timestamp with time zone",
"timestamp with local time zone",
"interval year to month",
"interval day to second",
"raw",
"long raw",
"blob",
"bfile",
"boolean",
"json",
"vector",
"rowid",
"urowid",
"xmltype",
"sdo_geometry",
],
clickhouse: [
"Int8", "Int16", "Int32", "Int64", "Int128", "Int256",
"UInt8", "UInt16", "UInt32", "UInt64", "UInt128", "UInt256",
"Float16", "Float32", "Float64",
"Decimal", "Decimal32", "Decimal64", "Decimal128", "Decimal256",
"Int8",
"Int16",
"Int32",
"Int64",
"Int128",
"Int256",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"UInt128",
"UInt256",
"Float16",
"Float32",
"Float64",
"Decimal",
"Decimal32",
"Decimal64",
"Decimal128",
"Decimal256",
"Bool",
"String", "FixedString",
"Date", "Date32", "DateTime", "DateTime64",
"String",
"FixedString",
"Date",
"Date32",
"DateTime",
"DateTime64",
"UUID",
"IPv4", "IPv6",
"Enum8", "Enum16",
"Array", "Map", "Tuple", "Nested",
"Nullable", "LowCardinality",
"SimpleAggregateFunction", "AggregateFunction",
"Point", "Ring", "Polygon", "MultiPolygon",
"IPv4",
"IPv6",
"Enum8",
"Enum16",
"Array",
"Map",
"Tuple",
"Nested",
"Nullable",
"LowCardinality",
"SimpleAggregateFunction",
"AggregateFunction",
"Point",
"Ring",
"Polygon",
"MultiPolygon",
"JSON",
],
};

View File

@ -209,7 +209,9 @@ export const useQueryStore = defineStore("query", () => {
return existing.id;
}
const title = resolvedTableName ? t("structureEditor.editTabTitle", { tableName: resolvedTableName }) : t("structureEditor.createTitle");
const title = resolvedTableName
? t("structureEditor.editTabTitle", { tableName: resolvedTableName })
: t("structureEditor.createTitle");
const id = uuid();
const tab: QueryTab = {
id,

View File

@ -494,12 +494,8 @@ fn build_primary_key_sql(
.map(|c| c.name.as_str())
.collect();
let new_pk_names: Vec<&str> = options
.columns
.iter()
.filter(|c| !c.marked_for_drop && c.is_primary_key)
.map(|c| c.name.as_str())
.collect();
let new_pk_names: Vec<&str> =
options.columns.iter().filter(|c| !c.marked_for_drop && c.is_primary_key).map(|c| c.name.as_str()).collect();
if old_pk_names == new_pk_names {
return Vec::new();
@ -520,10 +516,7 @@ fn build_primary_key_sql(
StructureDialect::Postgres => {
let raw_table = options.table_name.split('.').last().unwrap_or(&options.table_name);
let pk_name = format!("{}_pkey", clean(raw_table));
statements.push(format!(
"ALTER TABLE {table} DROP CONSTRAINT {};",
quote_ident(dialect, &pk_name)
));
statements.push(format!("ALTER TABLE {table} DROP CONSTRAINT {};", quote_ident(dialect, &pk_name)));
}
StructureDialect::Mysql => {
statements.push(format!("ALTER TABLE {table} DROP PRIMARY KEY;"));
@ -533,11 +526,7 @@ fn build_primary_key_sql(
}
if !new_pk_names.is_empty() {
let pk_list = new_pk_names
.iter()
.map(|n| quote_ident(dialect, n))
.collect::<Vec<_>>()
.join(", ");
let pk_list = new_pk_names.iter().map(|n| quote_ident(dialect, n)).collect::<Vec<_>>().join(", ");
statements.push(format!("ALTER TABLE {table} ADD PRIMARY KEY ({pk_list});"));
}
@ -1590,10 +1579,7 @@ mod tests {
});
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(
result.statements,
vec!["ALTER TABLE \"public\".\"users\" ADD PRIMARY KEY (\"id\");"]
);
assert_eq!(result.statements, vec!["ALTER TABLE \"public\".\"users\" ADD PRIMARY KEY (\"id\");"]);
}
#[test]
@ -1621,10 +1607,7 @@ mod tests {
});
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(
result.statements,
vec!["ALTER TABLE \"public\".\"users\" DROP CONSTRAINT \"users_pkey\";"]
);
assert_eq!(result.statements, vec!["ALTER TABLE \"public\".\"users\" DROP CONSTRAINT \"users_pkey\";"]);
}
#[test]
@ -1670,10 +1653,7 @@ mod tests {
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(
result.statements,
vec![
"ALTER TABLE `users` DROP PRIMARY KEY;",
"ALTER TABLE `users` ADD PRIMARY KEY (`uuid`);",
]
vec!["ALTER TABLE `users` DROP PRIMARY KEY;", "ALTER TABLE `users` ADD PRIMARY KEY (`uuid`);",]
);
}