erp-platform/ui/src/services/sql-query-manager.service.ts

191 lines
5.6 KiB
TypeScript
Raw Normal View History

2025-12-05 13:45:45 +00:00
import apiService, { Config } from '@/services/api.service'
import type {
SqlFunctionDto,
UpdateSqlFunctionDto,
SqlQueryDto,
UpdateSqlQueryDto,
CreateSqlQueryDto,
2025-12-05 13:45:45 +00:00
ExecuteSqlQueryDto,
SqlStoredProcedureDto,
UpdateSqlStoredProcedureDto,
DeployStoredProcedureDto,
SqlViewDto,
UpdateSqlViewDto,
DeployViewDto,
DeployFunctionDto,
2025-12-05 13:45:45 +00:00
SqlQueryExecutionResultDto,
DatabaseColumnDto,
DatabaseTableDto,
SqlObjectExplorerDto,
2025-12-05 13:45:45 +00:00
} from '@/proxy/sql-query-manager/models'
export class SqlObjectManagerService {
2025-12-05 13:45:45 +00:00
apiName = 'Default'
/**
* Get all SQL objects for Object Explorer in a single call
*/
getAllObjects = (dataSourceCode: string, config?: Partial<Config>) =>
apiService.fetchData<SqlObjectExplorerDto, void>(
2025-12-05 13:45:45 +00:00
{
method: 'GET',
url: '/api/app/sql-object-manager/objects',
params: { dataSourceCode },
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
// Query Operations
createQuery = (input: CreateSqlQueryDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlQueryDto, CreateSqlQueryDto>(
{
method: 'POST',
url: '/api/app/sql-object-manager/query',
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
updateQuery = (id: string, input: UpdateSqlQueryDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlQueryDto, UpdateSqlQueryDto>(
{
method: 'PUT',
url: `/api/app/sql-object-manager/query/${id}`,
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
deleteQuery = (id: string, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<void, void>(
{
method: 'DELETE',
url: `/api/app/sql-object-manager/query/${id}`,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
executeQuery = (input: ExecuteSqlQueryDto, config?: Partial<Config>) =>
apiService.fetchData<SqlQueryExecutionResultDto, ExecuteSqlQueryDto>(
{
method: 'POST',
url: '/api/app/sql-object-manager/execute-query',
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
executeSavedQuery = (id: string, config?: Partial<Config>) =>
apiService.fetchData<SqlQueryExecutionResultDto, void>(
2025-12-05 13:45:45 +00:00
{
method: 'POST',
url: `/api/app/sql-object-manager/execute-saved-query/${id}`,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
// Stored Procedure Operations
updateStoredProcedure = (id: string, input: UpdateSqlStoredProcedureDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlStoredProcedureDto, UpdateSqlStoredProcedureDto>(
{
method: 'PUT',
url: `/api/app/sql-object-manager/stored-procedure/${id}`,
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
deleteStoredProcedure = (id: string, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<void, void>(
{
method: 'DELETE',
url: `/api/app/sql-object-manager/stored-procedure/${id}`,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
deployStoredProcedure = (input: DeployStoredProcedureDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlQueryExecutionResultDto, DeployStoredProcedureDto>(
{
method: 'POST',
url: '/api/app/sql-object-manager/deploy-stored-procedure',
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
// View Operations
updateView = (id: string, input: UpdateSqlViewDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlViewDto, UpdateSqlViewDto>(
{
method: 'PUT',
url: `/api/app/sql-object-manager/view/${id}`,
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
deleteView = (id: string, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<void, void>(
{
method: 'DELETE',
url: `/api/app/sql-object-manager/view/${id}`,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
deployView = (input: DeployViewDto, config?: Partial<Config>) =>
2025-12-05 13:45:45 +00:00
apiService.fetchData<SqlQueryExecutionResultDto, DeployViewDto>(
{
method: 'POST',
url: '/api/app/sql-object-manager/deploy-view',
2025-12-05 13:45:45 +00:00
data: input,
},
{ apiName: this.apiName, ...config },
)
// Function Operations
updateFunction = (id: string, input: UpdateSqlFunctionDto, config?: Partial<Config>) =>
apiService.fetchData<SqlFunctionDto, UpdateSqlFunctionDto>(
2025-12-05 13:45:45 +00:00
{
method: 'PUT',
url: `/api/app/sql-object-manager/function/${id}`,
data: input,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
deleteFunction = (id: string, config?: Partial<Config>) =>
apiService.fetchData<void, void>(
2025-12-05 13:45:45 +00:00
{
method: 'DELETE',
url: `/api/app/sql-object-manager/function/${id}`,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
deployFunction = (input: DeployFunctionDto, config?: Partial<Config>) =>
apiService.fetchData<SqlQueryExecutionResultDto, DeployFunctionDto>(
2025-12-05 13:45:45 +00:00
{
method: 'POST',
url: '/api/app/sql-object-manager/deploy-function',
data: input,
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
// Database Metadata Operations
getTableColumns = (dataSourceCode: string, schemaName: string, tableName: string, config?: Partial<Config>) =>
apiService.fetchData<DatabaseColumnDto[], void>(
2025-12-05 13:45:45 +00:00
{
method: 'GET',
url: '/api/app/sql-object-manager/table-columns',
params: { dataSourceCode, schemaName, tableName },
2025-12-05 13:45:45 +00:00
},
{ apiName: this.apiName, ...config },
)
}
// Export service instance
export const sqlObjectManagerService = new SqlObjectManagerService()