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。

feat(mysql): suggest AES_ENCRYPT and AES_DECRYPT in SQL completion (#12849)

enilud6f125a44b37
diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.ts
index 8c25cb5e3f..046eaacbeb 100644
--- a/apps/desktop/src/lib/sql/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts
@@ -1131,6 +1131,8 @@ const SQL_FUNCTION_SIGNATURES = new Map<string, string[]>([
]);
const MYSQL_FUNCTION_SIGNATURES = new Map<string, string[]>([
+ ["AES_ENCRYPT", ["str", "key_str"]],
+ ["AES_DECRYPT", ["crypt_str", "key_str"]],
["CONVERT", ["expression", "type"]],
["DATE_FORMAT", ["date", "format"]],
["FROM_UNIXTIME", ["unix_timestamp"]],
diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.ts
index e4d5c286ef..c2e784d6e9 100644
--- a/packages/app-tests/sqlCompletion.test.ts
+++ b/packages/app-tests/sqlCompletion.test.ts
@@ -20,6 +20,7 @@ import {
} from "../../apps/desktop/src/lib/sql/sqlCompletion.ts";
import { sqlCompletionContextFromSemantic } from "../../apps/desktop/src/lib/sql/semantic/completion.ts";
import { buildSqlSemanticModel } from "../../apps/desktop/src/lib/sql/semantic/model.ts";
+import { sqlSnippetDatabaseTypeForConnection } from "../../apps/desktop/src/lib/database/jdbcDialect.ts";
import type { DatabaseType } from "../../apps/desktop/src/types/database.ts";
const tables: SqlCompletionTable[] = [
@@ -318,6 +319,41 @@ test("suggests MySQL VERSION and REVERSE without broadening other dialects", ()
assert.equal(buildFunctionItems("reve").find((item) => item.label === "REVERSE")?.apply, "REVERSE(${string})");
});
+test("suggests MySQL AES functions with required arguments, including through JDBC MySQL", () => {
+ const jdbcMysqlType = sqlSnippetDatabaseTypeForConnection({ db_type: "jdbc", connection_string: "jdbc:mysql://localhost:3306/app" });
+ assert.equal(jdbcMysqlType, "mysql");
+
+ for (const databaseType of ["mysql", jdbcMysqlType] as const) {
+ for (const [name, parameters] of [
+ ["AES_ENCRYPT", ["str", "key_str"]],
+ ["AES_DECRYPT", ["crypt_str", "key_str"]],
+ ] as const) {
+ const sql = `SELECT ${name.slice(0, -3)}`;
+ const items = buildSqlCompletionItems(sql, sql.length, {
+ tables: [],
+ columnsByTable: new Map(),
+ databaseType,
+ });
+ assert.equal(items.find((item) => item.type === "function" && item.label === name)?.apply, `${name}(${parameters.map((parameter) => `\${${parameter}}`).join(", ")})`);
+ const call = `SELECT ${name}(`;
+ assert.deepEqual(getSqlFunctionSignatureHelp(call, call.length, databaseType)?.parameters, parameters);
+ }
+ }
+
+ for (const databaseType of ["postgres", "sqlserver"] as const) {
+ const sql = "SELECT AES_";
+ const items = buildSqlCompletionItems(sql, sql.length, {
+ tables: [],
+ columnsByTable: new Map(),
+ databaseType,
+ });
+ assert.equal(
+ items.some((item) => item.type === "function" && (item.label === "AES_ENCRYPT" || item.label === "AES_DECRYPT")),
+ false,
+ );
+ }
+});
+
test("suggests the reported MySQL 5.7 built-in functions with dialect-specific signatures", () => {
const reportedFunctions = [
"VERSION",