Giter Club home page Giter Club logo

vscode-powerquery-sdk's Introduction

Power Query Connector SDK for VS Code

Provides functionality related to the development and testing of Custom Connectors for Power Query and Power BI.

Features

  • Custom connector template
  • Build connector file (.mez)
  • Set credentials
  • Run test queries
  • View query results

How to install the SDK using the Visual Studio Code User Interface

  1. Launch Visual Studio Code
  2. Select the Extensions view (Ctrl+Shift+X)

Open the extensions view in Visual Studio Code

  1. Click the ellipse in the upper right hand corner of the Extensions view, and select Install From VSIX ...

Install the extension from a vsix file

  1. Close and reopen Visual Studio Code

Using the Power Query SDK

This article focuses on the experience available for the Power Query SDK found in Visual Studio Code. You can learn more on how to install the Power Query SDK for Visual Studio from the article on Installing the SDK.

Create a new project

Before creating an extension project, it is recommended that you create a new folder where you'll store your extension project. During the creation of a new project, if no folder is selected, the Power Query SDK will help you locate or create a new folder before creating your extension project.

Once in Visual Studio Code, In the main Explorer pane of Visual Studio Code, you'll be able to see a section with the name Power Query SDK. This section will have only one button that reads Create an extension project. Select this button.

Create a new extension project button in Visual Studio Code

This button will open an input field at the top of the Visual Studio Code interface where you can enter the name of your new extension project and hit Enter.

Creating a new extension project and naming the project

After a few seconds, your Visual Studio Code window should open the main *.pq file for your extension project that contains your connector logic. The Power Query SDK will automatically run some necessary tasks to complete the setup of your workspace and you can check this in the Output console in Visual Studio Code.

Extension project created using the Hello World template

The Power Query SDK automatically creates the following set of files:

  • A settings.json file that dictates specific settings to work with at your workspace level
  • It builds the extension as a .mez file and stores it in a new bin\AnyCPU\Debug folder
  • A set of connector icons as png files
  • A resources.resx that serves as the main storage for strings to be used in the extension
  • A .pq file that holds the main logic of your extension or connector
  • A .query.pq file that main purpose is to be used as a way to create test queries that you can later evaluate
  • A .proj file that holds information about the extension project

Connector files

Once a extension project is recognized by the Power Query SDK, the section for the Power Query SDK will change its appearance, and will now display a list of tasks that you can run against your new extension project.

Tasks inside the Power Query SDK section

Credentials

Before you can evaluate any queries of your data connector, it is required to have a credential set.

The Power Query SDK offers multiple tasks through its user interface to allow you to set, list and delete credentials from your extension project.

Set credential

The Power Query SDK is primarily driven by tasks that can be triggered via multiple entry points. Setting a credential can be done in two ways and this is true for most tasks.

  1. Through the entry in the Power Query SDK section in the Explorer pane

Setting a credential through the Power Query SDK section in the Explorer

  1. Through the Terminal by selecting the "Run Task..." option and selecting the group of tasks for powerquery

Setting a credential through the Terminal menu

When you run this task, Visual Studio Code will guide you through a series of prompts to allow you to set the credential. These series of prompts are predictable and will always consist of the same stages:

  1. Choose the data source kind
  2. Choose the connector file
  3. Choose the authentication method

For the existing extension project, the authentication method available is anonymous and once the authentication is set a message box confirming that a credential has been generated successfully should be shown at the bottom right corner of the window.

Credential has been generated successfully

List credentials

Similar to setting a credential, the task to list credentials has two entry points in the same places: Power Query SDK section in the Explorer pane and inside the Terminal menu.

When this task is executed, it showcases the available credentials inside of the output terminal.

Credentials listed inside the Output console

Clear ALL credentials

Similar to the previous two tasks, the task to list credentials has two entry points in the same places: Power Query SDK section in the Explorer pane and inside the Terminal menu.

This task serves as a way to clear all credentials from your current session when you need to set a new credential to evaluate your queries.

The informational messages for this task are also shown in the output console.

Informational message for the Clear ALL credentials task

