MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / TestParseSQL

Function TestParseSQL

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

Source from the content-addressed store, hash-verified

29}
30
31func TestParseSQL(t *testing.T) {
32 sqls := []string{`create table user (
33 id bigint unsigned auto_increment,
34 created_at datetime null,
35 updated_at datetime null,
36 deleted_at datetime null,
37 name char(50) not null comment '用户名',
38 password char(100) not null comment '密码',
39 email char(50) not null comment '邮件',
40 phone bigint unsigned not null comment '手机号码',
41 age tinyint not null comment '年龄',
42 gender tinyint not null comment '性别,1:男,2:女,3:未知',
43 status tinyint not null comment '账号状态,1:未激活,2:已激活,3:封禁',
44 login_state tinyint not null comment '登录状态,1:未登录,2:已登录',
45 primary key (id),
46 constraint user_email_uindex
47 unique (email)
48);`,
49
50 `create table user_order (
51 id varchar(36) not null comment '订单id',
52 product_id varchar(36) not null comment '商品id',
53 user_id bigint unsigned not null comment '用户id',
54 status smallint null comment '0:未支付, 1:已支付, 2:已取消',
55 created_at timestamp null comment '创建时间',
56 updated_at timestamp null comment '更新时间',
57 primary key (id)
58);`,
59
60 `create table user_str (
61 user_id varchar(36) not null comment '用户id',
62 username varchar(50) not null comment '用户名',
63 email varchar(100) not null comment '邮箱',
64 created_at datetime null comment '创建时间',
65 primary key (user_id),
66 constraint email
67 unique (email)
68);`,
69
70 `create table user_no_primary (
71 username varchar(50) not null comment '用户名',
72 email varchar(100) not null comment '邮箱',
73 user_id varchar(36) not null comment '用户id',
74 created_at datetime null comment '创建时间',
75 constraint email
76 unique (email)
77);`}
78
79 for _, sql := range sqls {
80 codes, err := ParseSQL(sql, WithJSONTag(0), WithEmbed())
81 assert.Nil(t, err)
82 for k, v := range codes {
83 if k == CodeTypeTableInfo {
84 continue
85 }
86 assert.NotEmpty(t, k)
87 assert.NotEmpty(t, v)
88 }

Callers

nothing calls this directly

Calls 6

ParseSQLFunction · 0.85
WithJSONTagFunction · 0.85
WithEmbedFunction · 0.85
WithWebProtoFunction · 0.85
WithDBDriverFunction · 0.85
WithCustomTemplateFunction · 0.85

Tested by

no test coverage detected