mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.45k stars 292 forks source link

Support for Interpolated Variables from Connections Config #1064

Closed lucasvieirasilva closed 1 year ago

lucasvieirasilva commented 1 year ago

This PR adds support for interpolated variables from the connection config.

Example:

{
  "sqltools.queryParams.enableReplace": true,
  "sqltools.connections": [
    {
      "name": "SQLite",
      "driver": "SQLite",
      "database": "./docker/sqlite/test_db.db",
      "connectionTimeout": 15,
      "variables": {
        "env": "dev"
      }
    }
  ]
}

Query:

SELECT * FROM table_$[env];

You can also use Jinja format by adding the sqltools.queryParams.regex property with this value \\{\\{(.*)\\}\\}

Query:

SELECT * FROM table_{{ env }};

Benefits

Using pre-defined variables from the connection config to avoid prompting the variable value every time the user runs the query.

Related Issues


Thank you for your contribution! Before submitting this PR, please make sure:

lucasvieirasilva commented 1 year ago

Thanks for this contribution. I have suggested a minor change to a description in two places. Then I think it will be ready to merge.

@gjsjohnmurray Thanks for the review, I've applied your suggestions