https://github.com/hypnoce/sqls
SQL language server written in Go.
https://github.com/hypnoce/sqls
Last synced: 5 months ago
JSON representation
SQL language server written in Go.
- Host: GitHub
- URL: https://github.com/hypnoce/sqls
- Owner: hypnoce
- License: mit
- Fork: true (sqls-server/sqls)
- Created: 2021-02-26T08:53:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-26T11:06:55.000Z (over 5 years ago)
- Last Synced: 2024-06-20T12:01:56.055Z (almost 2 years ago)
- Language: Go
- Size: 1.63 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqls

An implementation of the Language Server Protocol for SQL.
## Note
This project is currently under development and there is no stable release. Therefore, destructive interface changes and configuration changes are expected.
## Features
sqls aims to provide advanced intelligence for you to edit sql in your own editor.
### Support RDBMS
- MySQL([Go-MySQL-Driver](https://github.com/go-sql-driver/mysql))
- PostgreSQL([pq](https://github.com/lib/pq))
- SQLite3([go-sqlite3](https://github.com/mattn/go-sqlite3))
### Language Server Features
#### Auto Completion

- DML(Data Manipulation Language)
- [x] SELECT
- [x] Sub Query
- [x] INSERT
- [x] UPDATE
- [x] DELETE
- DDL(Data Definition Language)
- [ ] CREATE TABLE
- [ ] ALTER TABLE
#### CodeAction

- [x] Execute SQL
- [ ] Explain SQL
- [x] Switch Connection(Selected Database Connection)
- [x] Switch Database
#### Hover

#### Signature Help

#### Document Formatting

## Installation
```
go get github.com/hypnoce/sqls
```
## Editor Plugins
- [sqls.vim](https://github.com/hypnoce/sqls.vim)
- [vscode-sqls](https://github.com/hypnoce/vscode-sqls)
- [sqls.nvim](https://github.com/nanotee/sqls.nvim)
## DB Configuration
The connection to the RDBMS is essential to take advantage of the functionality provided by `sqls`.
You need to set the connection to the RDBMS.
### Configuration Methods
There are the following methods for RDBMS connection settings, and they are prioritized in order from the top.
Whichever method you choose, the settings you make will remain the same.
1. Configuration file specified by the `-config` flag
1. `workspace/configuration` set to LSP client
1. Configuration file located in the following location
- `$XDG_CONFIG_HOME`/sqls/config.yml ("`$HOME`/.config" is used instead of `$XDG_CONFIG_HOME` if it's not set)
### Configuration file sample
```yaml
# Set to true to use lowercase keywords instead of uppercase.
lowercaseKeywords: false
connections:
- alias: dsn_mysql
driver: mysql
dataSourceName: root:root@tcp(127.0.0.1:13306)/world
- alias: individual_mysql
driver: mysql
proto: tcp
user: root
passwd: root
host: 127.0.0.1
port: 13306
dbName: world
params:
autocommit: "true"
tls: skip-verify
- alias: mysql_via_ssh
driver: mysql
proto: tcp
user: admin
passwd: Q+ACgv12ABx/
host: 192.168.121.163
port: 3306
dbName: world
sshConfig:
host: 192.168.121.168
port: 22
user: sshuser
passPhrase: ssspass
privateKey: /home/hypnoce/.ssh/id_rsa
```
### Workspace configuration Sample
* setting example with vim-lsp.
```vim
if executable('sqls')
augroup LspSqls
autocmd!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'sqls',
\ 'cmd': {server_info->['sqls']},
\ 'whitelist': ['sql'],
\ 'workspace_config': {
\ 'sqls': {
\ 'connections': [
\ {
\ 'driver': 'mysql',
\ 'dataSourceName': 'root:root@tcp(127.0.0.1:13306)/world',
\ },
\ {
\ 'driver': 'postgresql',
\ 'dataSourceName': 'host=127.0.0.1 port=15432 user=postgres password=mysecretpassword1234 dbname=dvdrental sslmode=disable',
\ },
\ ],
\ },
\ },
\ })
augroup END
endif
```
* setting example with coc.nvim.
In `coc-settings.json` opened by `:CocConfig`
```json
{
"languageserver": {
"sql": {
"command": "sqls",
"args": ["-config", "$HOME/.config/sqls/config.yml"],
"filetypes": ["sql"],
"shell": true
}
}
}
```
* setting example with [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#sqls).
```lua
require'lspconfig'.sqls.setup{
settings = {
sqls = {
connections = {
{
driver = 'mysql',
dataSourceName = 'root:root@tcp(127.0.0.1:13306)/world',
},
{
driver = 'postgresql',
dataSourceName = 'host=127.0.0.1 port=15432 user=postgres password=mysecretpassword1234 dbname=dvdrental sslmode=disable',
},
},
},
},
}
```
**I'm sorry. Please wait a little longer for other editor settings.**
### Configuration Params
The first setting in `connections` is the default connection.
| Key | Description |
|-------------|----------------------|
| connections | Database connections |
### connections
`dataSourceName` takes precedence over the value set in `proto`, `user`, `passwd`, `host`, `port`, `dbName`, `params`.
| Key | Description |
|----------------|---------------------------------------------|
| alias | Connection alias name. Optional. |
| driver | `mysql`, `postgresql`, `sqlite3`. Required. |
| dataSourceName | Data source name. |
| proto | `tcp`, `udp`, `unix`. |
| user | User name |
| passwd | Password |
| host | Host |
| port | Port |
| path | unix socket path |
| dbName | Database name |
| params | Option params. Optional. |
| sshConfig | ssh config. Optional. |
#### sshConfig
| Key | Description |
|------------|-----------------------------|
| host | ssh host. Required. |
| port | ssh port. Required. |
| user | ssh user. Optional. |
| privateKey | private key path. Required. |
| passPhrase | passPhrase. Optional. |
#### DSN (Data Source Name)
See also.
- https://github.com/go-sql-driver/mysql#dsn-data-source-name
- https://godoc.org/github.com/lib/pq
- https://github.com/mattn/go-sqlite3#connection-string
## Contributors
This project exists thanks to all the people who contribute.
## Inspired
I created sqls inspired by the following OSS.
- [dbcli Tools](https://github.com/dbcli)
- [mycli](https://www.mycli.net/)
- [pgcli](https://www.pgcli.com/)
- [litecli](https://litecli.com/)
- non-validating SQL parser
- [sqlparse](https://github.com/andialbrecht/sqlparse)