Evaluate a query and the results panel

Before you can evaluate any tests queries, a credential must be set. Using the connector that was created in the previous section, you can open the *.query.pq file that serves as your test query file.

For this specific connector where the project name was MyConnector, the code looks as follows:

// Use this file to write queries to test your data connector let result = MyConnector.Contents() in result

Before evaluating the query, let's change the code to look as follows:

// Use this file to write queries to test your data connector let result = MyConnector.Contents("Hello World") in result

Make sure to save the file after changing its code.

To evaluate this query you have three options:

  • Right select the file that's in use and select the option that reads "Evaluate current power query file"

Right click the current file to evaluate it

  • Going through the Terminal menu and selecting the "Evaluate current file" task

Selecting the evaluate current file task from the terminal menu experience

  • Use the native Run & Debug option from Visual Studio Code, select the hyperlink to create a launch.json file and then evaluate the file

Create a launch.json file to evaluate queries through the Run and Debug extensibility

After evaluating the query, the results will be displayed in the console at the bottom of the window and in a new panel called the results panel on the right.

Visual Studio Code window after evaluation has finalized showing the output in the console and the results panel

The results panel consists of three tabs:

  • Output tab: Displays a data preview of the query evaluated. If it's a table it will be displayed as grid.

Output tab in the results panel

  • Summary: Displays a summary of the Activity that ran the evaluation with statistics around it.

Summary tab in the results panel

  • DataSource: Displays general information about the data source used for the evaluation.

Summary tab in the results panel

To evaluate a different query you simply need to modify the *.query.pq file, save it and then run the evaluation task again with any of the three methods.

The Power Query SDK does not manage any sort of caching mechanism for the evaluations.

Bring a legacy extension project to the new SDK

This section is created to help connector developers who have extension projects that were created with the legacy Visual Studio based Power Query SDK.

To follow along, we recommend downloading the connector projects available from our DataConnectors repository for the TripPin sample, specifically the sample 9-TestConnection.

To bring the legacy extension project to the new SDK, follow these steps:

  1. Navigate to the folder where your extension project is located with Visual Studio Code's "Open folder" option in the File menu
  2. Setup a workspace using the existing folder and its contents via one of the following two methods:
  • The Power Query SDK has a mechanism to recognize the contents of your folder and suggest you to enable the conversion to a Power Query SDK workspace

Popup in the Visual Studio Code interface that suggests the user an upgrade to the Power Query SDK workspace

  • You can run the Setup workspace and the Build Task from the terminal menu. These will effectively create the .mez file and the settings.json files needed for the workspace

The addition of the two new folders and files is what transforms the current workspace into a new Power Query SDK workspace.

Upgrading the extension project to the new Power Query SDK

Setup workspace

What the Setup workspace task does is effectively create a settings.json file for your workspace that dictates some variables that will be used for your workspace when it comes to evaluations and general settings.

Build a extension file

The build task allows you to create the .mez file for your extension on demand.

Run TestConnection function

TestConnection is a function that enables your connector to be refreshed in the Microsoft Cloud through services such as Power BI. It's a record implemented inside of your connector data source record. You can learn more about the implementation of the TestConnection handler from the sample available for Test connection.

The task to run the TestConnection enables you to test such handler inside the Power Query SDK without having to manually try this handler in the Microsoft Cloud.

To run this task, first set a credential for your connector and then run the task either from the Power Query SDK section in the Explorer or through the list of tasks inside the terminal menu.

The result of such task will be displayed in the output terminal at the bottom of the window.

Result of the Run TestConnection function in the Power Query SDK

Related projects

vscode-powerquery

How to build and install from source

Install project dependencies:

npm install

Build the project and create the vsix installer (npx vsce package):

npm run vsix

Install the extension from the command line (code --install-extension <pqsdk.vsix>):

npm run code-install

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

vscode-powerquery-sdk's People

Contributors

albertli-msft avatar dependabot[bot] avatar mattmasson avatar microsoft-github-operations[bot] avatar microsoftopensource avatar ptyx507x avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.