MCPcopy Index your code
hub / github.com/deepnote/deepnote / wrapSqlExecution

Function wrapSqlExecution

packages/blocks/src/blocks/sql-blocks.ts:91–112  ·  view source on GitHub ↗

* Wraps a generated `_dntk.execute_sql*` call with the shared dataframe-formatter * prelude and, when the block defines a result variable name, an assignment plus a * trailing echo of that variable. Both SQL helpers share this logic, including the * `input_1` fallback applied to the result variab

(block: SqlBlock, executeSqlFunctionCall: string)

Source from the content-addressed store, hash-verified

89 * `input_1` fallback applied to the result variable name.
90 */
91function wrapSqlExecution(block: SqlBlock, executeSqlFunctionCall: string): string {
92 const pythonVariableName = block.metadata?.deepnote_variable_name
93 const sanitizedPythonVariableName =
94 pythonVariableName !== undefined ? sanitizePythonVariableName(pythonVariableName) || 'input_1' : undefined
95
96 const dataFrameConfig = createDataFrameConfig(block)
97
98 if (sanitizedPythonVariableName === undefined) {
99 return dedent`
100 ${dataFrameConfig}
101
102 ${executeSqlFunctionCall}
103 `
104 }
105
106 return dedent`
107 ${dataFrameConfig}
108
109 ${sanitizedPythonVariableName} = ${executeSqlFunctionCall}
110 ${sanitizedPythonVariableName}
111 `
112}
113
114export function isSqlBlock(block: DeepnoteBlock): block is SqlBlock {
115 return block.type === 'sql'

Calls 2

createDataFrameConfigFunction · 0.90

Tested by

no test coverage detected