JetBrains Rider 2022.2 Help

SQL Resolution Scopes

By using SQL resolution scopes, you can associate a folder or a file with a specific data source. When you set this mapping, you can use code assistance that corresponds to the associated data source.

When SQL resolution scopes are set, the IDE suggests database objects that are suitable for the associated data source. Consider that you have two data sources, one for your production database (PostgreSQL 14) and the other one for your test database (PostgreSQL 12.8). Tables in both databases have the same names, but databases have different structures. You can associate SQL files with either database separately.

Let's map postgresql_12.sql to the PostgreSQL 12.8 data source and postgresql_14.sql to PostgreSQL 14.

SQL Resolution Scopes

Both data sources have the actor table, but this table is stored in different schemas (guest.public.actor and postgres.public.actor). So, if we try to qualify the actor table or use code completion, completion suggestions will be associated with a corresponding data source.

suggestions in the completion list

And, if we exchange queries between these files, we will get errors (lines 14-15). Because we do not have tables under guest.public in PostgreSQL 14, and there is no postgres schema in PostgreSQL 12.8.

Add an SQL resolution scope

  1. Press Ctrl+Alt+S to open the IDE settings and select Languages & Frameworks | SQL Resolution Scopes.

  2. Click the Add button.

  3. In a file browser, navigate to a file or a directory that you want to associate with a data source.

  4. Click Open.

  5. Click the cell of the Resolution Scope column and select a data source that you want to associate with this directory or file.

    To use SQL code assistance in your project code, enable language injections.

Settings

Item

Description

Project mapping

A set of data sources, databases, and schemas used by default by all the SQL files in your project to resolve unqualified names of database objects.

If no mappings are set in the table below, files and directories use the project mapping.

Path

Path to a file or a directory that you want to associate with a data source or a set of data sources.

Resolution Scope

A data source or a set of data sources that will be associated with a file or a directory.

If you add a mapping for a directory with files that are already associated with a data source, the IDE displays a notification dialog. In this dialog, you must select whether children should inherit the parent's scope or preserve their scope.

db_inherit_a_scope_of_a_parent
Last modified: 01 April 2022