Templates with multiple files
Some programming patterns and frameworks require a set of related files, usually with a very specific structure. For example, you can create separate SQL files: one that creates database structure, and the other one that inserts the data to the database.
In DataGrip, you can create sets of related files by adding child templates to a file template. When you create a file from such a template, it will also create files from child templates.
Create a template with multiple files
In the Settings dialog (Control+Alt+S), select .
Create the main file template.
On the Files tab, click and specify the name, file extension, and body of the template.
Select the new template in the list and click on the toolbar. Specify the name, file extension, and body of the child template.
Example: Template for a table
In the Settings dialog (Control+Alt+S), select .
Create the table structure template.
On the Files tab, click and specify the following:
Name:
Table
Extension:
sql
File name:
${NAME}
Add the following code to the template body:
CREATE TABLE ${NAME} ( id integer DEFAULT NOT NULL, first_name character varying(45) NOT NULL, last_name character varying(45) NOT NULL, last_update timestamp without time zone DEFAULT now() NOT NULL );The name of this table will match the name that you provide, for example:
actor
.Create the table data template.
Select the new Table template in the list and click in the toolbar. Specify the following:
File name:
${NAME}_data
Extension:
sql
Add the following code to the template body:
INSERT INTO ${NAME} (id,first_name,last_name,last_update) VALUES ('1','PENELOPE','GUINESS','2006-02-15 04:34:33.000'); INSERT INTO ${NAME} (id,first_name,last_name,last_update) VALUES ('2','NICK','WAHLBERG','2006-02-15 04:34:33.000'); INSERT INTO ${NAME} (id,first_name,last_name,last_update) VALUES ('3','ED','CHASE','2006-02-15 04:34:33.000');The name of this file will be a combination of the name that you provide and
_data
, for example:actor_data
.Click OK to apply the changes.
To use the new template, right-click a directory in the Files tool window or press Alt+Insert and select the Table template. Specify a name for the table and DataGrip will create both files.