MCPcopy Create free account
hub / github.com/TabularisDB/tabularis / generateCreateTableSQL

Function generateCreateTableSQL

src/utils/sqlGenerator.ts:185–224  ·  view source on GitHub ↗
(
  tableName: string,
  columns: TableColumn[],
  foreignKeys: ForeignKey[],
  indexes: Index[],
  driver: DriverCapabilities | DatabaseDriver
)

Source from the content-addressed store, hash-verified

183 * a legacy string driver ID (for backward compatibility).
184 */
185export function generateCreateTableSQL(
186 tableName: string,
187 columns: TableColumn[],
188 foreignKeys: ForeignKey[],
189 indexes: Index[],
190 driver: DriverCapabilities | DatabaseDriver
191): string {
192 const caps = resolveSqlCapabilities(driver);
193 const quote = caps.quote;
194 const lines: string[] = [];
195
196 // Start CREATE TABLE
197 lines.push(`CREATE TABLE ${quote}${tableName}${quote} (`);
198
199 // Column definitions
200 const columnDefs = columns.map(col => generateColumnDefinition(col, driver));
201
202 // Primary key constraint (if not handled in column def)
203 const pkConstraint = generatePrimaryKeyConstraint(columns, driver);
204 if (pkConstraint) {
205 columnDefs.push(pkConstraint);
206 }
207
208 // Foreign key constraints
209 const fkConstraints = generateForeignKeyConstraints(foreignKeys, quote);
210 columnDefs.push(...fkConstraints);
211
212 // Close column definitions
213 lines.push(columnDefs.join(',\n'));
214 lines.push(');');
215
216 // Index statements
217 const indexStatements = generateIndexStatements(indexes, tableName, quote);
218 if (indexStatements.length > 0) {
219 lines.push('');
220 lines.push(...indexStatements);
221 }
222
223 return lines.join('\n');
224}

Callers 2

generateSQLFunction · 0.90

Calls 5

resolveSqlCapabilitiesFunction · 0.85
generateColumnDefinitionFunction · 0.85
generateIndexStatementsFunction · 0.85

Tested by

no test coverage detected