Skip to content

Commit

Permalink
feat: implement drop-trigger statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Jun 24, 2022
1 parent bc9df35 commit d19dbb8
Show file tree
Hide file tree
Showing 21 changed files with 6,753 additions and 6,685 deletions.
33 changes: 33 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package ast

import (
"github.com/pingcap/errors"

"github.com/arana-db/parser/auth"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
Expand All @@ -35,6 +36,7 @@ var (
_ DDLNode = &CreateSequenceStmt{}
_ DDLNode = &CreatePlacementPolicyStmt{}
_ DDLNode = &DropDatabaseStmt{}
_ DDLNode = &DropTriggerStmt{}
_ DDLNode = &DropIndexStmt{}
_ DDLNode = &DropTableStmt{}
_ DDLNode = &DropSequenceStmt{}
Expand Down Expand Up @@ -221,6 +223,37 @@ func (n *AlterDatabaseStmt) isAllPlacementOptions() bool {
return true
}

// DropTriggerStmt is a statement to drop a trigger in the database.
// See https://dev.mysql.com/doc/refman/5.7/en/drop-trigger.html
type DropTriggerStmt struct {
ddlNode

IfExists bool
Trigger *TableName
}

// Restore implements Node interface.
func (n *DropTriggerStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("DROP TRIGGER ")
if n.IfExists {
ctx.WriteKeyWord("IF EXISTS ")
}
if err := n.Trigger.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing DropTriggerStmt")
}
return nil
}

// Accept implements Node Accept interface.
func (n *DropTriggerStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*DropTriggerStmt)
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 @@ -36,6 +36,7 @@ func TestDDLVisitorCover(t *testing.T) {
{&CreateDatabaseStmt{}, 0, 0},
{&AlterDatabaseStmt{}, 0, 0},
{&DropDatabaseStmt{}, 0, 0},
{&DropTriggerStmt{}, 0, 0},
{&DropIndexStmt{Table: &TableName{}}, 0, 0},
{&DropTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
{&RenameTableStmt{TableToTables: []*TableToTable{}}, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package ast
import (
"strings"

"github.com/pingcap/errors"
"github.com/arana-db/parser/auth"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
"github.com/arana-db/parser/mysql"
"github.com/pingcap/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"regexp"
"strings"

"github.com/pingcap/errors"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
"github.com/arana-db/parser/opcode"
"github.com/pingcap/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"strings"
"time"

"github.com/pingcap/errors"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
"github.com/arana-db/parser/types"
"github.com/pingcap/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"strconv"
"strings"

"github.com/pingcap/errors"
"github.com/arana-db/parser/auth"
"github.com/arana-db/parser/charset"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
"github.com/arana-db/parser/mysql"
"github.com/pingcap/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion ast/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
package ast

import (
"github.com/pingcap/errors"
"github.com/arana-db/parser/format"
"github.com/arana-db/parser/model"
"github.com/pingcap/errors"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion auth/mysql_native_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"encoding/hex"
"fmt"

"github.com/pingcap/errors"
"github.com/arana-db/parser/terror"
"github.com/pingcap/errors"
)

// CheckScrambledPassword check scrambled password received from client.
Expand Down
4 changes: 2 additions & 2 deletions charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"sort"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/arana-db/parser/mysql"
"github.com/arana-db/parser/terror"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"go.uber.org/zap"
)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
go 1.13

module github.com/arana-db/parser

require (
Expand All @@ -14,5 +16,3 @@ require (
modernc.org/parser v1.0.2
modernc.org/y v1.0.1
)

go 1.13
2 changes: 1 addition & 1 deletion goyacc/format_yacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"regexp"
"strings"

"github.com/arana-db/parser/format"
"github.com/cznic/strutil"
"github.com/pingcap/errors"
"github.com/arana-db/parser/format"
parser "modernc.org/parser/yacc"
)

Expand Down
2 changes: 1 addition & 1 deletion model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"sync"
"time"

"github.com/pingcap/errors"
"github.com/arana-db/parser/mysql"
"github.com/arana-db/parser/terror"
"github.com/pingcap/errors"
)

// ActionType is the type for DDL action.
Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"strings"
"time"

"github.com/pingcap/errors"
"github.com/arana-db/parser/auth"
"github.com/arana-db/parser/charset"
"github.com/arana-db/parser/mysql"
"github.com/arana-db/parser/types"
"github.com/pingcap/errors"
)

// SchemaState is the state for schema elements.
Expand Down
1 change: 1 addition & 0 deletions mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/pingcap/errors"

"github.com/arana-db/parser/format"
)

Expand Down
Loading

0 comments on commit d19dbb8

Please sign in to comment.