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