Skip to content

Commit

Permalink
Merge pull request #2234 from taozhi8833998/refactor-alter-table-firs…
Browse files Browse the repository at this point in the history
…t-mysql

refactor: alter table first with optional column in mysql
  • Loading branch information
taozhi8833998 authored Nov 26, 2024
2 parents 542cda2 + b249a8c commit 527ae05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,12 +1228,12 @@ alter_table_stmt
};
}
alter_column_suffix
= k:('after'i / 'first'i) __ i:column_ref {
return {
keyword: k,
expr: i
= k:"first"i {
return { keyword: k };
}
/ k:"after"i __ i:column_ref {
return { keyword: k, expr: i };
}
}
alter_action_list
= head:alter_action tail:(__ COMMA __ alter_action)* {
return createList(head, tail);
Expand Down
10 changes: 5 additions & 5 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,12 @@ alter_table_stmt
}

alter_column_suffix
= k:('after'i / 'first'i) __ i:column_ref {
return {
keyword: k,
expr: i
= k:"first"i {
return { keyword: k };
}
/ k:"after"i __ i:column_ref {
return { keyword: k, expr: i };
}
}

alter_action_list
= head:alter_action tail:(__ COMMA __ alter_action)* {
Expand Down
4 changes: 3 additions & 1 deletion src/alter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ function alterExprToSQL(expr) {
toUpper(prefix),
name && name.trim(),
dataType.filter(hasVal).join(' '),
suffix && `${toUpper(suffix.keyword)}${suffix.expr ? ` ${columnRefToSQL(suffix.expr)}` : ''}`,
]
if (suffix) {
alterArray.push(toUpper(suffix.keyword), suffix.expr && columnRefToSQL(suffix.expr))
}
return alterArray.filter(hasVal).join(' ')
}

Expand Down

0 comments on commit 527ae05

Please sign in to comment.