MCPcopy Create free account
hub / github.com/outerbase/studio / getSingleTableName

Function getSingleTableName

src/components/gui/tabs/query-tab.tsx:487–521  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

485}
486
487export function getSingleTableName(query: string): string | null {
488 try {
489 // Normalize query by removing extra spaces and converting to lowercase
490 const normalizedQuery = query.replace(/\s+/g, " ").trim().toLowerCase();
491
492 // Match the table names after "from" keyword
493 const fromMatch = normalizedQuery.match(
494 /from\s+([^\s,;]+(?:\s*,\s*[^\s,;]+)*)/i
495 );
496 const joinMatches = normalizedQuery.match(/join\s+([^\s,;]+)/gi);
497
498 // If there are JOINs, more than one table is referenced
499 if (joinMatches && joinMatches.length > 0) {
500 return null;
501 }
502
503 // Check if a single table is present
504 if (fromMatch) {
505 const tableName = fromMatch[1];
506
507 // Ensure no additional tables are mentioned
508 const additionalTablesMatch = tableName.match(/,\s*[^\s,;]+/);
509 if (additionalTablesMatch) {
510 return null;
511 }
512
513 return tableName;
514 }
515
516 // No table found
517 return null;
518 } catch (e) {
519 return null;
520 }
521}

Callers 2

getFormatHandlersFunction · 0.90
QueryWindowFunction · 0.85

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected