diff --git a/dialect/sql/builder.go b/dialect/sql/builder.go index 6e16ae0b2..6c4fb4fa7 100644 --- a/dialect/sql/builder.go +++ b/dialect/sql/builder.go @@ -95,6 +95,7 @@ type TableBuilder struct { exists bool // check existence. charset string // table charset. collation string // table collation. + options string // table options. columns []Querier // table columns. primary []string // primary key. constraints []Querier // foreign keys and indices. @@ -172,6 +173,12 @@ func (t *TableBuilder) Collate(s string) *TableBuilder { return t } +// Options appends additional options to to the statement (MySQL only). +func (t *TableBuilder) Options(s string) *TableBuilder { + t.options = s + return t +} + // Query returns query representation of a `CREATE TABLE` statement. // // CREATE TABLE [IF NOT EXISTS] name @@ -202,6 +209,9 @@ func (t *TableBuilder) Query() (string, []interface{}) { if t.collation != "" { t.WriteString(" COLLATE " + t.collation) } + if t.options != "" { + t.WriteString(" " + t.options) + } return t.String(), t.args } diff --git a/dialect/sql/builder_test.go b/dialect/sql/builder_test.go index f3dfeb809..860cda16b 100644 --- a/dialect/sql/builder_test.go +++ b/dialect/sql/builder_test.go @@ -59,8 +59,9 @@ func TestBuilder(t *testing.T) { ). PrimaryKey("id"). Charset("utf8mb4"). - Collate("utf8mb4_general_ci"), - wantQuery: "CREATE TABLE `users`(`id` int auto_increment, `name` varchar(255), PRIMARY KEY(`id`)) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci", + Collate("utf8mb4_general_ci"). + Options("ENGINE=InnoDB"), + wantQuery: "CREATE TABLE `users`(`id` int auto_increment, `name` varchar(255), PRIMARY KEY(`id`)) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ENGINE=InnoDB", }, { input: CreateTable("users").