|
| 1 | +# Configuration |
| 2 | + |
| 3 | +This guide will help you to understand how to configure the Postgres Language Server. It explains the structure of the configuration file and how the configuration is resolved. |
| 4 | + |
| 5 | +The Postgres Language Server allows you to customize its behavior using CLI options or a configuration file named `postgrestools.jsonc`. We recommend that you create a configuration file for each project. This ensures that each team member has the same configuration in the CLI and in any editor that allows Biome integration. Many of the options available in a configuration file are also available in the CLI. |
| 6 | + |
| 7 | +## Configuration file structure |
| 8 | + |
| 9 | +A configuration file is usually placed in your project’s root folder. It is organized around the tools that are provided. All tools are enabled by default, but some require additional setup like a database connection or the `plpgsql_check` extension. |
| 10 | + |
| 11 | +```json |
| 12 | +{ |
| 13 | + "$schema": "https://pgtools.dev/latest/schema.json", |
| 14 | + "linter": { |
| 15 | + "enabled": true, |
| 16 | + "rules": { |
| 17 | + "recommended": true |
| 18 | + } |
| 19 | + }, |
| 20 | + "typecheck": { |
| 21 | + "enabled": true |
| 22 | + } |
| 23 | + "plpgsqlCheck": { |
| 24 | + "enabled" : true |
| 25 | + } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Configuring a database connection |
| 30 | + |
| 31 | +Some tools that the Postgres Language Server provides are implemented as mere interfaces on top of functionality that is provided by the database itself. This ensures correctness, but requires an active connection to a Postgres database. We strongly recommend to only connect to a local development database. |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "$schema": "https://pgtools.dev/latest/schema.json", |
| 36 | + "db": { |
| 37 | + "host": "127.0.0.1", |
| 38 | + "port": 5432, |
| 39 | + "username": "postgres", |
| 40 | + "password": "postgres", |
| 41 | + "database": "postgres", |
| 42 | + "connTimeoutSecs": 10, |
| 43 | + "allowStatementExecutionsAgainst": ["127.0.0.1/*", "localhost/*"] |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +## Specifying files to process |
| 50 | + |
| 51 | +You can control the files/folders to process using different strategies, either CLI, configuration and VCS. |
| 52 | + |
| 53 | +### Include files via CLI |
| 54 | +The first way to control which files and folders are processed is to list them in the CLI. In the following command, we only check `file1.sql` and all the files in the `src` folder, because folders are recursively traversed. |
| 55 | + |
| 56 | +```shell |
| 57 | +postgrestools check file1.js src/ |
| 58 | +``` |
| 59 | + |
| 60 | +### Control files via configuration |
| 61 | + |
| 62 | +The configuration file can be used to refine which files are processed. You can explicitly list the files to be processed using the `files.includes` field. `files.includes` accepts glob patterns such as sql/**/*.sql. Negated patterns starting with `!` can be used to exclude files. |
| 63 | + |
| 64 | +Paths and globs inside the configuration file are resolved relative to the folder the configuration file is in. An exception to this is when a configuration file is extended by another. |
| 65 | + |
| 66 | +#### Include files via configuration |
| 67 | +Let’s take the following configuration, where we want to include only SQL files (`.sql`) that are inside the `sql/` folder: |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "files": { |
| 72 | + "includes": ["sql/**/*.sql"] |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +#### Exclude files via configuration |
| 78 | +If you want to exclude files and folders from being processed, you can use the `files.ignore` . |
| 79 | + |
| 80 | +In the following example, we include all files, except those in any test/ folder: |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "files": { |
| 85 | + "ignore": [ |
| 86 | + "**/test", |
| 87 | + ] |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +#### Control files via VCS |
| 93 | +You can ignore files ignored by your [VCS](/guides/vcs_integration.md). |
| 94 | + |
| 95 | + |
| 96 | + |
0 commit comments