MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / executeStatement

Function executeStatement

src/components/QueryDrawer.tsx:53–96  ·  view source on GitHub ↗
(statement: string)

Source from the content-addressed store, hash-verified

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) {

Callers 1

QueryDrawerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected