(schema?: string, routineType?: "procedure" | "function")
| 475 | } |
| 476 | |
| 477 | async getStoredProcedures(schema?: string, routineType?: "procedure" | "function"): Promise<string[]> { |
| 478 | if (!this.connection) { |
| 479 | throw new Error("Not connected to SQL Server database"); |
| 480 | } |
| 481 | |
| 482 | try { |
| 483 | // In SQL Server, use 'dbo' as the default schema if none specified |
| 484 | const schemaToUse = schema || "dbo"; |
| 485 | |
| 486 | const request = this.connection.request().input("schema", sql.VarChar, schemaToUse); |
| 487 | |
| 488 | // Build routine type filter |
| 489 | let typeFilter: string; |
| 490 | if (routineType === "function") { |
| 491 | typeFilter = "AND ROUTINE_TYPE = 'FUNCTION'"; |
| 492 | } else if (routineType === "procedure") { |
| 493 | typeFilter = "AND ROUTINE_TYPE = 'PROCEDURE'"; |
| 494 | } else { |
| 495 | typeFilter = "AND (ROUTINE_TYPE = 'PROCEDURE' OR ROUTINE_TYPE = 'FUNCTION')"; |
| 496 | } |
| 497 | |
| 498 | const query = ` |
| 499 | SELECT ROUTINE_NAME |
| 500 | FROM INFORMATION_SCHEMA.ROUTINES |
| 501 | WHERE ROUTINE_SCHEMA = @schema |
| 502 | ${typeFilter} |
| 503 | ORDER BY ROUTINE_NAME |
| 504 | `; |
| 505 | |
| 506 | const result = await request.query(query); |
| 507 | return result.recordset.map((row: { ROUTINE_NAME: any }) => row.ROUTINE_NAME); |
| 508 | } catch (error) { |
| 509 | throw new Error(`Failed to get stored procedures: ${(error as Error).message}`); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | async getStoredProcedureDetail(procedureName: string, schema?: string): Promise<StoredProcedure> { |
| 514 | if (!this.connection) { |
nothing calls this directly
no outgoing calls
no test coverage detected