Skip to content

Commit b249a8c

Browse files
committed
refactor: alter table first with optional column in mysql
1 parent 542cda2 commit b249a8c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pegjs/mysql.pegjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,12 @@ alter_table_stmt
12281228
};
12291229
}
12301230
alter_column_suffix
1231-
= k:('after'i / 'first'i) __ i:column_ref {
1232-
return {
1233-
keyword: k,
1234-
expr: i
1231+
= k:"first"i {
1232+
return { keyword: k };
1233+
}
1234+
/ k:"after"i __ i:column_ref {
1235+
return { keyword: k, expr: i };
12351236
}
1236-
}
12371237
alter_action_list
12381238
= head:alter_action tail:(__ COMMA __ alter_action)* {
12391239
return createList(head, tail);

pegjs/sqlite.pegjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ alter_table_stmt
781781
}
782782

783783
alter_column_suffix
784-
= k:('after'i / 'first'i) __ i:column_ref {
785-
return {
786-
keyword: k,
787-
expr: i
784+
= k:"first"i {
785+
return { keyword: k };
786+
}
787+
/ k:"after"i __ i:column_ref {
788+
return { keyword: k, expr: i };
788789
}
789-
}
790790

791791
alter_action_list
792792
= head:alter_action tail:(__ COMMA __ alter_action)* {

src/alter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ function alterExprToSQL(expr) {
6464
toUpper(prefix),
6565
name && name.trim(),
6666
dataType.filter(hasVal).join(' '),
67-
suffix && `${toUpper(suffix.keyword)}${suffix.expr ? ` ${columnRefToSQL(suffix.expr)}` : ''}`,
6867
]
68+
if (suffix) {
69+
alterArray.push(toUpper(suffix.keyword), suffix.expr && columnRefToSQL(suffix.expr))
70+
}
6971
return alterArray.filter(hasVal).join(' ')
7072
}
7173

0 commit comments

Comments
 (0)