modified: backend/src/services/ScriptExecutor.ts
This commit is contained in:
@@ -72,16 +72,19 @@ export class ScriptExecutor {
|
|||||||
*/
|
*/
|
||||||
async executePython(code: string, context: ScriptContext): Promise<any> {
|
async executePython(code: string, context: ScriptContext): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
// Сериализуем параметры в JSON строку
|
||||||
|
const paramsJson = JSON.stringify(context.requestParams);
|
||||||
|
|
||||||
// Создаем wrapper код для Python
|
// Создаем wrapper код для Python
|
||||||
const wrapperCode = `
|
const wrapperCode = `
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Параметры запроса
|
# Параметры запроса - парсим JSON (автоматически конвертирует null->None, true->True, false->False)
|
||||||
params = ${JSON.stringify(context.requestParams)}
|
params = json.loads('''${paramsJson}''')
|
||||||
|
|
||||||
# Функция для выполнения SQL запросов
|
# Функция для выполнения SQL запросов (синхронная, НЕ используйте await!)
|
||||||
def exec_query(query_name, additional_params=None):
|
def exec_query(query_name, additional_params=None):
|
||||||
if additional_params is None:
|
if additional_params is None:
|
||||||
additional_params = {}
|
additional_params = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user