MCPcopy Create free account
hub / github.com/cmoog/vscode-sql-notebook / doExecution

Method doExecution

src/controller.ts:42–103  ·  view source on GitHub ↗
(cell: vscode.NotebookCell)

Source from the content-addressed store, hash-verified

40 }
41
42 private async doExecution(cell: vscode.NotebookCell): Promise<void> {
43 const execution = this._controller.createNotebookCellExecution(cell);
44 execution.executionOrder = ++this._executionOrder;
45 execution.start(Date.now());
46
47 // this is a sql block
48 const rawQuery = cell.document.getText();
49 if (!globalConnPool.pool) {
50 writeErr(
51 execution,
52 'No active connection found. Configure database connections in the SQL Notebook sidepanel.'
53 );
54 return;
55 }
56 const conn = await globalConnPool.pool.getConnection();
57 execution.token.onCancellationRequested(() => {
58 console.debug('got cancellation request');
59 (async () => {
60 conn.release();
61 conn.destroy();
62 writeErr(execution, 'Query cancelled');
63 })();
64 });
65
66 console.debug('executing query', { query: rawQuery });
67 let result: ExecutionResult;
68 try {
69 result = await conn.query(rawQuery);
70 console.debug('sql query completed', result);
71 conn.release();
72 } catch (err) {
73 console.debug('sql query failed', err);
74 // @ts-ignore
75 writeErr(execution, err.message);
76 conn.release();
77 return;
78 }
79
80 if (typeof result === 'string') {
81 writeSuccess(execution, [[text(result)]]);
82 return;
83 }
84
85 if (
86 result.length === 0 ||
87 (result.length === 1 && result[0].length === 0)
88 ) {
89 writeSuccess(execution, [[text('Successfully executed query')]]);
90 return;
91 }
92
93 writeSuccess(
94 execution,
95 result.map((item) => {
96 const outputs = [text(resultToMarkdownTable(item), 'text/markdown')];
97 if (outputJsonMimeType()) {
98 outputs.push(json(item));
99 }

Callers 1

_executeMethod · 0.95

Calls 5

resultToMarkdownTableFunction · 0.90
writeErrFunction · 0.85
writeSuccessFunction · 0.85
outputJsonMimeTypeFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected