createTable method
Create the table creation SQL
Builds the complete CREATE TABLE SQL statement based on the defined columns and their constraints.
Implementation
String createTable(String tableName) {
final buffer = StringBuffer();
final foreignKeys = <String>[];
buffer.write("CREATE TABLE IF NOT EXISTS $tableName (");
_columns.forEach((key, value) {
if (value is SchemaUtils) {
final columnDef = value.get();
if (columnDef.contains("FOREIGN KEY")) {
foreignKeys.add(columnDef);
} else {
buffer.write(columnDef);
}
} else {
buffer.write(value);
}
});
// Remove trailing comma from last column
final sql = buffer.toString().replaceAll(RegExp(r',$'), '');
// Add foreign key constraints
if (foreignKeys.isNotEmpty) {
buffer.write(", ${foreignKeys.join(", ")}");
}
buffer.write(")");
return buffer.toString();
}