(dialect DialectType, size OptionalInt)
| 66 | var UnsetDefault OptionalString = OptionalString{Set: false, Value: ""} |
| 67 | |
| 68 | func (d ColumnType) Format(dialect DialectType, size OptionalInt) (string, error) { |
| 69 | if dialect != DialectMySQL && dialect != DialectSQLite { |
| 70 | return "", fmt.Errorf("unsupported column type %d for dialect %d and size %v", d, dialect, size) |
| 71 | } |
| 72 | switch d { |
| 73 | case ColumnTypeSmallInt: |
| 74 | { |
| 75 | if dialect == DialectSQLite { |
| 76 | return "INTEGER", nil |
| 77 | } |
| 78 | mod := "" |
| 79 | if size.Set { |
| 80 | mod = fmt.Sprintf("(%d)", size.Value) |
| 81 | } |
| 82 | return "SMALLINT" + mod, nil |
| 83 | } |
| 84 | case ColumnTypeInteger: |
| 85 | { |
| 86 | if dialect == DialectSQLite { |
| 87 | return "INTEGER", nil |
| 88 | } |
| 89 | mod := "" |
| 90 | if size.Set { |
| 91 | mod = fmt.Sprintf("(%d)", size.Value) |
| 92 | } |
| 93 | return "INT" + mod, nil |
| 94 | } |
| 95 | case ColumnTypeChar: |
| 96 | { |
| 97 | if dialect == DialectSQLite { |
| 98 | return "TEXT", nil |
| 99 | } |
| 100 | mod := "" |
| 101 | if size.Set { |
| 102 | mod = fmt.Sprintf("(%d)", size.Value) |
| 103 | } |
| 104 | return "CHAR" + mod, nil |
| 105 | } |
| 106 | case ColumnTypeVarChar: |
| 107 | { |
| 108 | if dialect == DialectSQLite { |
| 109 | return "TEXT", nil |
| 110 | } |
| 111 | mod := "" |
| 112 | if size.Set { |
| 113 | mod = fmt.Sprintf("(%d)", size.Value) |
| 114 | } |
| 115 | return "VARCHAR" + mod, nil |
| 116 | } |
| 117 | case ColumnTypeBool: |
| 118 | { |
| 119 | if dialect == DialectSQLite { |
| 120 | return "INTEGER", nil |
| 121 | } |
| 122 | return "TINYINT(1)", nil |
| 123 | } |
| 124 | case ColumnTypeDateTime: |
| 125 | return "DATETIME", nil |
no outgoing calls