MCPcopy
hub / github.com/chartdb/chartdb / exportBaseSQL

Function exportBaseSQL

src/lib/data/sql-export/export-sql-script.ts:154–721  ·  view source on GitHub ↗
({
    diagram,
    targetDatabaseType,
    isDBMLFlow = false,
    onlyRelationships = false,
    skipFKGeneration = false,
}: {
    diagram: Diagram;
    targetDatabaseType: DatabaseType;
    isDBMLFlow?: boolean;
    onlyRelationships?: boolean;
    skipFKGeneration?: boolean;
})

Source from the content-addressed store, hash-verified

152};
153
154export const exportBaseSQL = ({
155 diagram,
156 targetDatabaseType,
157 isDBMLFlow = false,
158 onlyRelationships = false,
159 skipFKGeneration = false,
160}: {
161 diagram: Diagram;
162 targetDatabaseType: DatabaseType;
163 isDBMLFlow?: boolean;
164 onlyRelationships?: boolean;
165 skipFKGeneration?: boolean;
166}): string => {
167 const { tables, relationships } = diagram;
168
169 if (!tables || tables.length === 0) {
170 return '';
171 }
172
173 if (!isDBMLFlow && diagram.databaseType === targetDatabaseType) {
174 switch (diagram.databaseType) {
175 case DatabaseType.SQL_SERVER:
176 return exportMSSQL({ diagram, onlyRelationships });
177 case DatabaseType.POSTGRESQL:
178 return exportPostgreSQL({ diagram, onlyRelationships });
179 case DatabaseType.SQLITE:
180 return exportSQLite({ diagram, onlyRelationships });
181 case DatabaseType.MYSQL:
182 case DatabaseType.MARIADB:
183 return exportMySQL({ diagram, onlyRelationships });
184 default:
185 return exportPostgreSQL({ diagram, onlyRelationships });
186 }
187 }
188
189 // Deterministic cross-dialect exports (PostgreSQL to MySQL/SQL Server)
190 // These do not use LLM and provide consistent, predictable output
191 if (!isDBMLFlow && diagram.databaseType === DatabaseType.POSTGRESQL) {
192 if (
193 targetDatabaseType === DatabaseType.MYSQL ||
194 targetDatabaseType === DatabaseType.MARIADB
195 ) {
196 return exportPostgreSQLToMySQL({ diagram, onlyRelationships });
197 }
198 if (targetDatabaseType === DatabaseType.SQL_SERVER) {
199 return exportPostgreSQLToMSSQL({ diagram, onlyRelationships });
200 }
201 }
202
203 // Filter out the tables that are views
204 const nonViewTables = tables.filter((table) => !table.isView);
205
206 // Align the data types based on foreign key relationships
207 alignForeignKeyDataTypes(diagram);
208
209 // Initialize the SQL script string
210 let sqlScript = '';
211

Callers 8

export-sql.test.tsFile · 0.90
generateDBMLFromDiagramFunction · 0.90
ExportSQLDialogFunction · 0.90
exportSQLFunction · 0.85

Calls 14

exportMSSQLFunction · 0.90
exportPostgreSQLFunction · 0.90
exportSQLiteFunction · 0.90
exportMySQLFunction · 0.90
exportPostgreSQLToMySQLFunction · 0.90
exportPostgreSQLToMSSQLFunction · 0.90
supportsCustomTypesFunction · 0.90
supportsCheckConstraintsFunction · 0.90
escapeSQLCommentFunction · 0.90
alignForeignKeyDataTypesFunction · 0.85
simplifyDataTypeFunction · 0.85
getQuotedTableNameFunction · 0.85

Tested by

no test coverage detected