MCPcopy Index your code
hub / github.com/caesarHQ/textSQL / executeSql

Function executeSql

client/censusGPT/src/App.js:268–420  ·  view source on GitHub ↗
(sql)

Source from the content-addressed store, hash-verified

266 }
267
268 const executeSql = (sql) => {
269 setIsLoading(true)
270 setSqlExplanation()
271 clearMapLayers()
272
273 const options = {
274 method: 'POST',
275 headers: { 'content-type': 'application/json' },
276 body: JSON.stringify({
277 sql,
278 session_id: sessionId,
279 }),
280 }
281
282 fetch(api_endpoint + '/api/execute_sql', options)
283 .then((response) => response.json())
284 .then((response) => {
285 // Set the loading state to false
286 setIsLoading(false)
287
288 // Handle errors
289 if (!response || !response.result) {
290 capturePosthog('backend_error', response)
291 setErrorMessage(
292 'Something went wrong. Please try again or try a different query'
293 )
294 return
295 }
296
297 // Capture the response in posthog
298 capturePosthog('backend_response', { origin: 'executeSql' })
299
300 // Filter out lat and long columns
301 let filteredColumns = response.result.column_names.filter(
302 (c) => c !== 'lat' && c !== 'long'
303 )
304
305 // Fit the order of columns and filter out lat and long row values
306 let rows = response.result.results.map((value) => {
307 let row = []
308 // Find each of the filtered column value in the object and push it into the row
309 filteredColumns.map((c) => row.push(value[c]))
310 return row
311 })
312 setTableInfo({ rows, columns: filteredColumns })
313
314 // render cities layer on the map
315 if (
316 filteredColumns.indexOf('zip_code') === -1 &&
317 filteredColumns.indexOf('city') >= 0
318 ) {
319 // Get the cities
320 let responseCities = getCities(response.result)
321
322 if (!responseCities.length) {
323 setErrorMessage('No results were returned')
324 setCities([])
325 setZipcodes([]) // reset cities rendering

Callers 1

sqlDisplay.jsFile · 0.85

Calls 6

capturePosthogFunction · 0.90
getCitiesFunction · 0.90
getZipcodesFunction · 0.90
logSentryErrorFunction · 0.90
clearMapLayersFunction · 0.85

Tested by

no test coverage detected