(col *ast.ColumnDef)
| 997 | } |
| 998 | |
| 999 | func (f *SQLFormatter) formatColumnDef(col *ast.ColumnDef) { |
| 1000 | f.builder.WriteString(col.Name + " " + col.Type) |
| 1001 | for _, constraint := range col.Constraints { |
| 1002 | f.builder.WriteString(" ") |
| 1003 | f.writeKeyword(constraint.Type) |
| 1004 | // Format DEFAULT value if present |
| 1005 | if constraint.Type == "DEFAULT" && constraint.Default != nil { |
| 1006 | f.builder.WriteString(" ") |
| 1007 | if err := f.formatExpression(constraint.Default); err != nil { |
| 1008 | // Fallback to token literal on error |
| 1009 | f.builder.WriteString(constraint.Default.TokenLiteral()) |
| 1010 | } |
| 1011 | } |
| 1012 | // Format CHECK expression if present |
| 1013 | if constraint.Type == "CHECK" && constraint.Check != nil { |
| 1014 | f.builder.WriteString(" (") |
| 1015 | if err := f.formatExpression(constraint.Check); err != nil { |
| 1016 | f.builder.WriteString(constraint.Check.TokenLiteral()) |
| 1017 | } |
| 1018 | f.builder.WriteString(")") |
| 1019 | } |
| 1020 | // Format REFERENCES if present |
| 1021 | if constraint.Type == "REFERENCES" && constraint.References != nil { |
| 1022 | f.builder.WriteString(" ") |
| 1023 | f.builder.WriteString(constraint.References.Table) |
| 1024 | if len(constraint.References.Columns) > 0 { |
| 1025 | f.builder.WriteString("(") |
| 1026 | f.builder.WriteString(strings.Join(constraint.References.Columns, ", ")) |
| 1027 | f.builder.WriteString(")") |
| 1028 | } |
| 1029 | if constraint.References.OnDelete != "" { |
| 1030 | f.builder.WriteString(" ") |
| 1031 | f.writeKeyword("ON DELETE") |
| 1032 | f.builder.WriteString(" ") |
| 1033 | f.writeKeyword(constraint.References.OnDelete) |
| 1034 | } |
| 1035 | if constraint.References.OnUpdate != "" { |
| 1036 | f.builder.WriteString(" ") |
| 1037 | f.writeKeyword("ON UPDATE") |
| 1038 | f.builder.WriteString(" ") |
| 1039 | f.writeKeyword(constraint.References.OnUpdate) |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | func (f *SQLFormatter) formatAlterTableAction(action *ast.AlterTableAction) { |
| 1046 | f.builder.WriteString(action.Type) |
no test coverage detected