public void WriteTo(SqlBuilder sb) { sb.WriteIdentifier(Name); sb.Append(" "); sb.Write(Type); if (!IsOptional) { sb.Append(" NOT NULL"); } if (AutoIncriment) { sb.Append(" AUTO_INCREMENT"); } if (IsKey) { sb.Append(" "); sb.Append(IsUnique ? "UNIQUE" : "PRIMARY"); sb.Append(" KEY"); } if (Default != null) { sb.Append(" DEFAULT "); sb.Append(Default); } if (OnUpdate != null) { sb.Append(" ON UPDATE "); sb.Append(OnUpdate); } if (Format != null) { sb.Append(" " + Format.Value.ToString().ToUpper()); } }
public void WriteTo(SqlBuilder sql) { sql.CreateTable(new SchemaObject(Name)); sql.AppendLine(" ("); var i = 0; foreach (var column in Columns) { if (++i != 1) { sql.AppendLine(","); } sql.Indent(1); column.WriteTo(sql); } if (!PrimaryKey[0].IsIdentity) { sql.AppendLine(","); sql.Indent(1); sql.Append("PRIMARY KEY "); sql.WriteTuple(PrimaryKey.Names); } foreach (var index in Indexes) { sql.AppendLine(","); if (index.Type == IndexFlags.Unique) { // UNIQUE KEY `ix_phone` (`country`, `area`, `number`, `extension`), sql.Indent(1); sql.Append("UNIQUE KEY "); sql.WriteIdentifier(index.Name); sql.Append(" "); sql.WriteTuple(ValueList.With(index.Members)); } else { sql.Indent(1); sql.Append("INDEX "); sql.WriteIdentifier(index.Name); sql.Append(" "); sql.WriteTuple(ValueList.With(index.Members)); } } sql.AppendLine(""); sql.Append(")"); }