MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / TestParseSqlWithTablePrefix

Function TestParseSqlWithTablePrefix

pkg/sql2code/parser/parser_test.go:137–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestParseSqlWithTablePrefix(t *testing.T) {
138 sql := `CREATE TABLE t_person_info (
139 id BIGINT(11) AUTO_INCREMENT NOT NULL COMMENT 'id',
140 age INT(11) unsigned NULL,
141 name VARCHAR(30) NOT NULL DEFAULT 'default_name' COMMENT 'name',
142 created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
143 login_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
144 gender INT(8) NULL,
145 num INT(11) DEFAULT 3 NULL,
146 comment TEXT,
147 PRIMARY KEY (id)
148 ) COMMENT="person info";`
149
150 codes, err := ParseSQL(sql, WithTablePrefix("t_"), WithJSONTag(0), WithNullStyle(NullDisable))
151 assert.Nil(t, err)
152 for k, v := range codes {
153 if k == CodeTypeTableInfo {
154 continue
155 }
156 assert.NotEmpty(t, k)
157 assert.NotEmpty(t, v)
158 }
159 //printCode(codes)
160
161 codes, err = ParseSQL(sql, WithTablePrefix("t_"), WithJSONTag(0), WithCustomTemplate())
162 assert.Nil(t, err)
163 for k, v := range codes {
164 if k != CodeTypeTableInfo {
165 continue
166 }
167 assert.NotEmpty(t, k)
168 assert.NotEmpty(t, v)
169 }
170 jsonData := codes[CodeTypeTableInfo]
171 t.Log(jsonData)
172 t.Log(UnMarshalTableInfo(jsonData))
173
174 codes, err = ParseSQL(sql, WithTablePrefix("t_"), WithJSONTag(0), WithEmbed())
175 assert.Nil(t, err)
176 for k, v := range codes {
177 if k == CodeTypeTableInfo {
178 continue
179 }
180 assert.NotEmpty(t, k)
181 assert.NotEmpty(t, v)
182 }
183 //printCode(codes)
184
185 codes, err = ParseSQL(sql, WithTablePrefix("t_"), WithJSONTag(0), WithWebProto())
186 assert.Nil(t, err)
187 for k, v := range codes {
188 if k == CodeTypeTableInfo {
189 continue
190 }
191 assert.NotEmpty(t, k)
192 assert.NotEmpty(t, v)
193 }
194 //printCode(codes)

Callers

nothing calls this directly

Calls 9

ParseSQLFunction · 0.85
WithTablePrefixFunction · 0.85
WithJSONTagFunction · 0.85
WithNullStyleFunction · 0.85
WithCustomTemplateFunction · 0.85
UnMarshalTableInfoFunction · 0.85
WithEmbedFunction · 0.85
WithWebProtoFunction · 0.85
WithDBDriverFunction · 0.85

Tested by

no test coverage detected