Skip to content

Commit

Permalink
Add an input to select variable name in metadataform
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Oct 31, 2023
1 parent 694e227 commit 93773e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions schema/metadata-form.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"title": "-"
}
]
},
"/sql-cell/variable": {
"title": "Variable",
"type": "string"
}
}
},
Expand Down
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ const plugin: JupyterFrontEndPlugin<void> = {
body: JSON.stringify({ query: source, id: database_id })
})
.then(data => {
if (kernel && injection.status) {
const future = Private.transferDataToKernel(kernel, data.data);
const variable = SqlCell.getMetadata(activeCell.model, 'variable');
if (kernel && injection.status && variable) {
const future = Private.transferDataToKernel(
kernel,
data.data,
variable
);
future.done.then(reply => {
console.log('REPLY', reply);
});
Expand Down Expand Up @@ -394,13 +399,15 @@ namespace Private {
*/
export function transferDataToKernel(
kernel: Kernel.IKernelConnection,
data: any
data: any,
variable?: string
): Kernel.IShellFuture<
KernelMessage.IExecuteRequestMsg,
KernelMessage.IExecuteReplyMsg
> {
data = JSON.stringify(data).replace(/"/gi, '\\"');
const code = `_sql_transfer_data("${data}")`;
const variableStr = variable ? `, "${variable}"` : '';
const code = `_sql_transfer_data("${data}"${variableStr})`;
const content: KernelMessage.IExecuteRequestMsg['content'] = {
code: code,
stop_on_error: true
Expand Down

0 comments on commit 93773e6

Please sign in to comment.