SQL
Syntax highlighting and formatting support for SQL is built into the editor.
Formatting
SQL auto-formatting can be added to the editor using external tools like
sql-formatter.
- Install
sql-formatter:
npm install -g sql-formatter
- Ensure
sql-formatteris available in your path and check the version:
which sql-formatter
sql-formatter --version
- Configure Gram to automatically format SQL with
sql-formatter:
"languages": {
"SQL": {
"formatter": {
"external": {
"command": "sql-formatter",
"arguments": ["--language", "mysql"]
}
}
}
},
Substitute your preferred [SQL Dialect] for mysql above (duckdb, hive, mariadb, postgresql, redshift, snowflake, sqlite, spark, etc).
You can add this to Gram project settings (.gram/settings.json) or via your Gram user settings (~/.config/gram/settings.json).
Advanced Formatting
Sql-formatter also allows more precise control by providing sql-formatter configuration options. To provide these, create a .sql-formatter.json file in your project:
{
"language": "postgresql",
"tabWidth": 2,
"keywordCase": "upper",
"linesBetweenQueries": 2,
}
When using a .sql-formatter.json file you can use a more simplified set of Gram settings since the language need not be specified inline:
"languages": {
"SQL": {
"formatter": {
"external": {
"command": "sql-formatter"
}
}
}
},