다음을 통해 공유


Azure Data Studio 확장성 API

중요하다

Azure Data Studio는 2026년 2월 28일에사용 중지됩니다. Visual Studio Code를 사용하는 것을 권장합니다. Visual Studio Code로 마이그레이션하는 방법에 대한 자세한 내용은 Azure Data Studio에 무슨 일이 일어나고 있는지 확인하세요.

Azure Data Studio는 확장 프로그램이 개체 탐색기와 같은 Azure Data Studio의 다른 부분과 상호 작용하는 데 사용할 수 있는 API를 제공합니다. 이러한 API는 src/sql/azdata.d.ts 파일에서 사용할 수 있으며 아래에 설명되어 있습니다.

연결 관리

azdata.connection

연결 관리를 위한 최상위 함수

  • getCurrentConnection(): Thenable<azdata.connection.Connection> 현재 편집기 또는 개체 탐색기 선택에 따라 현재 연결을 가져옵니다.

  • getActiveConnections(): Thenable<azdata.connection.Connection[]> 모든 활성 사용자 연결 목록을 가져옵니다. 이러한 연결이 없으면 빈 목록을 반환합니다.

  • getCredentials(connectionId: string): Thenable<{ [name: string]: string }> 연결과 연결된 자격 증명을 포함하는 사전을 가져옵니다. 그렇지 않으면 data.connection.Connection 개체 아래의 옵션 사전의 일부로 반환되지만 해당 개체에서 제거됩니다.

연결

  • options: { [name: string]: string } 연결 옵션의 사전
  • providerName: string 연결 공급자의 이름(예: "MSSQL")
  • connectionId: string 연결의 고유 식별자

코드 예

> let connection = azdata.connection.getCurrentConnection();
connection: {
    providerName: 'MSSQL',
    connectionId: 'd97bb63a-466e-4ef0-ab6f-00cd44721dcc',
    options: {
        server: 'mairvine-sql-server',
        user: 'sa',
        authenticationType: 'sqlLogin',
        ...
 },
    ...
}
> let credentials = azdata.connection.getCredentials(connection.connectionId);
credentials: {
    password: 'abc123'
}

개체 탐색기

azdata.objectexplorer

개체 탐색기에 대한 최상위 함수

  • getNode(connectionId: string, nodePath?: string): Thenable<azdata.objectexplorer.ObjectExplorerNode> 지정된 연결 및 경로에 해당하는 개체 탐색기 노드를 가져옵니다. 지정된 경로가 없는 경우 지정된 연결의 최상위 노드를 반환합니다. 지정된 경로에 노드가 없으면 undefined반환합니다. 참고: 개체에 대한 nodePath의 경우 SQL Tools Service 백 엔드에서 생성되며 직접 생성하기 어렵습니다. 향후 API 개선으로 이름, 형식 및 스키마와 같이 노드에 대해 제공하는 메타데이터를 기반으로 노드를 가져올 수 있습니다.

  • getActiveConnectionNodes(): Thenable<azdata.objectexplorer.ObjectExplorerNode> 모든 활성 개체 탐색기 연결 노드를 가져옵니다.

  • findNodes(connectionId: string, type: string, schema: string, name: string, database: string, parentObjectNames: string[]): Thenable<azdata.objectexplorer.ObjectExplorerNode[]> 지정된 메타데이터와 일치하는 개체 탐색기 노드를 모두 찾습니다. 적용할 수 없는 경우, schema, databaseparentObjectNames 인수는 undefined이어야 합니다. parentObjectNames은(는) 개체 탐색기에서 가장 높은 수준에서 가장 낮은 수준까지의 계층 아래에 있는 원하는 개체에 속한 비데이터베이스 상위 개체의 목록입니다. 예를 들어 연결 ID가 connectionId이고, "schema1.table1" 테이블 및 "database1" 데이터베이스에 속하는 "column1" 열을 검색할 경우 findNodes(connectionId, 'Column', undefined, 'column1', 'database1', ['schema1.table1'])을 호출합니다. 이 API 호출에 대해 Azure Data Studio가 기본적으로 지원하는 유형 목록도 참조하세요

