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(postgres): suggest CURRENT_DATE in SQL completion

onenewcode7b7ed6f7b1d2
diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.ts
index bb0174d2be..23d046466e 100644
--- a/apps/desktop/src/lib/sql/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts
@@ -411,7 +411,11 @@ const POSTGRES_SQL_KEYWORDS = [
"JSONB_BUILD_OBJECT",
"JSONB_AGG",
"TO_JSONB",
+ "CURRENT_DATE",
+ "CURRENT_TIME",
"CURRENT_TIMESTAMP",
+ "LOCALTIME",
+ "LOCALTIMESTAMP",
];
const MYSQL_SQL_KEYWORDS = [
diff --git a/packages/app-tests/sqlCompletion.test.ts b/packages/app-tests/sqlCompletion.test.ts
index 556681fe70..21e3ec7e80 100644
--- a/packages/app-tests/sqlCompletion.test.ts
+++ b/packages/app-tests/sqlCompletion.test.ts
@@ -245,6 +245,43 @@ test("suggests database-specific data types and functions", () => {
assert.ok(mysqlCreateViewItems.some((item) => item.type === "function" && item.label === "DATE"));
});
+test("suggests PostgreSQL CURRENT_DATE as a keyword without parentheses", () => {
+ const itemsFor = (sql: string, databaseType: DatabaseType = "postgres") =>
+ buildSqlCompletionItems(sql, sql.length, {
+ tables: [],
+ columnsByTable: new Map(),
+ databaseType,
+ });
+ const assertBareKeyword = (items: ReturnType<typeof itemsFor>, label: string) => {
+ const item = items.find((candidate) => candidate.label === label);
+ assert.ok(item, `expected keyword ${label}`);
+ assert.equal(item.type, "keyword");
+ assert.equal((item.apply ?? item.label).includes("("), false);
+ };
+
+ assertBareKeyword(itemsFor("select current_d"), "CURRENT_DATE");
+
+ const currentPrefixItems = itemsFor("select current");
+ assertBareKeyword(currentPrefixItems, "CURRENT_DATE");
+ assertBareKeyword(currentPrefixItems, "CURRENT_TIMESTAMP");
+ assertBareKeyword(currentPrefixItems, "CURRENT_TIME");
+
+ const localtimeItems = itemsFor("select localt");
+ assertBareKeyword(localtimeItems, "LOCALTIME");
+ assertBareKeyword(localtimeItems, "LOCALTIMESTAMP");
+
+ const reportedSql = `SELECT * FROM "public"."table" where "CreateTime" >= current`;
+ assertBareKeyword(itemsFor(reportedSql), "CURRENT_DATE");
+
+ const mysqlCurrentDate = itemsFor("select current_d", "mysql").find((item) => item.label === "CURRENT_DATE");
+ assert.equal(mysqlCurrentDate?.type, "function");
+
+ assert.equal(
+ itemsFor("select current_d", "sqlserver").some((item) => item.label === "CURRENT_DATE"),
+ false,
+ );
+});
+
test("suggests MySQL VERSION and REVERSE without broadening other dialects", () => {
const buildFunctionItems = (prefix: string, databaseType?: "mysql" | "postgres" | "sqlserver") =>
buildSqlCompletionItems(`select ${prefix}`, `select ${prefix}`.length, {