MCPcopy
hub / github.com/whoiskatrin/sql-translator / handleSubmit

Function handleSubmit

pages/index.tsx:160–185  ·  view source on GitHub ↗
(event: React.FormEvent)

Source from the content-addressed store, hash-verified

158 };
159
160 const handleSubmit = async (event: React.FormEvent) => {
161 event.preventDefault();
162
163 try {
164 // Validate input syntax
165 if (!isHumanToSql) {
166 const pattern =
167 /^\s*(select|insert|update|delete|create|alter|drop|truncate|grant|revoke|use|begin|commit|rollback)\s/i;
168 const regex = new RegExp(pattern);
169 if (!regex.test(inputText)) {
170 toast.error("Invalid SQL syntax.");
171 return;
172 }
173 }
174 if (showTableSchema && !isValidTableSchema(tableSchema)) {
175 toast.error("Invalid table schema.");
176 return;
177 }
178
179 translate({ inputText, tableSchema, isHumanToSql });
180 setHasTranslated(true);
181 } catch (error) {
182 console.log(error);
183 toast.error(`Error translating ${isHumanToSql ? "to SQL" : "to human"}.`);
184 }
185 };
186
187 return (
188 <div className="flex flex-col items-center justify-center min-h-screen">

Callers 1

HomeFunction · 0.85

Calls 2

isValidTableSchemaFunction · 0.85
translateFunction · 0.85

Tested by

no test coverage detected