Skip to content

Commit 50a3bfc

Browse files
authored
Find sql objects (#82)
Closes #28 - Recursively go through the object explorer and cache all objects - If we're on a system database, take steps to work around this edge case (eg the root node will be the server, so don't cache any other databases) - Lualine support - Refresh cache - Cancel cache refresh (eg when switching databases) - Keymaps, user commands, etc - Docs
1 parent 0cbcaa0 commit 50a3bfc

16 files changed

+799
-68
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ An SQL Server plugin for neovim. Like it? Give a ⭐️!
1212

1313
## Features
1414

15-
Completions, including TSQL keywords,
15+
Completions, including TSQL keywords, stored procedures and cross database
16+
queries
1617

1718
<img src="./docs/screenshots/Tsql_completion.png" alt="Tsql keywords screenshot" width="300"/>
18-
19-
stored procedures
20-
2119
<img src="./docs/screenshots/Stored_procedure_completion.png" alt="stored procedures screenshot" width="300"/>
22-
23-
and cross database queries
24-
2520
<img src="./docs/screenshots/Cross_db_completion.png" alt="Cross db completion" width="300"/>
2621

2722
Execute queries, with results in markdown tables for automatic colouring and
2823
rendering
2924

30-
![results screenshot](./docs/screenshots/Results.png)
25+
<img src="./docs/screenshots/Results.png" alt="results screenshot" width="400"/>
26+
27+
Find and generate scripts for tables, views, stored procedures and functions
28+
29+
<img src="./docs/screenshots/Find.png" alt="finder screenshot" width="400"/>
3130

3231
User commands and optional which-key integration, showing only the key
3332
maps/commands which are possible (eg don't show `Connect` if we are already
@@ -41,7 +40,7 @@ Lualine integration
4140

4241
<img src="./docs/screenshots/Lualine.png" alt="Which key screenshot" width="600"/>
4342

44-
Other cherries on top:
43+
🍒 Other cherries on top:
4544

4645
- Save query results to csv, json, Excel and xml
4746
- Backup to/restore from `.bak` files
@@ -219,20 +218,21 @@ You can call the following as key maps typing your
219218
[prefix](#installation-and-setup) first, as user commands by doing
220219
`:MSSQL <command>` or as functions on `require("mssql")`.
221220

222-
| Key Map | User Command | Function | Description |
223-
| ------- | --------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
224-
| `n` | `NewQuery` | `new_query()` | Open a new buffer for sql queries |
225-
| `c` | `Connect` | `connect()` | Connect the current buffer (you'll be prompted to choose a connection) |
226-
| `x` | `ExecuteQuery` | `execute_query()` | Execute the selection, or the whole buffer. If you are disconnected, it will try to connect to the `default` connection in your `connections.json`. |
227-
| `l` | `CancelQuery` | `cancel_query()` | Cancel the currently running query. |
228-
| `q` | `Disconnect` | `disconnect()` | Disconnects the current buffer |
229-
| `s` | `SwitchDatabase` | `switch_database()` | Prompts, then switches to a database that is on the currently connected server |
230-
| `d` | `NewDefaultQuery` | `new_default_query()` | Opens a new query and connects to the connection called `default` in your `connections.json`. Useful when combined with the `promptForDatabase` option in the `connections.json`. |
231-
| `s` | `SaveQueryResults` | `save_query_results()` | When in a query result buffer, save the query result by giving a file path with an extension of `.csv`, `.json`, `.xml`, `.xlsx` or `.xls` |
232-
| `r` | `RefreshIntellisense` | `refresh_intellisense_cache()` | Rebuild the intellisense cache |
233-
| `e` | `EditConnections` | `edit_connections()` | Open the [connections file](#connections-json-file) for editing |
234-
| | `BackupDatabase` | `backup_database()` | Inserts an SQL command to back up the currently connected database |
235-
| | `RestoreDatabase` | `restore_database()` | Prompts for a `.bak` file, then inserts an SQL command to restore the database from that file |
221+
| Key Map | User Command | Function | Description |
222+
| ------- | ------------------ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
223+
| `n` | `NewQuery` | `new_query()` | Open a new buffer for sql queries |
224+
| `c` | `Connect` | `connect()` | Connect the current buffer (you'll be prompted to choose a connection) |
225+
| `x` | `ExecuteQuery` | `execute_query()` | Execute the selection, or the whole buffer. If you are disconnected, it will try to connect to the `default` connection in your `connections.json`. |
226+
| `f` | `Find` | `find_object()` | Find a table/view/stored procedure/function and generate a script |
227+
| `l` | `CancelQuery` | `cancel_query()` | Cancel the currently running query. |
228+
| `q` | `Disconnect` | `disconnect()` | Disconnects the current buffer |
229+
| `s` | `SwitchDatabase` | `switch_database()` | Prompts, then switches to a database that is on the currently connected server |
230+
| `d` | `NewDefaultQuery` | `new_default_query()` | Opens a new query and connects to the connection called `default` in your `connections.json`. Useful when combined with the `promptForDatabase` option in the `connections.json`. |
231+
| `s` | `SaveQueryResults` | `save_query_results()` | When in a query result buffer, save the query result by giving a file path with an extension of `.csv`, `.json`, `.xml`, `.xlsx` or `.xls` |
232+
| `r` | `RefreshCache` | `refresh_cache()` | Rebuild the intellisense and sql object (used for the Find function) caches |
233+
| `e` | `EditConnections` | `edit_connections()` | Open the [connections file](#connections-json-file) for editing |
234+
| | `BackupDatabase` | `backup_database()` | Inserts an SQL command to back up the currently connected database |
235+
| | `RestoreDatabase` | `restore_database()` | Prompts for a `.bak` file, then inserts an SQL command to restore the database from that file |
236236

237237
## Connections json file
238238

SampleInputMessage.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"jsonrpc": "2.0",
4+
"id": 3,
5+
"method": "objectexplorer/getsessionid",
6+
"params": {
7+
"options": {
8+
"id": "A3E83733-6997-4198-99A5-C3BE6E24EEC0",
9+
"server": "localhost",
10+
"database": "CreditControlTest",
11+
"databaseDisplayName": "CreditControlTest",
12+
"password": "",
13+
"authenticationType": "Integrated",
14+
"encrypt": "Mandatory",
15+
"trustServerCertificate": true,
16+
"connectTimeout": 15,
17+
"commandTimeout": 30,
18+
"applicationName": "vscode-mssql"
19+
}
20+
}
21+
},
22+
{
23+
"jsonrpc": "2.0",
24+
"id": 4,
25+
"method": "objectexplorer/createsession",
26+
"params": {
27+
"options": {
28+
"id": "A3E83733-6997-4198-99A5-C3BE6E24EEC0",
29+
"server": "localhost",
30+
"database": "CreditControlTest",
31+
"databaseDisplayName": "CreditControlTest",
32+
"password": "",
33+
"authenticationType": "Integrated",
34+
"encrypt": "Mandatory",
35+
"trustServerCertificate": true,
36+
"connectTimeout": 15,
37+
"commandTimeout": 30,
38+
"applicationName": "vscode-mssql"
39+
}
40+
}
41+
},
42+
{
43+
"jsonrpc": "2.0",
44+
"id": 5,
45+
"method": "connection/connect",
46+
"params": {
47+
"ownerUri": "localhost_CreditControlTest_NULL_Integrated_A3E83733-6997-4198-99A5-C3BE6E24EEC0_CreditControlTest_applicationName:vscode-mssql_encrypt:Mandatory_id:A3E83733-6997-4198-99A5-C3BE6E24EEC0_trustServerCertificate:true",
48+
"connection": {
49+
"options": {
50+
"id": "A3E83733-6997-4198-99A5-C3BE6E24EEC0",
51+
"server": "localhost",
52+
"database": "CreditControlTest",
53+
"databaseDisplayName": "CreditControlTest",
54+
"password": "",
55+
"authenticationType": "Integrated",
56+
"encrypt": "Mandatory",
57+
"trustServerCertificate": true,
58+
"connectTimeout": 15,
59+
"commandTimeout": 30,
60+
"applicationName": "vscode-mssql"
61+
}
62+
}
63+
}
64+
},
65+
{
66+
"jsonrpc": "2.0",
67+
"id": 6,
68+
"method": "objectexplorer/expand",
69+
"params": {
70+
"sessionId": "localhost_CreditControlTest_NULL_Integrated_A3E83733-6997-4198-99A5-C3BE6E24EEC0_CreditControlTest_applicationName:vscode-mssql_encrypt:Mandatory_id:A3E83733-6997-4198-99A5-C3BE6E24EEC0_trustServerCertificate:true",
71+
"nodePath": "localhost/CreditControlTest"
72+
}
73+
}
74+
]

docs/screenshots/Find.png

97.8 KB
Loading

docs/screenshots/Results.png

-25.8 KB
Loading

lua/mssql/default_opts.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ return {
4242

4343
-- The filetype (used in neovim to determine the language) of buffers that show query results. Set this to "" to disable markdown rendering.
4444
results_buffer_filetype = "markdown",
45+
46+
-- When choosing a table/view in the finder, immediately execute the generated SELECT statement
47+
execute_generated_select_statements = true,
4548
}

0 commit comments

Comments
 (0)