Skip to content

Commit

Permalink
parser: add support for ALTER DATABASE syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed May 7, 2019
1 parent e336082 commit 02f3aec
Show file tree
Hide file tree
Showing 5 changed files with 5,145 additions and 4,974 deletions.
36 changes: 36 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,42 @@ func (n *CreateDatabaseStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// AlterDatabaseStmt is a statement to change the structure of a database.
// See https://dev.mysql.com/doc/refman/5.7/en/alter-database.html
type AlterDatabaseStmt struct {
ddlNode

Name string
Options []*DatabaseOption
}

// Restore implements Node interface.
func (n *AlterDatabaseStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("ALTER DATABASE")
if n.Name != "" {
ctx.WritePlain(" ")
ctx.WriteName(n.Name)
}
for _, option := range n.Options {
ctx.WritePlain(" ")
err := option.Restore(ctx)
if err != nil {
return errors.Trace(err)
}
}
return nil
}

// Accept implements Node Accept interface.
func (n *AlterDatabaseStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*AlterDatabaseStmt)
return v.Leave(n)
}

// DropDatabaseStmt is a statement to drop a database and all tables in the database.
// See https://dev.mysql.com/doc/refman/5.7/en/drop-database.html
type DropDatabaseStmt struct {
Expand Down
1 change: 1 addition & 0 deletions ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (ts *testDDLSuite) TestDDLVisitorCover(c *C) {
expectedLeaveCnt int
}{
{&CreateDatabaseStmt{}, 0, 0},
{&AlterDatabaseStmt{}, 0, 0},
{&DropDatabaseStmt{}, 0, 0},
{&DropIndexStmt{Table: &TableName{}}, 0, 0},
{&DropTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
Expand Down
Loading

0 comments on commit 02f3aec

Please sign in to comment.