DataGrip 2019.3 Help

Quick start with DataGrip

This quick start guide will introduce you to the key concepts and help you with your first steps in DataGrip.

Step 1. Configure initial settings

After you have installed the product and launched it for the first time, you see the initial configuration wizard. You can see a more detailed description of the installation process in Install DataGrip.

  1. On the first page, select the color scheme for DataGrip, which can be either light or dark.

  2. On the second page, you can configure the default dialect and a directory with SQL scripts.

    Default SQL dialect: code in SQL files is highlighted according to the selected dialect. For example, if you select Microsoft SQL Server, the SQL files will be highlighted as SQL Server files by default. You can change this setting later. To set a dialect for a file or a folder, see SQL Dialects.

    Scripts directory: a directory that is attached in the Files tool window (View | Tool Windows | Files). You can attach any directory later.

    Configure initial settings

Step 2. Install Docker and Git plugins

We are going to need Docker and Git plugins to run the PostgreSQL instance and clone git repositories. If you want to use your DBMS and your scripts, feel free to skip this step.

Install the Git plugin by JetBrains

To enable version control in DataGrip, install the Git plugin by JetBrains.

  1. Open settings Ctrl+Alt+S and navigate to Plugins.

  2. Click Marketplace.

  3. In the search field, type Git, and press Enter.

  4. To install the plugin, click Install and restart DataGrip.

Install the Git plugin by JetBrains

Install the Docker plugin by JetBrains

To Docker support in DataGrip, install the Docker plugin by JetBrains.

  1. Open settings Ctrl+Alt+S and navigate to Plugins.

  2. Click Marketplace.

  3. In the search field, type Docker, and press Enter.

  4. To install the plugin, click Install and restart DataGrip.

Install the Docker plugin by JetBrains

Step 3. Clone repositories

