Skip to content

Commit d07605d

Browse files
committed
support sql workbooks
1 parent bcba187 commit d07605d

File tree

14 files changed

+84
-22
lines changed

14 files changed

+84
-22
lines changed

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@
213213
"light": "./resources/light/add-scratchpad-python.svg"
214214
}
215215
},
216+
{
217+
"category": "KX",
218+
"command": "kdb.scratchpad.sql.create",
219+
"title": "New Workbook (SQL)",
220+
"icon": {
221+
"dark": "./resources/dark/sql.svg",
222+
"light": "./resources/light/sql.svg"
223+
}
224+
},
216225
{
217226
"category": "KX",
218227
"command": "kdb.connections.content.selectView",
@@ -686,6 +695,10 @@
686695
"command": "kdb.scratchpad.python.create",
687696
"when": "true"
688697
},
698+
{
699+
"command": "kdb.scratchpad.sql.create",
700+
"when": "true"
701+
},
689702
{
690703
"command": "kdb.connections.content.selectView",
691704
"when": "false"
@@ -915,10 +928,15 @@
915928
"group": "navigation@2"
916929
},
917930
{
918-
"command": "kdb.scratchpad.explorer.refresh",
931+
"command": "kdb.scratchpad.sql.create",
919932
"when": "view == kdb-scratchpad-explorer",
920933
"group": "navigation@3"
921934
},
935+
{
936+
"command": "kdb.scratchpad.explorer.refresh",
937+
"when": "view == kdb-scratchpad-explorer",
938+
"group": "navigation@4"
939+
},
922940
{
923941
"command": "kdb.queryHistory.clear",
924942
"when": "view == kdb-query-history",

ref_card.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
| KX: Install KDB-X | KX: New Notebook | KX: Focus on Datasources view |
77
| KX: Start REPL | KX: New Workbook (q) | KX: Focus on Workbooks view |
88
| KX: Import Connections | KX: New Workbook (Python) | KX: Focus on Query History view |
9-
| KX: Export Connections | KX: New Datasource | KX: Focus on Help and Feedback view |
9+
| KX: Export Connections | KX: New Workbook (SQL) | KX: Focus on Help and Feedback view |
10+
| | KX: New Datasource | |
1011

1112
## Keybindings
1213

@@ -60,10 +61,10 @@
6061
| :--------- | :--: | :--: | :---: | :------: | :----: | :----: | :------------: |
6162
| File `q` ||||| | ||
6263
| File `py` ||||| | ||
63-
| File `sql` || | || | ||
64+
| File `sql` || | || | ||
6465
| Cell `q` ||||| | ||
6566
| Cell `py` ||||| | ||
66-
| Cell `sql` || | || | ||
67+
| Cell `sql` || | || | ||
6768
| Datasource | | | |||||
6869

6970
`REPL` and `My q` requires [PyKX](https://github.com/KxSystems/kx-vscode/wiki/Use-PyKX-Within-REPL) for Python support.

resources/dark/sql-active.svg

Lines changed: 3 additions & 0 deletions
Loading

resources/dark/sql-connected.svg

Lines changed: 3 additions & 0 deletions
Loading

resources/dark/sql.svg

Lines changed: 3 additions & 0 deletions
Loading

resources/light/sql-active.svg

Lines changed: 3 additions & 0 deletions
Loading

resources/light/sql-connected.svg

Lines changed: 3 additions & 0 deletions
Loading

resources/light/sql.svg

Lines changed: 3 additions & 0 deletions
Loading

src/commands/serverCommand.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
formatScratchpadStacktrace,
7979
resultToBase64,
8080
needsScratchpad,
81+
getSQLWrapper,
8182
} from "../utils/queryUtils";
8283
import { openUrl } from "../utils/uriUtils";
8384
import {
@@ -1126,8 +1127,12 @@ export async function runQuery(
11261127
variable = await inputVariable();
11271128
}
11281129

1130+
if (isSql && !isInsights) {
1131+
query = getSQLWrapper(query);
1132+
}
1133+
11291134
const runner = Runner.create((_, token) => {
1130-
return target || isSql
1135+
return target || (isSql && isInsights)
11311136
? variable
11321137
? populateScratchpad(
11331138
getPartialDatasourceFile(query, target, isSql, isPython),

src/commands/workspaceCommand.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,12 @@ function isPython(uri: Uri | undefined) {
449449
}
450450

451451
function isWorkbook(uri: Uri | undefined) {
452-
return uri && (uri.path.endsWith(".kdb.q") || uri.path.endsWith(".kdb.py"));
452+
return (
453+
uri &&
454+
(uri.path.endsWith(".kdb.q") ||
455+
uri.path.endsWith(".kdb.py") ||
456+
uri.path.endsWith(".kdb.sql"))
457+
);
453458
}
454459

455460
function isDataSource(uri: Uri | undefined) {
@@ -538,15 +543,6 @@ export async function runActiveEditor(type?: ExecutionTypes) {
538543
const target = isInsights ? getTargetForUri(uri) : undefined;
539544
const isSql = executorName.endsWith(".sql");
540545

541-
if (isSql && !isInsights) {
542-
notify(
543-
`SQL execution is not supported on ${conn.connLabel}.`,
544-
MessageKind.ERROR,
545-
{ logger },
546-
);
547-
return;
548-
}
549-
550546
if (type === ExecutionTypes.PopulateScratchpad && !isInsights) {
551547
notify(
552548
`Populating scratchpad is not supported on ${conn.connLabel}.`,

0 commit comments

Comments
 (0)