modified: backend/src/services/ScriptExecutor.ts
This commit is contained in:
@@ -40,6 +40,7 @@ export class ScriptExecutor {
|
||||
// Проверяем тип базы данных и выполняем соответствующий запрос
|
||||
if (dbConfig.type === 'aql') {
|
||||
// AQL запрос
|
||||
try {
|
||||
const result = await aqlExecutor.executeAqlQuery(dbId, {
|
||||
method: query.aql_method || 'GET',
|
||||
endpoint: query.aql_endpoint || '',
|
||||
@@ -49,16 +50,27 @@ export class ScriptExecutor {
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result.rows,
|
||||
rowCount: result.rowCount,
|
||||
executionTime: result.executionTime,
|
||||
};
|
||||
} catch (error: any) {
|
||||
// Возвращаем ошибку как объект, а не бросаем исключение
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// SQL запрос
|
||||
if (!query.sql) {
|
||||
throw new Error(`SQL query is required for database '${dbConfig.name}' (type: ${dbConfig.type})`);
|
||||
}
|
||||
|
||||
try {
|
||||
let processedQuery = query.sql;
|
||||
const paramValues: any[] = [];
|
||||
const paramMatches = query.sql.match(/\$\w+/g) || [];
|
||||
@@ -74,10 +86,20 @@ export class ScriptExecutor {
|
||||
const result = await sqlExecutor.executeQuery(dbId, processedQuery, paramValues);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result.rows,
|
||||
rowCount: result.rowCount,
|
||||
executionTime: result.executionTime,
|
||||
};
|
||||
} catch (error: any) {
|
||||
// Возвращаем ошибку как объект, а не бросаем исключение
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,8 +158,9 @@ def exec_query(query_name, additional_params=None):
|
||||
response_line = input()
|
||||
response = json.loads(response_line)
|
||||
|
||||
if 'error' in response:
|
||||
raise Exception(response['error'])
|
||||
# Проверяем успешность выполнения
|
||||
if not response.get('success', True):
|
||||
raise Exception(response.get('error', 'Unknown error'))
|
||||
|
||||
return response
|
||||
|
||||
@@ -200,6 +223,7 @@ print(json.dumps(result))
|
||||
// Проверяем тип базы данных и выполняем соответствующий запрос
|
||||
if (dbConfig.type === 'aql') {
|
||||
// AQL запрос
|
||||
try {
|
||||
const result = await aqlExecutor.executeAqlQuery(dbId, {
|
||||
method: query.aql_method || 'GET',
|
||||
endpoint: query.aql_endpoint || '',
|
||||
@@ -209,19 +233,33 @@ print(json.dumps(result))
|
||||
});
|
||||
|
||||
python.stdin.write(JSON.stringify({
|
||||
success: true,
|
||||
data: result.rows,
|
||||
rowCount: result.rowCount,
|
||||
executionTime: result.executionTime,
|
||||
}) + '\n');
|
||||
} catch (error: any) {
|
||||
// Отправляем ошибку как объект, а не через поле error
|
||||
python.stdin.write(JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
}) + '\n');
|
||||
}
|
||||
} else {
|
||||
// SQL запрос
|
||||
if (!query.sql) {
|
||||
python.stdin.write(JSON.stringify({
|
||||
error: `SQL query is required for database '${dbConfig.name}' (type: ${dbConfig.type})`
|
||||
success: false,
|
||||
error: `SQL query is required for database '${dbConfig.name}' (type: ${dbConfig.type})`,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
}) + '\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
// Преобразуем параметры
|
||||
let processedQuery = query.sql;
|
||||
const paramValues: any[] = [];
|
||||
@@ -242,13 +280,27 @@ print(json.dumps(result))
|
||||
);
|
||||
|
||||
python.stdin.write(JSON.stringify({
|
||||
success: true,
|
||||
data: result.rows,
|
||||
rowCount: result.rowCount,
|
||||
executionTime: result.executionTime,
|
||||
}) + '\n');
|
||||
} catch (error: any) {
|
||||
python.stdin.write(JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
}) + '\n');
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
python.stdin.write(JSON.stringify({ error: error.message }) + '\n');
|
||||
python.stdin.write(JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
data: [],
|
||||
rowCount: 0,
|
||||
}) + '\n');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user