201 lines
6.1 KiB
TypeScript
201 lines
6.1 KiB
TypeScript
import apiService, { Config } from '@/services/api.service'
|
|
import type {
|
|
SqlFunctionDto,
|
|
UpdateSqlFunctionDto,
|
|
SqlQueryDto,
|
|
UpdateSqlQueryDto,
|
|
CreateSqlQueryDto,
|
|
ExecuteSqlQueryDto,
|
|
SqlStoredProcedureDto,
|
|
UpdateSqlStoredProcedureDto,
|
|
DeployStoredProcedureDto,
|
|
SqlViewDto,
|
|
UpdateSqlViewDto,
|
|
DeployViewDto,
|
|
DeployFunctionDto,
|
|
SqlQueryExecutionResultDto,
|
|
DatabaseColumnDto,
|
|
DatabaseTableDto,
|
|
SqlObjectExplorerDto,
|
|
} from '@/proxy/sql-query-manager/models'
|
|
|
|
export class SqlObjectManagerService {
|
|
apiName = 'Default'
|
|
|
|
/**
|
|
* Get all SQL objects for Object Explorer in a single call
|
|
*/
|
|
getAllObjects = (dataSourceCode: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlObjectExplorerDto, void>(
|
|
{
|
|
method: 'GET',
|
|
url: '/api/app/sql-object-manager/objects',
|
|
params: { dataSourceCode },
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// Query Operations
|
|
createQuery = (input: CreateSqlQueryDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryDto, CreateSqlQueryDto>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/query',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
updateQuery = (id: string, input: UpdateSqlQueryDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryDto, UpdateSqlQueryDto>(
|
|
{
|
|
method: 'PUT',
|
|
url: `/api/app/sql-object-manager/query/${id}`,
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deleteQuery = (id: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<void, void>(
|
|
{
|
|
method: 'DELETE',
|
|
url: `/api/app/sql-object-manager/${id}/query`,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
executeQuery = (input: ExecuteSqlQueryDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryExecutionResultDto, ExecuteSqlQueryDto>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/execute-query',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
executeSavedQuery = (id: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryExecutionResultDto, void>(
|
|
{
|
|
method: 'POST',
|
|
url: `/api/app/sql-object-manager/execute-saved-query/${id}`,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// Stored Procedure Operations
|
|
updateStoredProcedure = (id: string, input: UpdateSqlStoredProcedureDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlStoredProcedureDto, UpdateSqlStoredProcedureDto>(
|
|
{
|
|
method: 'PUT',
|
|
url: `/api/app/sql-object-manager/stored-procedure/${id}`,
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deleteStoredProcedure = (id: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<void, void>(
|
|
{
|
|
method: 'DELETE',
|
|
url: `/api/app/sql-object-manager/${id}/stored-procedure`,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deployStoredProcedure = (input: DeployStoredProcedureDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryExecutionResultDto, DeployStoredProcedureDto>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/deploy-stored-procedure',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// View Operations
|
|
updateView = (id: string, input: UpdateSqlViewDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlViewDto, UpdateSqlViewDto>(
|
|
{
|
|
method: 'PUT',
|
|
url: `/api/app/sql-object-manager/view/${id}`,
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deleteView = (id: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<void, void>(
|
|
{
|
|
method: 'DELETE',
|
|
url: `/api/app/sql-object-manager/${id}/view`,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deployView = (input: DeployViewDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryExecutionResultDto, DeployViewDto>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/deploy-view',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// Function Operations
|
|
updateFunction = (id: string, input: UpdateSqlFunctionDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlFunctionDto, UpdateSqlFunctionDto>(
|
|
{
|
|
method: 'PUT',
|
|
url: `/api/app/sql-object-manager/function/${id}`,
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deleteFunction = (id: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<void, void>(
|
|
{
|
|
method: 'DELETE',
|
|
url: `/api/app/sql-object-manager/${id}/function`,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
deployFunction = (input: DeployFunctionDto, config?: Partial<Config>) =>
|
|
apiService.fetchData<SqlQueryExecutionResultDto, DeployFunctionDto>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/deploy-function',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// Database Metadata Operations
|
|
getTableColumns = (dataSourceCode: string, schemaName: string, tableName: string, config?: Partial<Config>) =>
|
|
apiService.fetchData<DatabaseColumnDto[], void>(
|
|
{
|
|
method: 'GET',
|
|
url: '/api/app/sql-object-manager/table-columns',
|
|
params: { dataSourceCode, schemaName, tableName },
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
|
|
// Smart Save - Analyzes SQL and saves to appropriate table with auto-deploy
|
|
smartSave = (input: { sqlText: string; dataSourceCode: string; name?: string; description?: string }, config?: Partial<Config>) =>
|
|
apiService.fetchData<{ objectType: string; objectId: string; deployed: boolean; message: string }, typeof input>(
|
|
{
|
|
method: 'POST',
|
|
url: '/api/app/sql-object-manager/smart-save',
|
|
data: input,
|
|
},
|
|
{ apiName: this.apiName, ...config },
|
|
)
|
|
}
|
|
|
|
// Export service instance
|
|
export const sqlObjectManagerService = new SqlObjectManagerService()
|