@@ -52,42 +52,67 @@ $ sql-language-server up --method stdio
5252
5353### Connect to database
5454
55- #### Create .sqllsrc.json on your project root
55+ #### Using Configuration Files
56+
57+ There are two ways to use configuration files.
58+
59+ - Set personal configuration file(~ /.config/sql-language-server/sqllsrc.json)
60+ - Set project configuration file on your project root(\$ {YOUR_PROJECT/.sqllsrc.json})
61+
62+ #### Example for personal configuration file
5663
5764- Examples
5865
5966``` json
6067{
61- "adapter" : " mysql" ,
62- "host" : " localhost" ,
63- "port" : 3307 ,
64- "user" : " username" ,
65- "password" : " password" ,
66- "database" : " mysql-development" ,
67- "ssh" : {
68- "user" : " ubuntu" ,
69- "remoteHost" : " ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com" ,
70- "dbHost" : " 127.0.0.1" ,
71- "port" : 3306 ,
72- "identityFile" : " ~/.ssh/id_rsa" ,
73- "passphrase" : " 123456"
74- }
68+ "connections" : [
69+ {
70+ "name" : " sql-language-server" ,
71+ "adapter" : " mysql" ,
72+ "host" : " localhost" ,
73+ "port" : 3307 ,
74+ "user" : " username" ,
75+ "password" : " password" ,
76+ "database" : " mysql-development" ,
77+ "projectPaths" : [" /Users/joe-re/src/sql-language-server" ],
78+ "ssh" : {
79+ "user" : " ubuntu" ,
80+ "remoteHost" : " ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com" ,
81+ "dbHost" : " 127.0.0.1" ,
82+ "port" : 3306 ,
83+ "identityFile" : " ~/.ssh/id_rsa" ,
84+ "passphrase" : " 123456"
85+ }
86+ },
87+ {
88+ "name" : " postgres-project" ,
89+ "adapter" : " prostgres" ,
90+ "host" : " localhost" ,
91+ "port" : 5432 ,
92+ "user" : " postgres" ,
93+ "password" : " pg_pass" ,
94+ "database" : " pg_test" ,
95+ "projectPaths" : [" /Users/joe-re/src/postgres_ptoject" ]
96+ }
97+ ]
7598}
7699```
77100
78101Please restart sql-language-server process after create .sqlrc.json.
79102
80103#### Parameters
81104
82- | Key | Description | value | required | default |
83- | -------- | --------------------------- | ----------------------- | -------- | --------------------------------- |
84- | adapter | Database type | `"mysql" | "postgres"` | true | |
85- | host | Database host | string | true | |
86- | port | Database port | string | false | mysql:3306, postgres:5432 |
87- | user | Database user | string | true | mysql:"root", postgres:"postgres" |
88- | password | Database password | string | false | |
89- | database | Database name | string | false | |
90- | ssh | Settings for port fowarding | \* see below SSH section | false | |
105+ | Key | Description | value | required | default |
106+ | ------------ | ------------------------------------------------------------------------------------------------------------------------- | ----------------------- | -------- | --------------------------------- |
107+ | name | Connection name(free-form text) | | true | |
108+ | adapter | Database type | "mysql" #124 ; "postgres" | true | |
109+ | host | Database host | string | true | |
110+ | port | Database port | string | false | mysql:3306, postgres:5432 |
111+ | user | Database user | string | true | mysql:"root", postgres:"postgres" |
112+ | password | Database password | string | false | |
113+ | database | Database name | string | false | |
114+ | 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 | [ ] |
115+ | ssh | Settings for port fowarding | \* see below SSH section | false | |
91116
92117##### SSH
93118
@@ -101,10 +126,79 @@ Please restart sql-language-server process after create .sqlrc.json.
101126| identitiFile | Identity file for ssh | string | false | ~ /.ssh/config/id_rsa |
102127| passphrase | Passphrase to allow to use identity file | string | false | |
103128
129+ #### Personal confuguration file
130+
131+ Personal configuration file is located on ` ~/.config/sql-language-server/.sqllsrc.json ` .
132+ sql-language-server will try to read when it's started.
133+
134+ #### Project confuguration file
135+
136+ Project configuration file is located on ` ${YOUR_PROJECT_ROOT}/.sqllsrc.json ` .
137+
138+ All setting items are similarly to personal configuration file, with some exceptions:
139+
140+ - Specify under ` connection ` property element directly(you don't need to set array)
141+ - You don't need to set project path.(if you set it it will be ignored)
142+ - It's merged to personal configuration if you have it.
143+
144+ Example:
145+ ``` json
146+ {
147+ "name" : " postgres-project" ,
148+ "adapter" : " prostgres" ,
149+ "host" : " localhost" ,
150+ "port" : 5432 ,
151+ "user" : " postgres" ,
152+ "database" : " pg_test"
153+ }
154+ ```
155+
156+ And also if you have set personal configuration and both of them's names are matched, it's merged automatically.
157+
158+ Personal configuration example:
159+ ``` json
160+ {
161+ connections: [{
162+ "name" : " postgres-project" ,
163+ "password" : " password" ,
164+ "ssh" : {
165+ "user" : " ubuntu" ,
166+ "remoteHost" : " ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com" ,
167+ "dbHost" : " 127.0.0.1" ,
168+ "port" : 5432 ,
169+ "identityFile" : " ~/.ssh/id_rsa" ,
170+ "passphrase" : " 123456"
171+ }
172+ }]
173+ }
174+ ```
175+
176+ It will merge them as following:
177+
178+ ``` json
179+ {
180+ "name" : " postgres-project" ,
181+ "adapter" : " prostgres" ,
182+ "host" : " localhost" ,
183+ "port" : 5432 ,
184+ "user" : " postgres" ,
185+ "database" : " pg_test" ,
186+ "password" : " password" ,
187+ "ssh" : {
188+ "user" : " ubuntu" ,
189+ "remoteHost" : " ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com" ,
190+ "dbHost" : " 127.0.0.1" ,
191+ "port" : 5432 ,
192+ "identityFile" : " ~/.ssh/id_rsa" ,
193+ "passphrase" : " 123456"
194+ }
195+ }
196+ ```
197+
104198#### Inject envitonment variables
105199
106- ${ssm : VARIABLE_NAME } syntax allows you to replace configuration value with environt variable.
107- This is useful when you don't write actual file on configuration file.
200+ ${env : VARIABLE_NAME } syntax allows you to replace configuration value with enviroment variable.
201+ This is useful when you don't write actual value on configuration file.
108202
109203##### example
110204
@@ -127,6 +221,22 @@ This is useful when you don't write actual file on configuration file.
127221}
128222```
129223
224+ #### Switch database connection
225+
226+ If you have multiple connection information on personal config file, you can swtich database connection.
227+
228+ ![ 2020-05-25_15-23-01] ( https://user-images.githubusercontent.com/4954534/82788937-02f63c80-9e9c-11ea-948d-e27ee0090463.gif )
229+
230+
231+ [ VSC extension] ( https://marketplace.visualstudio.com/items?itemName=joe-re.sql-language-server ) provides ` Switch database connection ` command.
232+
233+ Raw RPC param is:
234+ ```
235+ method: workspace/executeCommand
236+ command: switchDataBaseConnection
237+ arguments: string(project name)
238+ ```
239+
130240### TODO
131241
132242- [x] SELECT
0 commit comments