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.
On the first page, select the color scheme for DataGrip, which can be either light or dark.
-
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 ( ). You can attach any directory later.
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.
Open settings Ctrl+Alt+S and navigate to Plugins.
Click Marketplace.
In the search field, type
Git
, and press Enter.To install the plugin, click Install and restart DataGrip.
Install the Docker plugin by JetBrains
To Docker support in DataGrip, install the Docker plugin by JetBrains.
Open settings Ctrl+Alt+S and navigate to Plugins.
Click Marketplace.
In the search field, type
Docker
, and press Enter.To install the plugin, click Install and restart DataGrip.
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
Click VCS | Enable Version Control Integration.
In the Enable Version Control Integration dialog, ensure that
Git
is selected in the drop-down list and click OK.
Clone repositories
Click
.-
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
In the Directory field, click the folder icon () and specify a directory for the repository files.
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.
Enable Docker support
-
Install and run Docker.
For more information, see the Docker documentation.
-
Configure the Docker daemon connection settings.
-
Connect to the Docker daemon.
The configured Docker connection should appear in the Services tool window ( or Alt+8). Select the Docker node , and click , or select Connect from the context menu.
To edit the Docker connection settings, select the Docker node and click on the toolbar, or select Edit Configuration from the context menu.
Create the Docker-compose deployment configuration
In the Services tool window ( ), right-click the Docker node and select Deploy.
In the pop-up window, select Create Docker-compose Deployment.
In the Create Deployment Configuration dialog, click the Browse icon of the Compose file(s) field.
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
In the Docker Compose Configuration Files dialog, click OK.
In the Service(s) field, type
pg_12.X
.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
Navigate to
Ctrl+Alt+S.In the Data Sources and Drivers dialog, click the Add icon () and select PostgreSQL.
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.
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.
(Optional) In the Name field, delete the current name and type a new name for the connection (for example, PostgreSQL).
To ensure that the connection to the data source is successful, click Test Connection.
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.
Navigate to
.In the Files tool window, right-click any area and select Attach directory.
Navigate to the directory that you want to attach. In our case, it the dumps directory.
Click OK.
Step 8. Run the dump files
Create the database structure
In the Files (postgres-sakila-db tree node.
) tool window, navigate to theExpand postgres-sakila-db tree node.
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.
In the Execution Target dialog, select PostgreSQL and click OK.
Load sample data to the database
In the Files (postgres-sakila-db tree node.
) tool window, navigate to theExpand postgres-sakila-db tree node.
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.
In the Execution Target dialog, select PostgreSQL and click OK.
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.
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
.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
. 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).
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 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
.Click the light bulb icon (or press Alt+Enter) to open the list of suggestions.
-
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: