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: support DuckDB extensions in macOS builds

t8y2455f04a874d7
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 0404a122d6..a89ce5afd5 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -513,6 +513,8 @@ export default {
cte: "Queries with WITH/CTE are not editable yet. Use a simple single-table SELECT.",
"set-operation": "UNION, INTERSECT, or EXCEPT results cannot be mapped safely back to source rows.",
aggregation: "DISTINCT, GROUP BY, HAVING, and aggregate results cannot be edited directly.",
+ "external-source":
+ "External files and table-function results cannot be written back directly. Import them into a database table before editing.",
"complex-source": "JOINs, multiple tables, and subqueries cannot be mapped safely to one source row.",
"computed-columns":
"Computed expressions or function results cannot be written back. Select raw column names instead.",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 4c008a1139..1ddd36d519 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -508,6 +508,7 @@ export default {
cte: "包含 WITH/CTE 的查询暂不支持直接回写。请改为简单单表 SELECT。",
"set-operation": "包含 UNION、INTERSECT 或 EXCEPT 的结果无法安全定位原表行。",
aggregation: "包含 DISTINCT、GROUP BY、HAVING 或聚合结果,无法直接编辑原始数据。",
+ "external-source": "外部文件或表函数查询结果无法直接回写,请先导入到数据库表后再编辑。",
"complex-source": "包含 JOIN、多个表或子查询的结果无法安全定位单个原表行。",
"computed-columns": "结果列包含表达式或函数,无法安全回写。请查询原始列名。",
"no-table": "未识别到可编辑的数据表。",
diff --git a/apps/desktop/src/lib/sqlAnalysis.ts b/apps/desktop/src/lib/sqlAnalysis.ts
index 34f983c85a..ee6fb8bec7 100644
--- a/apps/desktop/src/lib/sqlAnalysis.ts
+++ b/apps/desktop/src/lib/sqlAnalysis.ts
@@ -40,6 +40,7 @@ export type QueryEditabilityReason =
| "cte"
| "set-operation"
| "aggregation"
+ | "external-source"
| "complex-source"
| "computed-columns"
| "no-table"
@@ -88,6 +89,7 @@ export function analyzeEditableQueryEditability(sql: string): QueryEditability {
const fromEnd = firstTopLevelKeywordIndex(normalized, ["WHERE", "ORDER", "LIMIT", "OFFSET", "FETCH"], fromIndex + 4);
const fromBody = normalized.slice(fromIndex + 4, fromEnd < 0 ? normalized.length : fromEnd).trim();
+ if (isExternalFromSource(fromBody)) return { editable: false, reason: "external-source" };
const source = parseFromSource(fromBody);
if (!source) return { editable: false, reason: "complex-source" };
@@ -113,6 +115,7 @@ export function queryEditabilityMessageKey(reason: QueryEditabilityReason): stri
cte: "grid.queryEditUnsupportedCte",
"set-operation": "grid.queryEditUnsupportedSetOperation",
aggregation: "grid.queryEditUnsupportedAggregation",
+ "external-source": "grid.queryEditUnsupportedExternalSource",
"complex-source": "grid.queryEditUnsupportedComplexSource",
"computed-columns": "grid.queryEditUnsupportedComputedColumns",
"no-table": "grid.queryEditUnsupportedNoTable",
@@ -221,6 +224,11 @@ function parseFromSource(body: string): { schema?: string; tableName: string; al
return { schema, tableName, alias };
}
+function isExternalFromSource(body: string): boolean {
+ const trimmed = body.trim();
+ return /^'(?:''|[^'])*'(?:\s+(?:AS\s+)?[A-Za-z_][\w$]*)?$/i.test(trimmed) || /^[A-Za-z_][\w$]*\s*\(/.test(trimmed);
+}
+
function parseQualifiedIdentifier(text: string): { parts: string[]; end: number; rest: string; done: boolean } | null {
const parts: string[] = [];
let pos = 0;
diff --git a/crates/dbx-core/src/sql_editability.rs b/crates/dbx-core/src/sql_editability.rs
index 747d3eac12..6d108a15db 100644
--- a/crates/dbx-core/src/sql_editability.rs
+++ b/crates/dbx-core/src/sql_editability.rs
@@ -28,6 +28,7 @@ pub enum QueryEditabilityReason {
Cte,
SetOperation,
Aggregation,
+ ExternalSource,
ComplexSource,
ComputedColumns,
NoTable,
@@ -113,6 +114,9 @@ pub fn analyze_editable_query_editability(sql: &str) -> QueryEditability {
first_top_level_keyword_index(&normalized, &["WHERE", "ORDER", "LIMIT", "OFFSET", "FETCH"], from_body_start)
.unwrap_or(normalized.len());
let from_body = normalized[from_body_start..from_end].trim();
+ if is_external_from_source(from_body) {
+ return not_editable(QueryEditabilityReason::ExternalSource);
+ }
let Some(source) = parse_from_source(from_body) else {
return not_editable(QueryEditabilityReason::ComplexSource);
};
@@ -308,6 +312,40 @@ fn parse_from_source(body: &str) -> Option<FromSource> {
Some(FromSource { schema, table_name, alias })
}
+fn is_external_from_source(body: &str) -> bool {
+ let trimmed = body.trim();
+ is_single_quoted_source_with_optional_alias(trimmed) || starts_with_table_function(trimmed)
+}
+
+fn is_single_quoted_source_with_optional_alias(text: &str) -> bool {
+ let mut chars = text.char_indices().peekable();
+ if chars.next().map(|(_, ch)| ch) != Some('\'') {
+ return false;
+ }
+ while let Some((idx, ch)) = chars.next() {
+ if ch == '\'' {
+ if chars.peek().is_some_and(|(_, next)| *next == '\'') {
+ chars.next();
+ continue;
+ }
+ let tail = text[idx + ch.len_utf8()..].trim();
+ if tail.is_empty() {
+ return true;
+ }
+ let alias_text = strip_leading_as(tail).unwrap_or(tail).trim();
+ return read_identifier(alias_text, 0).is_some_and(|alias| alias.end == alias_text.len());
+ }
+ }
+ false
+}
+
+fn starts_with_table_function(text: &str) -> bool {
+ let Some(ident) = read_identifier(text, 0) else {
+ return false;
+ };
+ text[ident.end..].trim_start().starts_with('(')
+}
+
fn parse_qualified_identifier(text: &str) -> Option<QualifiedIdentifier> {
let mut parts = Vec::new();
let mut pos = 0usize;
@@ -566,6 +604,14 @@ mod tests {
assert_eq!(result.reason, Some(QueryEditabilityReason::ComplexSource));
}
+ #[test]
+ fn reports_external_file_scan_as_external_source() {
+ let result = analyze_editable_query_editability("SELECT * FROM '/tmp/duckdb_excel_extension_test.xlsx'");
+
+ assert_eq!(result.editable, false);
+ assert_eq!(result.reason, Some(QueryEditabilityReason::ExternalSource));
+ }
+
#[test]
fn reports_grouped_query_as_aggregation() {
let result = analyze_editable_query_editability("select id, count(*) as total from users group by id");
diff --git a/packages/app-tests/macosEntitlements.test.ts b/packages/app-tests/macosEntitlements.test.ts
new file mode 100644
index 0000000000..374f003c05
--- /dev/null
+++ b/packages/app-tests/macosEntitlements.test.ts
@@ -0,0 +1,18 @@
+import { strict as assert } from "node:assert";
+import { existsSync, readFileSync } from "node:fs";
+import test from "node:test";
+
+const tauriConfig = JSON.parse(readFileSync("src-tauri/tauri.conf.json", "utf8")) as {
+ bundle?: { macOS?: { entitlements?: string } };
+};
+
+test("macOS bundle disables library validation for DuckDB extensions", () => {
+ const entitlementsPath = tauriConfig.bundle?.macOS?.entitlements;
+
+ assert.equal(entitlementsPath, "Entitlements.plist");
+ assert.equal(existsSync(`src-tauri/${entitlementsPath}`), true);
+
+ const entitlements = readFileSync(`src-tauri/${entitlementsPath}`, "utf8");
+ assert.match(entitlements, /com\.apple\.security\.cs\.disable-library-validation/);
+ assert.match(entitlements, /<true\/>/);
+});
diff --git a/packages/app-tests/sqlAnalysis.test.ts b/packages/app-tests/sqlAnalysis.test.ts
index 2e929b39fa..423d433be6 100644
--- a/packages/app-tests/sqlAnalysis.test.ts
+++ b/packages/app-tests/sqlAnalysis.test.ts
@@ -61,6 +61,16 @@ test("reports why joined query results are not editable", () => {
assert.equal(queryEditabilityMessageKey(result.reason), "grid.queryEditUnsupportedComplexSource");
});
+test("reports DuckDB external file scans as read-only external sources", () => {
+ const result = analyzeEditableQueryEditability("SELECT * FROM '/tmp/duckdb_excel_extension_test.xlsx'");
+
+ assert.deepEqual(result, {
+ editable: false,
+ reason: "external-source",
+ });
+ assert.equal(queryEditabilityMessageKey(result.reason), "grid.queryEditUnsupportedExternalSource");
+});
+
test("reports computed result columns as unsafe to edit", () => {
const result = analyzeEditableQueryEditability("select id, count(*) as total from users group by id");
diff --git a/src-tauri/Entitlements.plist b/src-tauri/Entitlements.plist
new file mode 100644
index 0000000000..5a07243b07
--- /dev/null
+++ b/src-tauri/Entitlements.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.cs.disable-library-validation</key>
+ <true/>
+</dict>
+</plist>
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 9333078011..4b2c96f747 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -45,7 +45,9 @@
"mimeType": "application/sql"
}
],
- "macOS": {},
+ "macOS": {
+ "entitlements": "Entitlements.plist"
+ },
"windows": {
"nsis": {
"installMode": "currentUser",