mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sql: add support for table options (#925)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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").
|
||||
|
||||
Reference in New Issue
Block a user