Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(trino): support schema-aware table browsing and inserts

t8y27f19a0376a5d
diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue
index 6e23fe0342..3bd534bf61 100644
--- a/src/components/grid/DataGrid.vue
+++ b/src/components/grid/DataGrid.vue
@@ -812,7 +812,9 @@ const tableUsesSyntheticRowId = computed(() =>
usesSyntheticRowIdKey(props.databaseType, props.tableMeta?.primaryKeys ?? []),
);
const hiveTableTransactional = ref<boolean | undefined>(undefined);
-const canEditExistingRows = computed(() => canEditExistingTableRows(props.databaseType, hiveTableTransactional.value));
+const canEditExistingRows = computed(() =>
+ canEditExistingTableRows(props.databaseType, hiveTableTransactional.value, props.tableMeta?.primaryKeys ?? []),
+);
watch(
() => [props.databaseType, props.connectionId, props.database, props.tableMeta?.schema, props.tableMeta?.tableName],
async () => {
@@ -2033,7 +2035,7 @@ defineExpose({
{{ t("grid.refresh") }}
</Button>
<Button
- v-if="useTransaction && editable && (tableMeta || customSave)"
+ v-if="editable && (tableMeta || customSave)"
variant="ghost"
size="sm"
class="h-5 text-xs px-1.5 shrink-0"
diff --git a/src/lib/databaseCapabilities.ts b/src/lib/databaseCapabilities.ts
index aabf498825..4ebf85f446 100644
--- a/src/lib/databaseCapabilities.ts
+++ b/src/lib/databaseCapabilities.ts
@@ -12,6 +12,7 @@ export const SCHEMA_AWARE_TYPES = new Set<DatabaseType>([
"jdbc",
"h2",
"snowflake",
+ "trino",
"db2",
"informix",
]);
@@ -109,7 +110,14 @@ export const SINGLE_DATABASE_TYPES = new Set<DatabaseType>(["oracle", "dameng"])
export const FETCH_FIRST_TYPES = new Set<DatabaseType>(["oracle", "dameng"]);
-export const TREE_SCHEMA_TYPES = new Set<DatabaseType>(["postgres", "redshift", "sqlserver", "gaussdb", "jdbc"]);
+export const TREE_SCHEMA_TYPES = new Set<DatabaseType>([
+ "postgres",
+ "redshift",
+ "sqlserver",
+ "gaussdb",
+ "jdbc",
+ "trino",
+]);
export const PG_LIKE_STRUCTURE_TYPES = new Set<DatabaseType>(["postgres", "redshift", "gaussdb"]);
diff --git a/src/lib/tableEditing.ts b/src/lib/tableEditing.ts
index b5dac52253..7ea66a8884 100644
--- a/src/lib/tableEditing.ts
+++ b/src/lib/tableEditing.ts
@@ -12,18 +12,21 @@ export function editablePrimaryKeys(databaseType: DatabaseType | undefined, colu
export function isTableDataEditable(databaseType: DatabaseType | undefined, primaryKeys: string[]): boolean {
if (databaseType === "hive") return true;
+ if (databaseType === "trino") return true;
return primaryKeys.length > 0;
}
export function supportsDataGridTransaction(databaseType: DatabaseType | undefined): boolean {
- return databaseType !== "hive";
+ return databaseType !== "hive" && databaseType !== "trino";
}
export function canEditExistingTableRows(
databaseType: DatabaseType | undefined,
hiveTableTransactional?: boolean,
+ primaryKeys: string[] = [],
): boolean {
if (databaseType === "hive") return hiveTableTransactional === true;
+ if (databaseType === "trino") return primaryKeys.length > 0;
return true;
}
diff --git a/tests/dataGridSql.test.ts b/tests/dataGridSql.test.ts
index 0b673cfee9..9077001d63 100644
--- a/tests/dataGridSql.test.ts
+++ b/tests/dataGridSql.test.ts
@@ -80,6 +80,24 @@ test("builds Hive grid save statements without primary keys using row predicates
]);
});
+test("builds Trino insert statements with schema-qualified identifiers", () => {
+ const statements = buildDataGridSaveStatements({
+ databaseType: "trino",
+ tableMeta: {
+ schema: "tiny",
+ tableName: "nation",
+ primaryKeys: [],
+ },
+ columns: ["nationkey", "name"],
+ rows: [],
+ dirtyRows: [],
+ deletedRows: [],
+ newRows: [[100, "Atlantis"]],
+ });
+
+ assert.deepEqual(statements, ['INSERT INTO "tiny"."nation" ("nationkey", "name") VALUES (100, \'Atlantis\');']);
+});
+
test("uses Oracle ROWID as a synthetic key without writing it as a normal column", () => {
const statements = buildDataGridSaveStatements({
databaseType: "oracle",
diff --git a/tests/databaseCapabilities.test.ts b/tests/databaseCapabilities.test.ts
new file mode 100644
index 0000000000..46d06bda2b
--- /dev/null
+++ b/tests/databaseCapabilities.test.ts
@@ -0,0 +1,11 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { SCHEMA_AWARE_TYPES, TREE_SCHEMA_TYPES } from "../src/lib/databaseCapabilities.ts";
+
+test("treats Trino catalogs as schema tree roots", () => {
+ assert.equal(TREE_SCHEMA_TYPES.has("trino"), true);
+});
+
+test("treats Trino tables as schema-qualified SQL targets", () => {
+ assert.equal(SCHEMA_AWARE_TYPES.has("trino"), true);
+});
diff --git a/tests/tableEditing.test.ts b/tests/tableEditing.test.ts
index cf90c8fbed..f7975b27df 100644
--- a/tests/tableEditing.test.ts
+++ b/tests/tableEditing.test.ts
@@ -38,12 +38,14 @@ test("does not synthesize ROWID for non-Oracle keyless tables", () => {
test("allows Hive table data editing even without declared primary keys", () => {
assert.equal(isTableDataEditable("hive", []), true);
+ assert.equal(isTableDataEditable("trino", []), true);
assert.equal(isTableDataEditable("mysql", []), false);
assert.equal(isTableDataEditable("postgres", ["id"]), true);
});
test("does not use transactional grid saves for Hive", () => {
assert.equal(supportsDataGridTransaction("hive"), false);
+ assert.equal(supportsDataGridTransaction("trino"), false);
assert.equal(supportsDataGridTransaction("postgres"), true);
});
@@ -51,6 +53,8 @@ test("allows existing row edits for Hive only when the table is transactional",
assert.equal(canEditExistingTableRows("hive", true), true);
assert.equal(canEditExistingTableRows("hive", false), false);
assert.equal(canEditExistingTableRows("hive", undefined), false);
+ assert.equal(canEditExistingTableRows("trino", undefined, []), false);
+ assert.equal(canEditExistingTableRows("trino", undefined, ["id"]), true);
assert.equal(canEditExistingTableRows("postgres", undefined), true);
});
diff --git a/tests/tableSelectSql.test.ts b/tests/tableSelectSql.test.ts
index 0d3109fc52..6ca3ae1584 100644
--- a/tests/tableSelectSql.test.ts
+++ b/tests/tableSelectSql.test.ts
@@ -28,6 +28,17 @@ test("builds a schema-qualified PostgreSQL table WHERE query", () => {
assert.equal(sql, 'SELECT * FROM "public"."orders" WHERE (amount > 10) LIMIT 50 OFFSET 100;');
});
+test("builds schema-qualified Trino table data queries", () => {
+ const sql = buildTableSelectSql({
+ databaseType: "trino",
+ schema: "tiny",
+ tableName: "nation",
+ limit: 100,
+ });
+
+ assert.equal(sql, 'SELECT * FROM "tiny"."nation" LIMIT 100;');
+});
+
test("builds Hive table data queries with backtick identifiers", () => {
const sql = buildTableSelectSql({
databaseType: "hive",