Skip to content

Commit 94b12b7

Browse files
authored
update tidb parser (#63)
use the latest PingCAP TiDB parser packages throughout the project
1 parent 03c362e commit 94b12b7

File tree

13 files changed

+66
-87
lines changed

13 files changed

+66
-87
lines changed

element/column.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"strings"
1010

1111
ptypes "github.com/auxten/postgresql-parser/pkg/sql/types"
12-
"github.com/pingcap/parser/ast"
13-
"github.com/pingcap/parser/format"
14-
"github.com/pingcap/parser/types"
12+
"github.com/pingcap/tidb/pkg/parser/ast"
13+
"github.com/pingcap/tidb/pkg/parser/format"
14+
"github.com/pingcap/tidb/pkg/parser/types"
1515
sqlite "github.com/rqlite/sql"
1616
sql_templates "github.com/sunary/sqlize/sql-templates"
1717
)
@@ -42,7 +42,7 @@ type Column struct {
4242
// GetType ...
4343
func (c Column) GetType() byte {
4444
if c.CurrentAttr.MysqlType != nil {
45-
return c.CurrentAttr.MysqlType.Tp
45+
return c.CurrentAttr.MysqlType.GetType()
4646
}
4747

4848
return 0
@@ -244,7 +244,11 @@ func (c Column) pkDefinition(isPrev bool) (string, bool) {
244244
}
245245

246246
_ = opt.Restore(ctx)
247-
strSql += " " + b.String()
247+
optStr := b.String()
248+
if opt.Tp == ast.ColumnOptionDefaultValue {
249+
optStr = strings.ReplaceAll(optStr, "DEFAULT _UTF8MB4", "DEFAULT ")
250+
}
251+
strSql += " " + optStr
248252
}
249253

250254
return strSql, isPrimaryKey

element/index.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import (
66
"fmt"
77
"strings"
88

9-
"github.com/pingcap/parser/ast"
10-
"github.com/pingcap/parser/model"
9+
"github.com/pingcap/tidb/pkg/parser/ast"
1110
)
1211

1312
// Index ...
1413
type Index struct {
1514
Node
1615
Typ ast.IndexKeyType
17-
IndexType model.IndexType
16+
IndexType ast.IndexType
1817
CnsTyp ast.ConstraintType
1918
Columns []string
2019
}

element/migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/binary"
66
"strings"
77

8-
"github.com/pingcap/parser/ast"
8+
"github.com/pingcap/tidb/pkg/parser/ast"
99
sql_templates "github.com/sunary/sqlize/sql-templates"
1010
"github.com/sunary/sqlize/utils"
1111
)

element/table.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99

1010
ptypes "github.com/auxten/postgresql-parser/pkg/sql/types"
11-
"github.com/pingcap/parser/ast"
12-
"github.com/pingcap/parser/types"
11+
"github.com/pingcap/tidb/pkg/parser/ast"
12+
"github.com/pingcap/tidb/pkg/parser/types"
1313
"github.com/sunary/sqlize/utils"
1414
)
1515

@@ -449,9 +449,10 @@ func (t Table) MigrationColumnUp() ([]string, map[string]struct{}) {
449449
strCols := make([]string, 0)
450450
commentCols := make([]string, 0)
451451
for i := range t.Columns {
452-
if t.Columns[i].Action == MigrateAddAction {
452+
switch t.Columns[i].Action {
453+
case MigrateAddAction:
453454
strCols = append(strCols, " "+t.Columns[i].migrationUp("", "", maxIdent)[0])
454-
} else if t.Columns[i].Action == MigrateModifyAction || t.Columns[i].Action == MigrateRenameAction {
455+
case MigrateModifyAction, MigrateRenameAction:
455456
nCol := t.Columns[i]
456457
nCol.Action = MigrateAddAction
457458
strCols = append(strCols, " "+nCol.migrationUp("", "", maxIdent)[0])

export/avro/builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"strconv"
55
"strings"
66

7-
"github.com/pingcap/parser/mysql"
8-
"github.com/pingcap/parser/types"
7+
"github.com/pingcap/tidb/pkg/parser/mysql"
8+
"github.com/pingcap/tidb/pkg/parser/types"
99
"github.com/sunary/sqlize/element"
1010
)
1111

@@ -59,7 +59,7 @@ func getAvroType(col element.Column) interface{} {
5959
"type": "string",
6060
"connect.version": 1,
6161
"connect.parameters": map[string]string{
62-
"allowed": strings.Join(col.CurrentAttr.MysqlType.Elems, ","),
62+
"allowed": strings.Join(col.CurrentAttr.MysqlType.GetElems(), ","),
6363
},
6464
"connect.default": "init",
6565
"connect.name": "io.debezium.data.Enum",
@@ -71,7 +71,7 @@ func getAvroType(col element.Column) interface{} {
7171
return "int"
7272

7373
case types.ETDecimal:
74-
displayFlen, displayDecimal := col.CurrentAttr.MysqlType.Flen, col.CurrentAttr.MysqlType.Decimal
74+
displayFlen, displayDecimal := col.CurrentAttr.MysqlType.GetFlen(), col.CurrentAttr.MysqlType.GetDecimal()
7575
return map[string]interface{}{
7676
"type": "bytes",
7777
"scale": displayDecimal,

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/sunary/sqlize
22

3-
go 1.19
3+
go 1.24.1
44

55
require (
66
github.com/auxten/postgresql-parser v1.0.1
7-
github.com/pingcap/parser v0.0.0-20200623164729-3a18f1e5dceb
7+
github.com/pingcap/tidb/pkg/parser v0.0.0-20250728085548-73284c42b94f
88
github.com/pkg/errors v0.9.1
99
github.com/rqlite/sql v0.0.0-20241111133259-a4122fabb196
1010
)
@@ -24,16 +24,18 @@ require (
2424
github.com/kr/pretty v0.3.1 // indirect
2525
github.com/kr/text v0.2.0 // indirect
2626
github.com/lib/pq v1.10.9 // indirect
27-
github.com/pingcap/errors v0.11.4 // indirect
27+
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee // indirect
28+
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
2829
github.com/pingcap/log v1.1.0 // indirect
2930
github.com/rogpeppe/go-internal v1.12.0 // indirect
3031
github.com/sirupsen/logrus v1.9.3 // indirect
3132
github.com/spf13/pflag v1.0.5 // indirect
33+
go.uber.org/atomic v1.11.0 // indirect
3234
go.uber.org/multierr v1.11.0 // indirect
3335
go.uber.org/zap v1.27.0 // indirect
34-
golang.org/x/sync v0.7.0 // indirect
36+
golang.org/x/sync v0.16.0 // indirect
3537
golang.org/x/sys v0.21.0 // indirect
36-
golang.org/x/text v0.16.0 // indirect
38+
golang.org/x/text v0.27.0 // indirect
3739
google.golang.org/genproto v0.0.0-20240617180043-68d350f18fd4 // indirect
3840
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
3941
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect

0 commit comments

Comments
 (0)