ObjectExplorerNode

  • connectionId: string 노드가 있는 연결의 ID입니다.

  • nodePath: string getNode 함수 호출에 사용되는 노드의 경로입니다.

  • nodeType: string 노드의 유형을 나타내는 문자열

  • nodeSubType: string 노드의 하위 유형을 나타내는 문자열

  • nodeStatus: string 노드의 상태를 나타내는 문자열입니다.

  • label: string 개체 탐색기에 표시되는 노드 레이블

  • isLeaf: boolean 노드가 리프 노드인지, 즉 자식이 없는지 여부입니다.

  • metadata: azdata.ObjectMetadata 이 노드가 나타내는 개체를 설명하는 메타데이터

  • errorMessage: string 노드가 오류 상태인 경우 표시되는 메시지

  • isExpanded(): Thenable<boolean> 노드가 현재 개체 탐색기에 확장되었는지 여부

  • setExpandedState(expandedState: vscode.TreeItemCollapsibleState): Thenable<void> 노드를 확장할지 또는 축소할지를 설정합니다. 상태가 None으로 설정된 경우 노드는 변경되지 않습니다.

  • setSelected(selected: boolean, clearOtherSelections?: boolean): Thenable<void> 노드가 선택되었는지 여부를 설정합니다. clearOtherSelections이 true이면 새 선택을 할 때 다른 선택 항목을 지웁니다. false이면 기존 선택 항목을 그대로 둡니다. clearOtherSelections 기본값은 selected가 true이면 true로, selected가 false인 경우 false로 설정됩니다.

  • getChildren(): Thenable<azdata.objectexplorer.ObjectExplorerNode[]> 이 노드의 모든 자식 노드를 가져옵니다. 자식이 없으면 빈 목록을 반환합니다.

  • getParent(): Thenable<azdata.objectexplorer.ObjectExplorerNode> 이 노드의 부모 노드를 가져옵니다. 부모가 없으면 정의되지 않은 값을 반환합니다.

코드 예

private async interactWithOENode(selectedNode: azdata.objectexplorer.ObjectExplorerNode): Promise<void> {
    let choices = ['Expand', 'Collapse', 'Select', 'Select (multi)', 'Deselect', 'Deselect (multi)'];
    if (selectedNode.isLeaf) {
 choices[0] += ' (is leaf)';
 choices[1] += ' (is leaf)';
 } else {
        let expanded = await selectedNode.isExpanded();
        if (expanded) {
 choices[0] += ' (is expanded)';
 } else {
 choices[1] += ' (is collapsed)';
 }
 }
    let parent = await selectedNode.getParent();
    if (parent) {
 choices.push('Get Parent');
 }
    let children = await selectedNode.getChildren();
 children.forEach(child => choices.push(child.label));
    let choice = await vscode.window.showQuickPick(choices);
 let nextNode: azdata.objectexplorer.ObjectExplorerNode = undefined;
    if (choice === choices[0]) {
 selectedNode.setExpandedState(vscode.TreeItemCollapsibleState.Expanded);
 } else if (choice === choices[1]) {
 selectedNode.setExpandedState(vscode.TreeItemCollapsibleState.Collapsed);
 } else if (choice === choices[2]) {
 selectedNode.setSelected(true);
 } else if (choice === choices[3]) {
 selectedNode.setSelected(true, false);
 } else if (choice === choices[4]) {
 selectedNode.setSelected(false);
 } else if (choice === choices[5]) {
 selectedNode.setSelected(false, true);
 } else if (choice === 'Get Parent') {
 nextNode = parent;
 } else {
        let childNode = children.find(child => child.label === choice);
 nextNode = childNode;
 }
    if (nextNode) {
        let updatedNode = await azdata.objectexplorer.getNode(nextNode.connectionId, nextNode.nodePath);
        this.interactWithOENode(updatedNode);
 }
}

vscode.commands.registerCommand('mssql.objectexplorer.interact', () => {
 azdata.objectexplorer.getActiveConnectionNodes().then(activeConnections => {
 vscode.window.showQuickPick(activeConnections.map(connection => connection.label + ' ' + connection.connectionId)).then(selection => {
            let selectedNode = activeConnections.find(connection => connection.label + ' ' + connection.connectionId === selection);
            this.interactWithOENode(selectedNode);
 });
 });
});

제안된 API

확장에서 대화 상자, 마법사 및 문서 탭에 사용자 지정 UI를 표시할 수 있도록 제안된 API를 추가했습니다. 추가 설명서는 제안된 API 형식 파일 참조하세요. 하지만 이러한 API는 언제든지 변경될 수 있습니다. 이러한 API 중 일부를 사용하는 방법의 예는 "하위 서비스" 샘플 확장찾을 수 있습니다.