getCreateTableStatement method
String
getCreateTableStatement(
)
Implementation
String getCreateTableStatement() {
final databaseDefinition = fields.map((field) {
final autoIncrement =
primaryKey.fields.contains(field) && primaryKey.autoGenerateId;
return field.getDatabaseDefinition(autoIncrement);
}).toList();
final foreignKeyDefinitions =
foreignKeys.map((foreignKey) => foreignKey.getDefinition()).toList();
databaseDefinition.addAll(foreignKeyDefinitions);
final primaryKeyDefinition = _createPrimaryKeyDefinition();
if (primaryKeyDefinition != null) {
databaseDefinition.add(primaryKeyDefinition);
}
final withoutRowidClause = withoutRowid ? ' WITHOUT ROWID' : '';
if (fts == null) {
return 'CREATE TABLE IF NOT EXISTS `$name` (${databaseDefinition.join(', ')})$withoutRowidClause';
} else {
if (fts!.tableCreateOption().isNotEmpty) {
databaseDefinition.add('${fts!.tableCreateOption()}');
}
return 'CREATE VIRTUAL TABLE IF NOT EXISTS `$name` ${fts!.usingOption}(${databaseDefinition.join(', ')})';
}
}