tableCreationToPgsql method
String
tableCreationToPgsql(
{ - bool ifNotExists = false,
})
Implementation
String tableCreationToPgsql({bool ifNotExists = false}) {
String out = '';
// Table
if (ifNotExists) {
out += 'CREATE TABLE IF NOT EXISTS "$name" (\n';
} else {
out += 'CREATE TABLE "$name" (\n';
}
var columnsPgSql = <String>[];
for (var column in columns) {
columnsPgSql.add(' ${column.toPgSqlFragment()}');
}
out += columnsPgSql.join(',\n');
out += '\n);\n';
// Indexes
var indexesExceptId = <IndexDefinition>[];
for (var index in indexes) {
if (index.elements.length == 1 &&
index.elements.first.definition == 'id') {
continue;
}
indexesExceptId.add(index);
}
if (indexesExceptId.isNotEmpty) {
out += '\n';
out += '-- Indexes\n';
for (var index in indexesExceptId) {
out += index.toPgSql(tableName: name, ifNotExists: ifNotExists);
}
}
out += '\n';
return out;
}