Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 8d42337

Browse files
author
kuba--
committed
Support SQLAlchemy syntax for show create table
Signed-off-by: kuba-- <[email protected]>
1 parent f33e6ea commit 8d42337

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sql/plan/show_create_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func produceCreateStatement(table sql.Table) string {
8989

9090
// Statement creation parts for each column
9191
for indx, col := range schema {
92-
createStmtPart := fmt.Sprintf("`%s` %s", col.Name, col.Type.Type())
92+
createStmtPart := fmt.Sprintf(" `%s` %s", col.Name, col.Type.Type())
9393

9494
if !col.Nullable {
9595
createStmtPart = fmt.Sprintf("%s NOT NULL", createStmtPart)
@@ -111,7 +111,7 @@ func produceCreateStatement(table sql.Table) string {
111111

112112
prettyColCreateStmts := strings.Join(colCreateStatements, ",\n")
113113
composedCreateTableStatement :=
114-
fmt.Sprintf("CREATE TABLE `%s` (%s) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", table.Name(), prettyColCreateStmts)
114+
fmt.Sprintf("CREATE TABLE `%s` (\n%s\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", table.Name(), prettyColCreateStmts)
115115

116116
return composedCreateTableStatement
117117
}

sql/plan/show_create_table_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func TestShowCreateTable(t *testing.T) {
3737

3838
expected := sql.NewRow(
3939
table.Name(),
40-
"CREATE TABLE `test-table` (`baz` TEXT NOT NULL,\n"+
41-
"`zab` INT32 DEFAULT 0,\n"+
42-
"`bza` INT64 DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
40+
"CREATE TABLE `test-table` (\n `baz` TEXT NOT NULL,\n"+
41+
" `zab` INT32 DEFAULT 0,\n"+
42+
" `bza` INT64 DEFAULT 0\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
4343
)
4444

4545
require.Equal(expected, row)

0 commit comments

Comments
 (0)