fusenapi/generator/gen_test.go
2023-06-16 18:52:24 +08:00

40 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"regexp"
"testing"
)
func TestA(t *testing.T) {
main3()
}
func main3() {
ddl := `CREATE TABLE fs_guest (
guest_id bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
auth_key varchar(512) NOT NULL DEFAULT '' COMMENT 'jwt token',
status tinyint(3) unsigned DEFAULT '1' COMMENT '1正常 0不正常',
is_del tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 1删除',
created_at int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
updated_at int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
is_open_render tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否打开个性化渲染1开启0关闭',
is_thousand_face tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已经存在千人千面1存在0不存在',
is_low_rendering tinyint(1) unsigned zerofill NOT NULL DEFAULT '0' COMMENT '是否开启低渲染模型渲染',
is_remove_bg tinyint(1) NOT NULL DEFAULT '1' COMMENT '用户上传logo是否去除背景',
guid decimal(10,2) NOT NULL,
PRIMARY KEY (guest_id) USING BTREE,
UNIQUE KEY fs_guest_guid_IDX (guid) USING BTREE,
KEY fs_guest_is_del_IDX (is_del) USING BTREE,
KEY fs_guest_status_IDX (status) USING BTREE,
KEY fs_guest_created_at_IDX (created_at) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='游客表'`
// 正则表达式匹配
r, _ := regexp.Compile(`CREATE TABLE (\S+) \..*COMMENT='(.*)'`)
matches := r.FindStringSubmatch(ddl)
// 输出结果
fmt.Println("表名:", matches[1])
fmt.Println("注释:", matches[2])
}