Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Visual Studio Code extension

This documentation applies to the FQL v10 version of the Fauna Visual Studio Code extension. The v10 and v4 versions aren’t compatible and can’t be used simultaneously. If you have the v4 version installed, it must be uninstalled before activating the v10 extension.

The Fauna Visual Studio Code extension provides rich support for the Fauna Query Language (FQL) and allows you to run queries, featuring autocompletion and awareness of your database environment.

Prerequisites

Install the Fauna extension

Go to the Visual Studio Marketplace and follow the instructions to install the Fauna extension.

Get an authentication token

You need an admin-level key’s secret to access the database in VS Code. See Keys.

If you already have a secret for an existing database, you may skip this step.

  1. Log in to your Fauna account using your email and password.

  2. Choose the Explorer menu item.

  3. Expand the Region Group and click the database you want to use.

  4. Hover over the database entry you want to use and click the key icon.

  5. In the Keys tab, click Create Key.

  6. Choose Admin and, optionally, enter VS Code as a Key Name.

  7. Click Save.

  8. Copy and save the Key Secret, which is needed to complete VS Code setup in the next step.

This is the only time Fauna displays the secret field. Fauna can’t recover the secret if it is discarded or lost. Copy and save the secret to a password manager or other safe location.

Add the authentication token to VS Code

Before using the extension, open the extension settings and set your secret to the database you want to run queries against. This can be set globally across all VS Code instances and at the Workspace level to allow for different databases per VS Code project.

Configure the Fauna extension for VS Code to access the Fauna database using the authentication token from the preceding step.

  1. In the VS Code activity bar, select the Fauna icon.

  2. Click Configure Fauna Extension.

  3. In the Fauna: Db Secret box, paste the saved secret from the preceding step.

    Leave the default Fauna: Endpoint unchanged.

The authentication token or key is a credential that provides full access to your database. don’t commit it to your .vscode configuration.

Run FQL queries

  1. Open the FQL Playground:

    Toggle the Playground opened or closed using one of the following methods:

    • cmd+l on Mac

    • ctrl+l on Linux and Windows

    • Fauna: Toggle Playground from the command palette.

  2. Enter an FQL query in the edit box. Submit the query by clicking Fauna: Run Query at the top right or entering Cmd+Enter or Ctrl+Enter.

    The response is displayed in the output window.

You can use .fql files to save any number of queries in your project.

Commands

The following commands are available from the command palette.

Command Description Key binding

Fauna: Run Query

Run the query in the FQL Playground or active .fql file.

Cmd+Enter
Ctrl+Enter

Fauna: Run Query as Document

Run the query in the FQL Playground or active .fql file as the provided document. This is useful if you have a document that has role membership and want to test permission.

Fauna: Run Query with Secret

Run the query in the FQL Playground or active .fql files with a given secret instead of using the secret set for the extension.

Fauna: Run Query as Role

Run the query in the FQL Playground or active .fql file as the provided role.

Fauna: Toggle Playground

Open the FQL Playground if closed or close the FQL Playground if open. This command saves the contents before closing.

cmd+l
ctrl+l

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!