Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Commit 88d7da1

Browse files
committed
tpl: sql script removes quote
1 parent 13baa8c commit 88d7da1

9 files changed

+33
-31
lines changed

example/model/model_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ func runInitSQLScript() error {
2323
return err
2424
}
2525
for _, f := range fs {
26-
query, err := ioutil.ReadFile(filepath.Join(dir, f.Name()))
26+
plain, err := ioutil.ReadFile(filepath.Join(dir, f.Name()))
2727
if err != nil {
2828
return err
2929
}
30-
log.Printf("EXEC SCRIPT: \nFILENAME:%s \nPLAIN QUERY: %s", f.Name(), string(query))
31-
if _, err := MySQL().Exec(string(query)); err != nil {
32-
return err
30+
log.Printf("EXEC SCRIPT: \nFILENAME:%s \nPLAIN QUERY: %s", f.Name(), string(plain))
31+
queries := strings.Split(string(plain), ";")
32+
for _, q := range queries {
33+
if strings.TrimSpace(q) == "" {
34+
continue
35+
}
36+
log.Printf("EXEC QUERY: %s", q)
37+
if _, err := MySQL().Exec(q); err != nil {
38+
return err
39+
}
3340
}
3441
}
3542
return nil

example/script/gen.script.mysql.blog.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ CREATE TABLE `blogs` (
88
`readed` INT(11) NOT NULL DEFAULT '0',
99
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1010
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
11-
PRIMARY KEY(`id`,`user_id`)
12-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'blogs';
13-
CREATE INDEX `status_of_blog_idx` ON `blogs`(`status`);
11+
PRIMARY KEY(`id`,`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'blogs';
12+
CREATE INDEX status_of_blog_idx ON blogs(status);
1413

example/script/gen.script.mysql.indexed.blog.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ CREATE TABLE `indexed_blog` (
88
`readed` INT(11) NOT NULL DEFAULT '0',
99
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1010
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
11-
PRIMARY KEY(`id`)
12-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'indexed_blog';
11+
PRIMARY KEY(`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'indexed_blog';
1312

example/script/gen.script.mysql.office.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ CREATE TABLE `testCRUD` (
99
`update_by` VARCHAR(100) NOT NULL DEFAULT '',
1010
`create_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
1111
`update_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
12-
PRIMARY KEY(`office_id`)
13-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'testCRUD';
12+
PRIMARY KEY(`office_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'testCRUD';
1413

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
DROP VIEW IF EXISTS `user_base_info`;
3-
CREATE VIEW `user_base_info` AS SELECT `id`,`name`,`mailbox`,`sex` FROM users;
2+
DROP VIEW IF EXISTS user_base_info;
3+
CREATE VIEW user_base_info AS SELECT `id`,`name`,`mailbox`,`sex` FROM users;
44

example/script/gen.script.mysql.user.blogs.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
CREATE TABLE `user_blogs` (
33
`user_id` INT(11) NOT NULL DEFAULT '0',
44
`blog_id` INT(11) NOT NULL DEFAULT '0',
5-
PRIMARY KEY(`user_id`,`blog_id`)
6-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'user_blogs';
5+
PRIMARY KEY(`user_id`,`blog_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'user_blogs';
76

example/script/gen.script.mysql.user.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
CREATE TABLE `users` (
33
`id` INT(11) NOT NULL AUTO_INCREMENT,
4+
`sub_id` INT(11) NOT NULL DEFAULT '0',
45
`name` VARCHAR(100) NOT NULL DEFAULT '',
56
`mailbox` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '邮箱',
67
`sex` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
@@ -14,9 +15,8 @@ CREATE TABLE `users` (
1415
`created_at` BIGINT(20) NOT NULL DEFAULT '0',
1516
`updated_at` BIGINT(20) NOT NULL DEFAULT '0',
1617
`deleted_at` BIGINT(20) NULL ,
17-
PRIMARY KEY(`id`),
18-
UNIQUE KEY `uniq_mailbox_password_of_user_uk` (`mailbox`,`password`)
19-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '用户表';
20-
CREATE INDEX `sex_of_user_idx` ON `users`(`sex`);
21-
CREATE INDEX `age_of_user_rng` ON `users`(`age`);
18+
PRIMARY KEY(`id`,`sub_id`,`name`),
19+
UNIQUE KEY `uniq_mailbox_password_of_user_uk` (`mailbox`,`password`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '用户表';
20+
CREATE INDEX sex_of_user_idx ON users(sex);
21+
CREATE INDEX age_of_user_rng ON users(age);
2222

tpl/bindata.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tpl/script.mysql.sql

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ CREATE TABLE `{{$obj.DbTable}}` (
1717
{{- end -}}
1818
)
1919
{{- end}}
20-
{{- end}}
21-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '{{$obj.Comment}}';
20+
{{- end}}) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '{{$obj.Comment}}';
2221

2322
{{- range $i, $index := $obj.Indexes}}
2423
{{- if not $index.HasPrimaryKey}}
25-
CREATE INDEX `{{$index.Name | camel2name}}` ON `{{$obj.DbTable}}`(
24+
CREATE INDEX {{$index.Name | camel2name}} ON {{$obj.DbTable}}(
2625
{{- range $i, $f := $index.Fields -}}
2726
{{- if eq (add $i 1) (len $index.Fields) -}}
28-
`{{- $f.Name | camel2name -}}`
27+
{{- $f.Name | camel2name -}}
2928
{{- else -}}
30-
`{{- $f.Name | camel2name -}}`,
29+
{{- $f.Name | camel2name -}},
3130
{{- end -}}
3231
{{- end -}}
3332
);
@@ -36,12 +35,12 @@ CREATE INDEX `{{$index.Name | camel2name}}` ON `{{$obj.DbTable}}`(
3635

3736
{{- range $i, $index := $obj.Ranges}}
3837
{{- if not $index.HasPrimaryKey}}
39-
CREATE INDEX `{{$index.Name | camel2name}}` ON `{{$obj.DbTable}}`(
38+
CREATE INDEX {{$index.Name | camel2name}} ON {{$obj.DbTable}}(
4039
{{- range $i, $f := $index.Fields -}}
4140
{{- if eq (add $i 1) (len $index.Fields) -}}
42-
`{{- $f.Name | camel2name -}}`
41+
{{- $f.Name | camel2name -}}
4342
{{- else -}}
44-
`{{- $f.Name | camel2name -}}`,
43+
{{- $f.Name | camel2name -}},
4544
{{- end -}}
4645
{{- end -}}
4746
);
@@ -50,8 +49,8 @@ CREATE INDEX `{{$index.Name | camel2name}}` ON `{{$obj.DbTable}}`(
5049
{{- end}}
5150

5251
{{- if ne $obj.DbView ""}}
53-
DROP VIEW IF EXISTS `{{$obj.DbView}}`;
54-
CREATE VIEW `{{$obj.DbView}}` AS {{$obj.ImportSQL}};
52+
DROP VIEW IF EXISTS {{$obj.DbView}};
53+
CREATE VIEW {{$obj.DbView}} AS {{$obj.ImportSQL}};
5554
{{- end}}
5655

5756
{{end}}

0 commit comments

Comments
 (0)