MCPcopy Create free account
hub / github.com/writefreely/writefreely / Format

Method Format

db/create.go:68–130  ·  view source on GitHub ↗
(dialect DialectType, size OptionalInt)

Source from the content-addressed store, hash-verified

66var UnsetDefault OptionalString = OptionalString{Set: false, Value: ""}
67
68func (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

Callers 15

CreatedDateMethod · 0.80
Created8601Method · 0.80
processPostMethod · 0.80
UserFacingCreatedMethod · 0.80
Created8601Method · 0.80
Updated8601Method · 0.80
viewExportPostsFunction · 0.80
viewExportFullFunction · 0.80
GetPostsMethod · 0.80
CreatedFriendlyMethod · 0.80
ExpiresFriendlyMethod · 0.80
CreatedFriendlyMethod · 0.80

Calls

no outgoing calls

Tested by 1

TestColumnType_FormatFunction · 0.64