Skip to content

Commit

Permalink
Format MySQL CREATE TABLE options
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Dec 30, 2023
1 parent e6d695c commit bd36338
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/syntax/create_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ export const createTableMap: CstToDocMap<AllCreateTableNodes> = {
],
column_definition: (print) =>
print.spaced(["name", "dataType", "constraints"]),
table_option: (print) => print.spaced(["name"]),
table_option: (print, node) => {
if (node.value && node.hasEq) {
return [print.spaced("name"), " = ", print.spaced("value")];
} else if (node.value) {
return [print.spaced("name"), " ", print.spaced("value")];
} else {
return print.spaced("name");
}
},
create_table_like_clause: (print) => print.spaced(["likeKw", "name"]),
create_table_copy_clause: (print) => print.spaced(["copyKw", "name"]),
create_table_clone_clause: (print) => print.spaced(["cloneKw", "table"]),
Expand Down
12 changes: 12 additions & 0 deletions test/ddl/create_table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ describe("create table", () => {
`);
});

it(`formats MySQL table options`, async () => {
await testMysql(dedent`
CREATE TABLE foo (
id INT
)
AUTOEXTEND_SIZE = 10,
AVG_ROW_LENGTH = 100,
DEFAULT CHARACTER SET latin1,
COMMENT = 'hello'
`);
});

it(`formats single short BigQuery extra CREATE TABLE clause`, async () => {
await testBigquery(dedent`
CREATE TABLE client (
Expand Down

0 comments on commit bd36338

Please sign in to comment.