From bd363382e4598f7df8c10330675ac63a37163be9 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sat, 30 Dec 2023 22:28:58 +0200 Subject: [PATCH] Format MySQL CREATE TABLE options --- src/syntax/create_table.ts | 10 +++++++++- test/ddl/create_table.test.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/syntax/create_table.ts b/src/syntax/create_table.ts index 6aef0be..44b3e50 100644 --- a/src/syntax/create_table.ts +++ b/src/syntax/create_table.ts @@ -22,7 +22,15 @@ export const createTableMap: CstToDocMap = { ], 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"]), diff --git a/test/ddl/create_table.test.ts b/test/ddl/create_table.test.ts index 1a3c8d8..f50f79f 100644 --- a/test/ddl/create_table.test.ts +++ b/test/ddl/create_table.test.ts @@ -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 (