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。

1.6 KB
Raw Blame
import type { DatabaseType } from "@/types/database";
import { supportsOracleDatabaseLinks, type OracleDatabaseLink } from "@/lib/database/oracleDatabaseLinks";
import { isSqlCompletionSuppressedContext } from "@/lib/sql/sqlCompletion";

export function oracleDatabaseLinkCompletionContext(sql: string, cursor: number, databaseType?: DatabaseType) {
  if (!supportsOracleDatabaseLinks(databaseType) || isSqlCompletionSuppressedContext(sql, cursor, { databaseType })) return null;
  const before = sql.slice(0, cursor);
  const match = /(?:[A-Za-z0-9_$#]|"(?:[^"]|"")+"|\))@([A-Za-z0-9_$#.]*)$/.exec(before);
  if (!match) return null;
  const prefix = match[1];
  return { prefix, from: cursor - prefix.length, to: cursor + (/^[A-Za-z0-9_$#.]*/.exec(sql.slice(cursor))?.[0].length ?? 0) };
}

export function oracleDatabaseLinkCompletionItems(links: readonly OracleDatabaseLink[], prefix: string) {
  const seen = new Set<string>();
  // Oracle resolves object@link against the login user's private links plus
  // PUBLIC links; CURRENT_SCHEMA never enables or disables either, and the
  // link query already restricts owners to SESSION_USER and PUBLIC.
  return [...links]
    .sort((a, b) => Number(a.owner === "PUBLIC") - Number(b.owner === "PUBLIC"))
    .filter((link) => {
      const key = link.name.toUpperCase();
      if (seen.has(key) || !key.startsWith(prefix.toUpperCase())) return false;
      seen.add(key);
      return true;
    })
    .map((link) => ({ label: link.name, apply: link.name, type: "namespace", detail: `${link.owner} · ${link.username || "—"} · ${link.host}` }));
}