MCPcopy
hub / github.com/chartdb/chartdb / getQuotedTableName

Function getQuotedTableName

src/lib/data/sql-export/export-sql-script.ts:100–129  ·  view source on GitHub ↗
(
    table: DBTable,
    isDBMLFlow: boolean = false
)

Source from the content-addressed store, hash-verified

98
99// Helper function to properly quote table/schema names with special characters
100const getQuotedTableName = (
101 table: DBTable,
102 isDBMLFlow: boolean = false
103): string => {
104 // Check if a name is already quoted
105 const isAlreadyQuoted = (name: string) => {
106 return (
107 (name.startsWith('"') && name.endsWith('"')) ||
108 (name.startsWith('`') && name.endsWith('`')) ||
109 (name.startsWith('[') && name.endsWith(']'))
110 );
111 };
112
113 // Only add quotes if needed and not already quoted
114 const quoteIfNeeded = (name: string) => {
115 if (isAlreadyQuoted(name)) {
116 return name;
117 }
118 const needsQuoting = /[^a-zA-Z0-9_]/.test(name) || isDBMLFlow;
119 return needsQuoting ? `"${name}"` : name;
120 };
121
122 if (table.schema) {
123 const quotedSchema = quoteIfNeeded(table.schema);
124 const quotedTable = quoteIfNeeded(table.name);
125 return `${quotedSchema}.${quotedTable}`;
126 } else {
127 return quoteIfNeeded(table.name);
128 }
129};
130
131const getQuotedFieldName = (
132 fieldName: string,

Callers 1

exportBaseSQLFunction · 0.85

Calls 1

quoteIfNeededFunction · 0.85

Tested by

no test coverage detected