composeCreateColumn function
Implementation
String composeCreateColumn(final CreateColumn col) {
final sb = new StringBuffer();
sb.write(col.name);
if (col is CreateInt) {
if (col.autoIncrement) {
if (!col.isPrimary)
throw new Exception(
'SQLite requires that AUTOINCREMENT columns are Primary keys!');
sb.write(' INTEGER PRIMARY KEY AUTOINCREMENT');
} else {
sb.write(' INT');
}
} else if (col is CreateBool) {
sb.write(' INT');
} else if (col is CreateDouble) {
sb.write(' REAL');
} else if (col is CreateDateTime) {
sb.write(' TEXT');
} else if (col is CreateStr) {
if (col.length <= 0) {
sb.write(' TEXT');
} else {
sb.write(' CHAR(');
sb.write(col.length);
sb.write(')');
}
} else {
throw new Exception('Unknown columns to create ${col.runtimeType}!');
}
if (!col.isNullable && !(col is CreateInt && col.autoIncrement))
sb.write(' NOT NULL');
return sb.toString();
}