This quick start guide will introduce you to the key concepts and help you with your first steps in working with databases in GoLand.
Before you start
Enable the Database Tools and SQL plugin
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in GoLand by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
Step 1. Create a data source
Depending on a database vendor (MySQL, PostgreSQL, Oracle, and so on), you need to create a corresponding data source to use it to connect to the database.
Data source
Data source is a connection configuration. It stores a list of connection details that are used to establish connection to a database. For example, host, port, database name, driver, SSH and SSL configuration settings, and so on. In data source settings, you can also select databases and schemas for introspection and display in Database tool window, and change the driver for your connection.
Find more information about data sources in Data sources.
In this tutorial, you will set up a demo data source and connect to a demo database. To do this, you can either use the PostgreSQL or MySQL sample databases deployed remotely or download and use the SQLite sample database file.
You can also set up this demo data source using the connection credentials of a database you have setup and running somewhere else. To do this and connect to your database, enter the credentials or its JDBC URL in the corresponding fields of Data Source and Drivers dialog that is described in this tutorial.
PostgreSQL
MySQL
SQLite
In GoLand, go to Database tool window (View | Tool Windows | Database or ) .
Click the Create data source link.
Navigate to Data Source and select PostgreSQL.
GoLand will open a Data Source and Drivers dialog with the settings of your new data source.
In GoLand, go to Database tool window (View | Tool Windows | Database or ) .
Click the Create data source link.
Navigate to Data Source and select MySQL.
GoLand will open a Data Source and Drivers dialog with the settings of your new data source.
Prepare the SQLite sample database file by downloading from a GitHub repository, then copy the downloaded file to clipboard.
In GoLand, paste the SQLite database file to the IDE project root directory.
To do that, in the Project tool window (View | Tool Windows | Project or Alt01) , click any area and press Ctrl0V. In the Copy dialog that appears, click OK.
Go to Database tool window (View | Tool Windows | Database or ) .
Click the Create data source link.
Navigate to Data Source and select SQLite.
GoLand will open a Data Source and Drivers dialog with the settings of your new data source.
Then, set up your new data source with the connection settings of your database.
PostgreSQL
MySQL
SQLite
In the Name field of the dialog, enter your new data source's name. For example, Demo DB.
If there is a Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.
In the Host field, enter the following server address:
postgresql.datagrip-dbs.intellij.net
Make sure that the Port field contains the PostgreSQL default value: 5432.
In the User field, enter the demo user name: datagrip.
In the Password field, enter the password: datagrip.
In the Database field, enter the database name: datagrip.
To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.
In the Schemas tab, make sure that the datagrip database that you will work with is selected.
Click OK to create the data source.
Once the data source is created, it appears in the Database tool window.
In the Name field of the dialog, enter your new data source's name. For example, Demo DB.
If there is a Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.
In the Host field, enter the following server address:
mysql.datagrip-dbs.intellij.net
Make sure that the Port field contains the MySQL default value: 3306.
In the User field, enter the demo user name: datagrip.
In the Password field, enter the password: datagrip.
In the Database field, enter the database name: datagrip.
To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.
In the Schemas tab, make sure that the datagrip database that you will work with is selected.
Click OK to create the data source.
Once the data source is created, it appears in the Database tool window.
In the Name field of the dialog, enter your new data source's name. For example, Demo DB.
If there is a Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.
In the File field, enter the path to your database file in the project root: demo_db.sqlite.
ALternatively, click Open and navigate to the file.
To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.
In the Schemas tab, make sure that the main database that you will work with is selected.
Click OK to create the data source.
Once the data source is created, it appears in the Database tool window.
Step 2. Write and run SQL queries
With the Database Tools and SQL plugin, you can write SQL and NoSQL code in query consoles that are attached to data sources. When you create a new data source, the IDE creates a default query console for that data source.
Query console
Query consoles are SQL files in which you can compose and execute SQL statements. Unlike the usual SQL files, they are attached to your data source by default.
For more information about query consoles, refer to the Query consoles topic.
In this tutorial, we will run simple queries in the default query console that GoLand creates and opens upon the new data source creation.
PostgreSQL
MySQL
SQLite
tip
In case you have closed the default query console, open it. To do that, in the Database tool window, select your data source, click Jump to Query Console on the toolbar, then select Default Query Console.
In the default query console, enter the following SQL query:
SELECT*FROM actor;
To run the query, click Execute on the editor toolbar.
GoLand will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt08) for you to analyze.
At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because GoLand will use the default schema of the data source.
For more information about how to set a default schema, refer to the Schemas topic.
tip
In case you have closed the default query console, open it. To do that, in the Database tool window, select your data source, click Jump to Query Console on the toolbar, then select Default Query Console.
In the default query console, enter the following SQL query:
SELECT*FROM actor;
To run the query, click Execute on the editor toolbar.
GoLand will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt08) for you to analyze.
At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because GoLand will use the default schema of the data source.
For more information about how to set a default schema, refer to the Schemas topic.
tip
In case you have closed the default query console, open it. To do that, in the Database tool window, select your data source, click Jump to Query Console on the toolbar, then select Default Query Console.
In the default query console, enter the following SQL query:
SELECT*FROM actor;
To run the query, click Execute on the editor toolbar.
GoLand will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt08) for you to analyze.
At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because GoLand will use the default schema of the data source.
For more information about how to set a default schema, refer to the Schemas topic.
Step 3. Explore the database
Now you can explore your database and database objects in a tree view and also open the objects to view their data. With the Database Tools and SQL plugin, you can do this in Database tool window.
Database Explorer
Database tool window is a tool window that displays the database structure as a tree with nodes. You can create folders and move data sources to them, assign colors to data sources, filter the database objects, and so on.
For example, let us navigate to the actor table and its columns.
PostgreSQL
MySQL
SQLite
In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected databases.
Then, double-click the nodes or click the arrow icon near them to expand the list of items: datagrip | public | tables | actor | columns.
To view the actor table data, double-click its name.
GoLand will open the actor table in a data editor tab.
In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected schemas.
Then, double-click the nodes or click the arrow icon near them to expand the list of items: datagrip | tables | actor | columns.
To view the actor table data, double-click its name.
GoLand will open the actor table in a data editor tab.
In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected . schemas
Then, double-click the nodes or click the arrow icon near them to expand the list of items: main | tables | actor | columns.
To view the actor table data, double-click its name.
GoLand will open the actor table in a data editor tab.
Step 4. View, sort, and filter the data
With the Database Tools and SQL plugin, you can view and edit the data of database tables and views in the data editor and viewer.
Data editor and viewer
The data editor and viewer, or data editor, provides a user interface for working with data. In the data editor, you can sort, filter, add, edit, and remove the data as well as perform other associated tasks.
In this tutorial, we will sort the first_name column of actor table alphabetically and will also filter the last_name column to see the last names that start with JO.
PostgreSQL
MySQL
SQLite
To sort the data, in the data editor tab, click the arrows icon in the first_name column header. GoLand will send the ORDER BY query to the database and display its result in the editor.
For more information about sorting data on the database side and on the client side, refer to the Sort data topic.
To filter the data, in the data editor tab, click Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.
GoLand will filter the data and display the result.
For more information about filtering data in the IDE, refer to the Filter data topic.
To sort the data, in the data editor tab, click the arrows icon in the first_name column header. GoLand will send the ORDER BY query to the database and display its result in the editor.
For more information about sorting data on the database side and on the client side, refer to the Sort data topic.
To filter the data, in the data editor tab, click Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.
GoLand will filter the data and display the result.
For more information about filtering data in the IDE, refer to the Filter data topic.
To sort the data, in the data editor tab, click the arrows icon in the first_name column header. GoLand will send the ORDER BY query to the database and display its result in the editor.
For more information about sorting data on the database side and on the client side, refer to the Sort data topic.
To filter the data, in the data editor tab, click Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.
GoLand will filter the data and display the result.
For more information about filtering data in the IDE, refer to the Filter data topic.
Next steps
After going through this tutorial, you can create a connection configuration and connect to a database using its JDBC URL, explore the connected database, run SQL queries in query consoles, and view the query results. Also, you can view, sort, and filter database object data.
To learn more about the IDE, consider the following topics and sections: