feat(easysearch): add first-class database support
This commit is contained in:
80 files changed
+875
-107
No files matched your search
+37
-6
@@ -11,11 +11,11 @@ function installLocalStorage() {
|
||||
});
|
||||
}
|
||||
|
||||
function esConnection(): ConnectionConfig {
|
||||
function esConnection(dbType: "elasticsearch" | "easysearch" = "elasticsearch", id = "es-1"): ConnectionConfig {
|
||||
return {
|
||||
id: "es-1",
|
||||
name: "Elasticsearch",
|
||||
db_type: "elasticsearch",
|
||||
id,
|
||||
name: dbType === "easysearch" ? "Easysearch" : "Elasticsearch",
|
||||
db_type: dbType,
|
||||
host: "127.0.0.1",
|
||||
port: 9200,
|
||||
username: "",
|
||||
@@ -24,11 +24,11 @@ function esConnection(): ConnectionConfig {
|
||||
} as ConnectionConfig;
|
||||
}
|
||||
|
||||
function seedConnectionNode(store: { treeNodes: TreeNode[]; connectedIds: Set<string> }, id = "es-1") {
|
||||
function seedConnectionNode(store: { treeNodes: TreeNode[]; connectedIds: Set<string> }, id = "es-1", label = "Elasticsearch") {
|
||||
store.connectedIds.add(id);
|
||||
store.treeNodes.push({
|
||||
id,
|
||||
label: "Elasticsearch",
|
||||
label,
|
||||
type: "connection",
|
||||
connectionId: id,
|
||||
isExpanded: false,
|
||||
@@ -136,4 +136,35 @@ describe("connectionStore Elasticsearch open/expand", () => {
|
||||
.sort(),
|
||||
).toEqual(["orders", "users"]);
|
||||
});
|
||||
|
||||
it("loads Easysearch indices through the Elasticsearch-compatible tree", async () => {
|
||||
const elasticsearchListIndices = vi.fn().mockResolvedValue(["orders", "users"]);
|
||||
const checkConnectionHealth = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth,
|
||||
elasticsearchListIndices,
|
||||
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
|
||||
loadSchemaCache: vi.fn().mockResolvedValue(null),
|
||||
saveSchemaCache: vi.fn().mockResolvedValue(undefined),
|
||||
saveConnections: vi.fn().mockResolvedValue(undefined),
|
||||
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.addEphemeralConnection(esConnection("easysearch", "easysearch-1"));
|
||||
seedConnectionNode(store, "easysearch-1", "Easysearch");
|
||||
|
||||
await store.loadElasticsearchIndices("easysearch-1");
|
||||
|
||||
expect(elasticsearchListIndices).toHaveBeenCalledWith("easysearch-1");
|
||||
expect(
|
||||
store.treeNodes
|
||||
.find((node) => node.id === "easysearch-1")
|
||||
?.children?.map((node) => node.label)
|
||||
.sort(),
|
||||
).toEqual(["orders", "users"]);
|
||||
});
|
||||
});
|
||||
@@ -967,6 +967,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
oracle: "Oracle",
|
||||
"mongodb-legacy": MONGO_LEGACY_DRIVER_LABEL,
|
||||
elasticsearch: "Elasticsearch",
|
||||
easysearch: "Easysearch",
|
||||
qdrant: "Qdrant",
|
||||
milvus: "Milvus",
|
||||
weaviate: "Weaviate",
|
||||
@@ -2602,7 +2603,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await loadZooKeeperRoot(connectionId);
|
||||
} else if (config.db_type === "mongodb") {
|
||||
await loadMongoDatabases(connectionId);
|
||||
} else if (config.db_type === "elasticsearch") {
|
||||
} else if (config.db_type === "elasticsearch" || config.db_type === "easysearch") {
|
||||
// Reload: list indices.
|
||||
await loadElasticsearchIndices(connectionId);
|
||||
} else if (config.db_type === "milvus") {
|
||||
@@ -3121,7 +3122,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
async function loadConnectedConnectionRootForSidebarSearch(connectionId: string) {
|
||||
if (!connectedIds.value.has(connectionId)) return;
|
||||
const config = getConfig(connectionId);
|
||||
if (!config || ["redis", "etcd", "zookeeper", "mongodb", "elasticsearch", "milvus", "qdrant", "weaviate", "chromadb", "mq", "nacos"].includes(config.db_type)) return;
|
||||
if (!config || ["redis", "etcd", "zookeeper", "mongodb", "elasticsearch", "easysearch", "milvus", "qdrant", "weaviate", "chromadb", "mq", "nacos"].includes(config.db_type)) return;
|
||||
const node = findConnectionNode(connectionId);
|
||||
if (!node || node.type !== "connection" || node.isLoading || hasConnectionMetadataChildren(node.children)) return;
|
||||
const scope = { kind: "connection-databases" as const, connectionId, driverProfile: metadataDriverProfile(config) };
|
||||
@@ -5007,7 +5008,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
await loadZooKeeperRoot(node.connectionId);
|
||||
} else if (config?.db_type === "mongodb") {
|
||||
await loadMongoDatabases(node.connectionId);
|
||||
} else if (config?.db_type === "elasticsearch") {
|
||||
} else if (config?.db_type === "elasticsearch" || config?.db_type === "easysearch") {
|
||||
await loadElasticsearchIndices(node.connectionId);
|
||||
} else if (config?.db_type === "milvus") {
|
||||
await loadMilvusDatabases(node.connectionId);
|
||||
|
||||
@@ -46,7 +46,7 @@ import { frontendQueryTimeoutSecsForSql, queryTimeoutSecsForConnection } from "@
|
||||
import { queryResultNameFromPreamble, queryResultSourceLabel } from "@/lib/sql/queryResultSource";
|
||||
import { simpleDataGridOrderByReferencesMissingColumn, sortDataGridRowIndexes, type DataGridSortDirection } from "@/lib/dataGrid/dataGridSort";
|
||||
import { MAX_RESULT_PAGE_SIZE, normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";
|
||||
import { executableStatementRanges, splitSqlStatementRanges } from "@/lib/sql/sqlStatementRanges";
|
||||
import { elasticsearchRestRequestRanges, executableStatementRanges, splitSqlStatementRanges } from "@/lib/sql/sqlStatementRanges";
|
||||
import { externalSqlFileDisplayTitles, normalizeExternalSqlPath } from "@/lib/sql/sqlFileOpen";
|
||||
import { clearDataGridPendingSnapshotsForTab } from "@/composables/useDataGridEditor";
|
||||
import { buildTabResultSnapshot, deleteTabResultSnapshot, pruneTabResultSnapshots, readTabResultSnapshot, tabResultCacheKey, writeTabResultSnapshot } from "@/lib/tabs/tabResultCache";
|
||||
@@ -372,14 +372,6 @@ function annotateQueryResultSource(result: QueryResult, sourceStatement: string,
|
||||
return result;
|
||||
}
|
||||
|
||||
const ELASTICSEARCH_REST_REQUEST = /^(?:GET|POST|PUT|DELETE|HEAD)\s+\S+/i;
|
||||
|
||||
function elasticsearchRestRequestRanges(sql: string, databaseType?: DatabaseType) {
|
||||
if (databaseType !== "elasticsearch") return [];
|
||||
const requests = splitSqlStatementRanges(sql, databaseType);
|
||||
return requests.length > 0 && requests.every((request) => ELASTICSEARCH_REST_REQUEST.test(request.sql)) ? requests : [];
|
||||
}
|
||||
|
||||
function elasticsearchHttpErrorStatus(result: QueryResult): number | undefined {
|
||||
const statusIndex = result.columns.findIndex((column) => column.toLowerCase() === "status");
|
||||
if (statusIndex < 0) return undefined;
|
||||
|
||||
Reference in new issue
Block a user