Azure Data Studio 확장성 API

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 }> 연결과 연결된 자격 증명을 포함하는 사전을 가져옵니다. 그렇지 않으면 개체 아래 azdata.connection.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적용할 수 없는 경우여야 합니다undefined.parentObjectNamesdatabase 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> 노드가 선택되었는지 여부를 설정합니다. true이면 clearOtherSelections 새 선택을 할 때 다른 선택 항목을 지웁니다. false이면 기존 선택 항목을 그대로 둡니다. clearOtherSelections 은 true이면 selected true로, false인 경우 selected 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 중 일부를 사용하는 방법의 예제는 "sqlservices" 샘플 확장에서 찾을 수 있습니다.