| 51 | }, [queryStore.showDrawer]); |
| 52 | |
| 53 | const executeStatement = async (statement: string) => { |
| 54 | if (!statement) { |
| 55 | toast.error("Please enter a statement."); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (!context) { |
| 60 | toast.error("No execution context found."); |
| 61 | setIsLoading(false); |
| 62 | setExecutionResult(undefined); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | setIsLoading(true); |
| 67 | setExecutionResult(undefined); |
| 68 | const { connection, database } = context; |
| 69 | try { |
| 70 | const response = await fetch("/api/connection/execute", { |
| 71 | method: "POST", |
| 72 | headers: { |
| 73 | "Content-Type": "application/json", |
| 74 | }, |
| 75 | body: JSON.stringify({ |
| 76 | connection, |
| 77 | db: database?.name, |
| 78 | statement, |
| 79 | }), |
| 80 | }); |
| 81 | const result = (await response.json()) as ResponseObject<ExecutionResult>; |
| 82 | if (result.message) { |
| 83 | setExecutionResult({ |
| 84 | rawResult: [], |
| 85 | error: result.message, |
| 86 | }); |
| 87 | } else { |
| 88 | setExecutionResult(result.data); |
| 89 | } |
| 90 | } catch (error) { |
| 91 | console.error(error); |
| 92 | toast.error("Failed to execute statement"); |
| 93 | } finally { |
| 94 | setIsLoading(false); |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | const close = () => { |
| 99 | if (originalStatement !== statement && context?.messageId) { |