Skip to content

Commit c86933b

Browse files
committed
Fix parse ddl with newline, close #94
1 parent 455504f commit c86933b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ddlmod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
var (
1515
sqliteSeparator = "`|\"|'|\t"
16-
indexRegexp = regexp.MustCompile(fmt.Sprintf("(?i)CREATE(?: UNIQUE)? INDEX [%v]?[\\w\\d-]+[%v]? ON (.*)$", sqliteSeparator, sqliteSeparator))
17-
tableRegexp = regexp.MustCompile(fmt.Sprintf("(?i)(CREATE TABLE [%v]?[\\w\\d-]+[%v]?)(?: \\((.*)\\))?", sqliteSeparator, sqliteSeparator))
16+
indexRegexp = regexp.MustCompile(fmt.Sprintf("(?is)CREATE(?: UNIQUE)? INDEX [%v]?[\\w\\d-]+[%v]? ON (.*)$", sqliteSeparator, sqliteSeparator))
17+
tableRegexp = regexp.MustCompile(fmt.Sprintf("(?is)(CREATE TABLE [%v]?[\\w\\d-]+[%v]?)(?: \\((.*)\\))?", sqliteSeparator, sqliteSeparator))
1818
separatorRegexp = regexp.MustCompile(fmt.Sprintf("[%v]", sqliteSeparator))
1919
columnsRegexp = regexp.MustCompile(fmt.Sprintf("\\([%v]?([\\w\\d]+)[%v]?(?:,[%v]?([\\w\\d]+)[%v]){0,}\\)", sqliteSeparator, sqliteSeparator, sqliteSeparator, sqliteSeparator))
2020
columnRegexp = regexp.MustCompile(fmt.Sprintf("^[%v]?([\\w\\d]+)[%v]?\\s+([\\w\\(\\)\\d]+)(.*)$", sqliteSeparator, sqliteSeparator))

ddlmod_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@ func TestGetColumns(t *testing.T) {
217217
ddl: "CREATE TABLE Persons (ID int NOT NULL,LastName varchar(255) NOT NULL,FirstName varchar(255),FullName varchar(255) GENERATED ALWAYS AS (FirstName || ' ' || LastName))",
218218
columns: []string{"`ID`", "`LastName`", "`FirstName`"},
219219
},
220+
{
221+
name: "with_new_line",
222+
ddl: `CREATE TABLE "tb_sys_role_menu__temp" (
223+
"id" integer PRIMARY KEY AUTOINCREMENT,
224+
"created_at" datetime NOT NULL,
225+
"updated_at" datetime NOT NULL,
226+
"created_by" integer NOT NULL DEFAULT 0,
227+
"updated_by" integer NOT NULL DEFAULT 0,
228+
"role_id" integer NOT NULL,
229+
"menu_id" bigint NOT NULL
230+
)`,
231+
columns: []string{"`id`", "`created_at`", "`updated_at`", "`created_by`", "`updated_by`", "`role_id`", "`menu_id`"},
232+
},
220233
}
221234

222235
for _, p := range params {

0 commit comments

Comments
 (0)