compileColumn static method
String
compileColumn(
- MigrationColumn column
)
Implementation
static String compileColumn(MigrationColumn column) {
var buf = StringBuffer(columnType(column));
if (column.isNullable == false) buf.write(' NOT NULL');
if (column.defaultValue != null) {
String s;
var value = column.defaultValue;
if (value is RawSql) {
s = value.value;
} else if (value is String) {
var b = StringBuffer();
for (var ch in value.codeUnits) {
if (ch == $single_quote) {
b.write("\\'");
} else {
b.writeCharCode(ch);
}
}
s = b.toString();
} else {
s = value.toString();
}
buf.write(' DEFAULT $s');
}
if (column.indexType == IndexType.unique) {
buf.write(' UNIQUE');
} else if (column.indexType == IndexType.primaryKey) {
buf.write(' PRIMARY KEY');
}
for (var ref in column.externalReferences) {
buf.write(' ${compileReference(ref)}');
}
return buf.toString();
}