{"id":13626082,"url":"https://github.com/joe-re/sql-language-server","last_synced_at":"2025-05-15T16:09:42.852Z","repository":{"id":38885770,"uuid":"131777261","full_name":"joe-re/sql-language-server","owner":"joe-re","description":"SQL Language Server","archived":false,"fork":false,"pushed_at":"2024-01-09T17:41:09.000Z","size":30757,"stargazers_count":645,"open_issues_count":60,"forks_count":60,"subscribers_count":10,"default_branch":"release","last_synced_at":"2024-04-29T02:52:15.322Z","etag":null,"topics":["language-server-protocol","lint","sql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joe-re.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-05-02T00:26:25.000Z","updated_at":"2024-04-26T17:26:44.000Z","dependencies_parsed_at":"2024-04-14T08:58:49.713Z","dependency_job_id":null,"html_url":"https://github.com/joe-re/sql-language-server","commit_stats":{"total_commits":241,"total_committers":12,"mean_commits":"20.083333333333332","dds":"0.15352697095435686","last_synced_commit":"44aade3314c9060d57b45f41026973b2d81182b6"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joe-re%2Fsql-language-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joe-re%2Fsql-language-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joe-re%2Fsql-language-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joe-re%2Fsql-language-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joe-re","download_url":"https://codeload.github.com/joe-re/sql-language-server/tar.gz/refs/heads/release","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730069,"owners_count":20986404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language-server-protocol","lint","sql"],"created_at":"2024-08-01T21:02:09.470Z","updated_at":"2025-04-07T21:15:21.451Z","avatar_url":"https://github.com/joe-re.png","language":"TypeScript","readme":"# SQL Language Server\n\n[![build-and-test](https://github.com/joe-re/sql-language-server/actions/workflows/test.yaml/badge.svg)](https://github.com/joe-re/sql-language-server/actions/workflows/test.yaml)\n\nThe SQL Language Server offers autocompletion, error/warning notifications, and other editor support. It includes a linting feature, an SQL parser, and a Visual Studio Code extension. It supports MySQL, PostgreSQL, and SQLite3 databases.\n\n![completion](https://user-images.githubusercontent.com/4954534/47268897-36b70500-d589-11e8-98b2-65cffdcd60b8.gif)\n\n## Packages\n\n- **sql-language-server**: Autocompletion and notification of warnings and errors [GitHub link](https://github.com/joe-re/sql-language-server/tree/release/packages/server)\n- **sqlint**: Linting [GitHub link](https://github.com/joe-re/sql-language-server/tree/release/packages/sqlint)\n- **VSC extension**: [Github link](https://github.com/joe-re/sql-language-server/tree/release/packages/client)\n- **SQL parser**: [Github link](https://github.com/joe-re/sql-language-server/tree/release/packages/sql-parser)\n\n### Supported DB\n- MySQL\n- PostgreSQL\n- SQLite3\n\n## Installation \u0026 How to setup\n\n### Visual Studio Code\n\nInstall the [VSC extension](https://marketplace.visualstudio.com/items?itemName=joe-re.sql-language-server).\n\n### Other Editors\n\n```\nnpm i -g sql-language-server\n```\n\n#### Neovim\n\n##### [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)\n\nAdd the following to the `init.vim` file (`.vimrc`):\n\n```vim\nlet g:LanguageClient_serverCommands = {\n    \\ 'sql': ['sql-language-server', 'up', '--method', 'stdio'],\n    \\ }\n```\n\n##### [nvim-lsp](https://github.com/neovim/nvim-lspconfig#sqlls)\n\nRun the following command and reference the [nvim-lsp documentation](https://github.com/neovim/nvim-lspconfig#sqlls) for more information.\n\n```vim\n:LspInstall sqlls\n```\n\n#### Monaco Editor ([monaco-languageclient](https://github.com/TypeFox/monaco-languageclient))\n\nSee the [example](https://github.com/joe-re/sql-language-server/blob/master/example/monaco_editor) to use the Monaco Editor to develop sql-language-server.\n\nFollow the [development section](#development) section to check Mocaco Editor working.\n\n## Usage\n\n### CLI\n\n```\n$ sql-language-server up [options]        run sql-language-server\n```\n\n#### Options\n\n```\n  --version      Show version number                                   [boolean]\n  --help         Show help                                             [boolean]\n  --method, -m  What use to communicate with sql language server\n                   [string] [choices: \"stdio\", \"node-ipc\"] [default: \"node-ipc\"]\n  --debug, -d    Enable debug logging                 [boolean] [default: false]\n```\n\n- Example\n\n```\n$ sql-language-server up --method stdio\n```\n\n### Configuration\n\nThere are two ways to use configuration files.\n\n- Set personal configuration file (`~/.config/sql-language-server/.sqllsrc.json`)\n- Set project configuration file on your project root (`${YOUR_PROJECT}/.sqllsrc.json`)\n- Use workspace/configuration according to LSP specification\n\n#### Example for personal configuration file\n\n- Examples\n\n```json\n{\n  \"connections\": [\n    {\n      \"name\": \"sql-language-server\",\n      \"adapter\": \"mysql\",\n      \"host\": \"localhost\",\n      \"port\": 3307,\n      \"user\": \"username\",\n      \"password\": \"password\",\n      \"database\": \"mysql-development\",\n      \"projectPaths\": [\"/Users/joe-re/src/sql-language-server\"],\n      \"ssh\": {\n        \"user\": \"ubuntu\",\n        \"remoteHost\": \"ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n        \"dbHost\": \"127.0.0.1\",\n        \"port\": 3306,\n        \"identityFile\": \"~/.ssh/id_rsa\",\n        \"passphrase\": \"123456\"\n      }\n    },\n    {\n      \"name\": \"postgres-project\",\n      \"adapter\": \"postgres\",\n      \"host\": \"localhost\",\n      \"port\": 5432,\n      \"user\": \"postgres\",\n      \"password\": \"pg_pass\",\n      \"database\": \"pg_test\",\n      \"projectPaths\": [\"/Users/joe-re/src/postgres_project\"]\n    },\n    {\n      \"name\": \"sqlite3-project\",\n      \"adapter\": \"sqlite3\",\n      \"filename\": \"/Users/joe-re/src/sql-language-server/packages/server/test.sqlite3\",\n      \"projectPaths\": [\"/Users/joe-re/src/sqlite2_project\"]\n    }\n  ]\n}\n```\n\nPlease restart sql-language-server process after creating `.sqllsrc.json`.\n\n#### Connection parameters\n\n| Key          | Description                                                                                                               | value                   | required | default                           |\n| ------------ | ------------------------------------------------------------------------------------------------------------------------- | ----------------------- | -------- | --------------------------------- |\n| name         | Connection name(free-form text)                                                                                           |                         | true     |                                   |\n| adapter      | Database type                                                                                                             | \"mysql\" or \"postgres\" or \"sqlite3\" or \"bigquery\"  | true     |                                   |\n| host         | Database host                                                                                                             | string                  | false    |                                   |\n| port         | Database port                                                                                                             | string                  | false    | mysql:3306, postgres:5432         |\n| user         | Database user                                                                                                             | string                  | false    | mysql:\"root\", postgres:\"postgres\" |\n| password     | Database password                                                                                                         | string                  | false    |                                   |\n| database     | Database name                                                                                                             | string                  | false    |                                   |\n| filename     | Database filename(only for sqlite3)                                                                                       | string                  | false    |                                   |\n| projectPaths | Project path that you want to apply(if you don't set it configuration will not apply automatically when lsp's started up) | string[]                | false    | []                                |\n| ssh          | Settings for port fowarding                                                                                               | \\*see below SSH section | false    |                                   |\n\n##### SSH\n\n| Key          | Description                              | value  | required | default                   |\n| ------------ | ---------------------------------------- | ------ | -------- | ------------------------- |\n| remoteHost   | The host address you want to connect to  | string | true     |                           |\n| remotePort   | Port number of the server for ssh        | number | false    | 22                        |\n| user         | User name on the server                  | string | false    |                           |\n| dbHost       | Database host on the server              | string | false    | 127.0.0.1                 |\n| dbPort       | Database port on the server               | number | false    | mysql:3306, postgres:5432 |\n| identityFile | Identity file for ssh                    | string | false    | ~/.ssh/config/id_rsa      |\n| passphrase   | Passphrase to allow to use identity file | string | false    |                           |\n\n#### Personal configuration file\n\nThe personal configuration file is located at `~/.config/sql-language-server/.sqllsrc.json`. When the SQL Language Server starts, it will try to read this file.\n\n#### Project configuration file\n\nThe project configuration file is located at `${YOUR_PROJECT_ROOT}/.sqllsrc.json`. This file has the same settings as the personal configuration file, with a few exceptions:\n\n- The connection property is specified directly, rather than as an array.\n- The project path does not need to be set. If it is set, it will be ignored.\n- The project configuration file is merged with the personal configuration file, if it exists.\n\nHere is an example project configuration file for a PostgreSQL database:\n```json\n{\n  \"name\": \"postgres-project\",\n  \"adapter\": \"postgres\",\n  \"host\": \"localhost\",\n  \"port\": 5432,\n  \"user\": \"postgres\",\n  \"database\": \"pg_test\"\n}\n```\n\nIf you have also set a personal configuration, the project configuration and personal configure will be merged if they have the same name.\n\nPersonal configuration example:\n```json\n{\n  \"connections\": [{\n    \"name\": \"postgres-project\",\n    \"password\": \"password\",\n    \"ssh\": {\n      \"user\": \"ubuntu\",\n      \"remoteHost\": \"ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n      \"dbHost\": \"127.0.0.1\",\n      \"port\": 5432,\n      \"identityFile\": \"~/.ssh/id_rsa\",\n      \"passphrase\": \"123456\"\n    }\n  }]\n}\n```\n\nIt will merge them as follows:\n\n```json\n{\n  \"name\": \"postgres-project\",\n  \"adapter\": \"postgres\",\n  \"host\": \"localhost\",\n  \"port\": 5432,\n  \"user\": \"postgres\",\n  \"database\": \"pg_test\",\n  \"password\": \"password\",\n  \"ssh\": {\n    \"user\": \"ubuntu\",\n    \"remoteHost\": \"ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n    \"dbHost\": \"127.0.0.1\",\n    \"port\": 5432,\n    \"identityFile\": \"~/.ssh/id_rsa\",\n    \"passphrase\": \"123456\"\n  }\n}\n```\n\n#### Workspace configuration for sql-language-server\n\n##### Parameters of workspace configuration\n\n- `connections`: This parameter is the same as the connections parameter in the personal configuration file. It allows you to specify the connections for your workspace.\n- `lint`: This parameter is the same as the configuration of [sqlint](https://github.com/joe-re/sql-language-server/tree/release/packages/sqlint#configuration). It allows you to configure the linting rules for your workspace.\n\n\n##### Example of workspace configuration\n\n- [coc.nvim](https://github.com/neoclide/coc.nvim)\n\n~/.config/nvim/coc-settings.json\n```json\n{\n  \"languageserver\": {\n    \"sql\": {\n      \"command\": \"sql-language-server\",\n      \"args\": [\"up\", \"--method\", \"stdio\"],\n      \"filetypes\": [\"sql\"],\n      \"settings\": {\n        \"sqlLanguageServer\": {\n          \"connections\": [\n            {\n              \"name\": \"mysql_project\",\n              \"adapter\": \"mysql\",\n              \"host\": \"127.0.0.1\",\n              \"port\": 3306,\n              \"user\": \"sqlls\",\n              \"password\": \"sqlls\",\n              \"database\": \"mysql_db\",\n              \"projectPaths\": [\"/Users/joe_re/src/MysqlProject\"],\n              \"ssh\": {\n                \"user\": \"ubuntu\",\n                \"remoteHost\": \"xxx-xx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n                \"dbHost\": \"127.0.0.1\",\n                \"port\": 3306\n              }\n            }\n          ],\n          \"lint\": {\n            \"rules\": {\n              \"align-column-to-the-first\": \"error\",\n              \"column-new-line\": \"error\",\n              \"linebreak-after-clause-keyword\": \"off\",\n              \"reserved-word-case\": [\"error\", \"upper\"],\n              \"space-surrounding-operators\": \"error\",\n              \"where-clause-new-line\": \"error\",\n              \"align-where-clause-to-the-first\": \"error\"\n            }\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n- VS Code workspace setting\n\n```json\n\"settings\": {\n  \"sqlLanguageServer.connections\": [\n    {\n      \"name\": \"mysql_project\",\n      \"adapter\": \"mysql\",\n      \"host\": \"127.0.0.1\",\n      \"port\": 3306,\n      \"user\": \"sqlls\",\n      \"password\": \"sqlls\",\n      \"database\": \"mysql_db\",\n      \"projectPaths\": [\"/Users/joe_re/src/MysqlProject\"],\n      \"ssh\": {\n        \"user\": \"ubuntu\",\n        \"remoteHost\": \"xxx-xx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n        \"dbHost\": \"127.0.0.1\",\n        \"port\": 3306\n      }\n    }\n  ],\n  \"sqlLanguageServer.lint\": {\n    \"rules\": {\n      \"align-column-to-the-first\": \"off\",\n      \"column-new-line\": \"error\",\n      \"linebreak-after-clause-keyword\": \"error\",\n      \"reserved-word-case\": [\"error\", \"upper\"],\n      \"space-surrounding-operators\": \"error\",\n      \"where-clause-new-line\": \"error\",\n      \"align-where-clause-to-the-first\": \"error\",\n    }\n  }\n}\n```\n\n\n#### Inject environment variables\n\n`${env:VARIABLE_NAME}` syntax allows you to replace configuration value with an environment variable.\nThis is useful if you don't want to store the value in the configuration file.\n\n##### Example\n\n```json\n{\n  \"adapter\": \"mysql\",\n  \"host\": \"localhost\",\n  \"port\": 3307,\n  \"user\": \"username\",\n  \"password\": \"${env:DB_PASSWORD}\",\n  \"database\": \"mysql-development\",\n  \"ssh\": {\n    \"user\": \"ubuntu\",\n    \"remoteHost\": \"ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com\",\n    \"dbHost\": \"127.0.0.1\",\n    \"port\": 3306,\n    \"identityFile\": \"~/.ssh/id_rsa\",\n    \"passphrase\": \"${env:SSH_PASSPHRASE}\"\n  }\n}\n```\n\n#### Switch database connection\n\nIf you have multiple connection entries in your personal config file, you can switch the database connection.\n\n![2020-05-25_15-23-01](https://user-images.githubusercontent.com/4954534/82788937-02f63c80-9e9c-11ea-948d-e27ee0090463.gif)\n\n\n[VSC extension](https://marketplace.visualstudio.com/items?itemName=joe-re.sql-language-server) provides `Switch database connection` command.\n\nRaw RPC param:\n```\nmethod: workspace/executeCommand\ncommand: switchDataBaseConnection\narguments: string(project name)\n```\n\n\n#### SQLite3 Notes\n\nIf you get error when you use sqlite3 connection, you may need to rebuild sqlite3 to your environment.\n\nVSC extension provides the command to rebuild it.(Name: `Rebuild SQLite3 Client`)\n![image](https://user-images.githubusercontent.com/4954534/85928359-ef952180-b8de-11ea-8cb3-7a9a509cd6d7.png)\n\nIf you're using sql-language-server directly, go to the install directory and run `npm rebuild sqlite` to rebuild it.\n\n\n#### Linting\n\nYou can use lint rules provided by [sqlint](https://github.com/joe-re/sql-language-server/tree/release/packages/sqlint) to ensure your SQL code follows best practices and avoid potential errors. Refer to the [sqlint configuraton documentation](https://github.com/joe-re/sql-language-server/tree/release/packages/sqlint#configuration) to learn how to use and configure the linter to match your use case.\n\n![sqlint-on-editor](https://user-images.githubusercontent.com/4954534/83353304-3c3f1880-a384-11ea-8266-4d7048461b56.png)\n\nYou can also use sqlint to automatically fix any problems it can identify in your code.\n\n![2020-06-18_08-24-03](https://user-images.githubusercontent.com/4954534/84964358-84a95500-b13e-11ea-9c4f-0b787306bbdf.gif)\n\nRaw RPC param:\n```\nmethod: workspace/executeCommand\ncommand: fixAllFixableProblems\narguments: string(document uri)\n```\n\n## Contributing to sql-language-server\n\n### Bug Reports and Feature Requests\n\nIf you have any questions, problems or suggestions for improvements, feel free to create a new issue on [GitHub Issues](https://github.com/joe-re/sql-language-server/issues). You can also start a discussion there about new rules for SQLint.\n\n### Development\n\nCode contributions are always appreciated, so feel free to fork the repo and submit pull requests.\n\n#### Development environment\n\nYou can start developing sql-language-server using Docker Compose. To begin the development process in your Docker container, run the following command:\n\n```sh\n$ docker compose up\n```\n\nOpen `http://localhost:3000` on your browser.\n\n#### Migrating the Database\n\nTo migrate the database, follow these steps:\n\n1. Login into development Docker container\n\n```sh\n$ docker compose exec assets bash\n```\n\n2. Migrate the database\n\n```sh\n$ cd example/monaco_editor\n$ yarn migrate:postgres # postgres\n$ yarn migrate:mysql    # mysql\n$ yarn migrate:sqlite   # sqlite3\n```\n","funding_links":[],"categories":["TypeScript","SQL"],"sub_categories":["Language Server Protocol"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoe-re%2Fsql-language-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoe-re%2Fsql-language-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoe-re%2Fsql-language-server/lists"}