For example purposes, we are going to use the following two repositories: Sakila dump files (https://github.com/DataGrip/dumps) and Docker-compose files (https://github.com/JetBrains/docker-env-compose). Sakila repository includes scripts that generate the structure of the Sakila database and scripts that add data to database objects. Docker repository includes YAML files that define services, networks, and volumes.

Enable version control integration

  1. Click VCS | Enable Version Control Integration.

  2. In the Enable Version Control Integration dialog, ensure that Git is selected in the drop-down list and click OK.

    Enable version control integration

Clone repositories

  1. Click VCS | Git | Clone.

  2. In the URL field, copy and paste the following web URL:

    • Sakila dump files: https://github.com/DataGrip/dumps.git

    • Docker-compose files: https://github.com/JetBrains/docker-env-compose.git

  3. In the Directory field, click the folder icon (The folder icon) and specify a directory for the repository files.

    Clone repositories

Step 4. Run the Docker database image

For this tutorial, we are going to run a PostgreSQL container for Docker (from the docker-env-compose repository). You can view the full list of available services in docker-compose.yml. The service name is the first line of the service definition (before the JDBC URL). In the following example, the service name is pg_12.X, the JDBC URL is jdbc:postgresql://localhost:54333/guest?user=guest&password=guest.

You can run the container from a command line by running: docker-compose up -d pg_12.X. Otherwise, you can enable and use the Docker plugin in DataGrip.

pg_12.X: # jdbc:postgresql://localhost:54333/guest?user=guest&password=guest container_name: pg_12.X ports: - "54333:5432" image: postgres:12-alpine env_file: .env healthcheck: test: "exit 0"

Enable Docker support

  1. Install and run Docker.

    For more information, see the Docker documentation.

  2. Configure the Docker daemon connection settings.

    • In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Docker.

    • Click The Add button to add a Docker configuration and specify how to connect to the Docker daemon.

      The connection settings depend on your Docker version and operating system.

      The Connection successful message should appear at the bottom of the dialog.

      The Docker connection settings
  3. Connect to the Docker daemon.

    The configured Docker connection should appear in the Services tool window (View | Tool Windows | Services or Alt+8). Select the Docker node Docker node, and click The Connect button, or select Connect from the context menu.

    The Docker tool window, connected to Docker

    To edit the Docker connection settings, select the Docker node and click The Edit Configuration button on the toolbar, or select Edit Configuration from the context menu.

Create the Docker-compose deployment configuration

  1. In the Services tool window (View | Tool Windows | Services), right-click the Docker node and select Deploy.

  2. In the pop-up window, select Create Docker-compose Deployment.

  3. In the Create Deployment Configuration dialog, click the Browse icon of the Compose file(s) field.

  4. In the Docker Compose Configuration Files dialog, click the Add button and navigate to the compose file. The Compose YAML file defines services, networks, and volumes. In our case, it is docker-compose.yml

  5. In the Docker Compose Configuration Files dialog, click OK.

  6. In the Service(s) field, type pg_12.X.

  7. Click Run.

    As a result, you can see the pg_12.X running container in the Services tool window.

Step 5. Connect to a database

Depending on a database vendor (MySQL, PostgreSQL, Oracle), you need to create a corresponding data source connection. In this tutorial, we will create a PostgreSQL connection.

If you want to connect to other database management systems (DBMS), refer to Connecting to a database. If you cannot connect to

  1. Navigate to File | Data Sources Ctrl+Alt+S.

  2. In the Data Sources and Drivers dialog, click the Add icon (The Add icon) and select PostgreSQL.

  3. At the bottom of the data source settings area, click the Download missing driver files link. Alternatively, you can specify user drivers for the data source. For more information about user drivers, see Add a user driver to an existing connection.

  4. In the URL field, copy and paste the JDBC URL: jdbc:postgresql://localhost:54333/guest?user=guest&password=guest. JDBC URL for other DBMS, see in docker-compose.yml. You can open docker-compose.yml in a text editor.

  5. (Optional) In the Name field, delete the current name and type a new name for the connection (for example, PostgreSQL).

  6. To ensure that the connection to the data source is successful, click Test Connection.

Integration with PostgreSQL

Step 7. Attach a directory with SQL scripts

To run SQL scripts, you can right-click the data source and select Run SQL script. Alternatively, you can attach a folder with these scripts to the Files tool window and run them from here.

  1. Navigate to View | Tool Windows | Files.

  2. In the Files tool window, right-click any area and select Attach directory.

  3. Navigate to the directory that you want to attach. In our case, it the dumps directory.

  4. Click OK.

Attach a directory with SQL files

Step 8. Run the dump files

Create the database structure

  1. In the Files (View | Tool Windows | Project) tool window, navigate to the postgres-sakila-db tree node.

  2. Expand postgres-sakila-db tree node.

  3. Right-click the postgres-sakila-schema.sql and select Run postgres-sakila-schema .sql. Alternatively, click the postgres-sakila-schema.sql file and press Ctrl+Shift+F10.

  4. In the Execution Target dialog, select PostgreSQL and click OK.

Create the database structure

Load sample data to the database

  1. In the Files (View | Tool Windows | Project) tool window, navigate to the postgres-sakila-db tree node.

  2. Expand postgres-sakila-db tree node.

  3. Right-click the postgres-sakila-insert-data.sql and select Run postgres-sakila-insert-data.sql. Alternatively, click the postgres-sakila-insert-data.sql file and press Ctrl+Shift+F10.

  4. In the Execution Target dialog, select PostgreSQL and click OK.

Load sample data to the database

Step 9. Write your code

As you work in the editor, DataGrip analyzes your code, searches for ways to optimize it, and detects potential and actual problems. The following list includes basic features and tools that might be useful for your code writing and increase your productivity:

Code completion

Suggestions for code completion appear as you type your code. DataGrip has two types of code completion:

Basic code completion Ctrl+Space helps you complete names of types, interfaces, methods, and keywords within the visibility scope. When you invoke code completion, DataGrip analyzes the context and suggests the choices that are reachable from the current caret position. By default, DataGrip displays the code completion popup automatically as you type.

Smart code completion Ctrl+Shift+Space filters the suggestions list and shows only the types applicable to the current context.

The following animation shows the difference between basic and smart completion. Notice the number of variants that are suggested for different completion types

Generating code

DataGrip provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity. These can be either predefined or custom templates that are applied differently based on the context, various wrappers, and automatic pairing of characters.

From the main menu, select Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.

You can generate functions, procedures, views, and other database objects.

  • To generate an object, press Alt+Insert and select the object that you want to generate.

Live templates

Use live templates to insert common constructs into your code, such as statements or definitions of database objects.

To expand a code snippet, type the corresponding template abbreviation and press Tab. Keep pressing Tab to jump from one variable in the template to the next one. Press Shift+Tab to move to the previous variable.

To see the list of live templates, open settings Ctrl+Alt+S and navigate to Editor | Live templates.

Inspections

In DataGrip, there is a set of code inspections that detect and correct anomalous code in your project before you compile it. The IDE can find and highlight various problems, locate dead code, find probable bugs, spelling problems, and improve the overall code structure.

Inspections can scan your code in all project files, or only in specific scopes (for example, only in production code, or in modified files).

Every inspection has a severity level — the extent to which a problem can affect your code. Severities are highlighted differently in the editor so that you can quickly distinguish between critical problems and less important things. DataGrip comes with a set of predefined severity levels and enables you to create your own.

To see the list of inspections, open settings Ctrl+Alt+S and navigate to Editor | Inspections. Disable some of them, or enable others, plus adjust the severity of each inspection. You decide whether it should be considered an error or just a warning.

For example, the Unused subquery item inspection detects an unused item in the subquery (for example, a field).

Unused subquery item

Intention actions

As you work in the editor, DataGrip analyzes your code, searches for ways to optimize it, and detects potential and actual problems.

As soon as the IDE finds a way to alter your code, it displays a yellow bulb icon yellow bulb icon in the editor next to the current line. By clicking this icon, you can view intention actions available in the current context. Intention actions cover a wide range of situations from warnings to optimization suggestions. You can view the full list of intentions and customize them in the Settings/Preferences dialog Ctrl+Alt+S.

To see the list of intention actions, open settings Ctrl+Alt+S and navigate to Editor | Intentions.

  1. Click the light bulb icon (or press Alt+Enter) to open the list of suggestions.

  2. Select an action from the list and press Enter.

    For example, you can use an intention action in the INSERT statement to create a table with valid field types:

Last modified: 13 April 2020