Skip to content

Commit

Permalink
revert: "feat(BREAKING): accept only positive values for VARCHAR length"
Browse files Browse the repository at this point in the history
This reverts commit 6003beb.
  • Loading branch information
bevzzz committed Dec 29, 2022
1 parent 2c350a3 commit 36e43ae
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dialect/mssqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (*Dialect) AppendBool(b []byte, v bool) []byte {
return strconv.AppendUint(b, uint64(num), 10)
}

func (d *Dialect) DefaultVarcharLen() uint {
func (d *Dialect) DefaultVarcharLen() int {
return 255
}

Expand Down
2 changes: 1 addition & 1 deletion dialect/mysqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (*Dialect) AppendJSON(b, jsonb []byte) []byte {
return b
}

func (d *Dialect) DefaultVarcharLen() uint {
func (d *Dialect) DefaultVarcharLen() int {
return 255
}

Expand Down
2 changes: 1 addition & 1 deletion dialect/pgdialect/sqltype.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem()
)

func (d *Dialect) DefaultVarcharLen() uint {
func (d *Dialect) DefaultVarcharLen() int {
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion dialect/sqlitedialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (d *Dialect) AppendBytes(b []byte, bs []byte) []byte {
return b
}

func (d *Dialect) DefaultVarcharLen() uint {
func (d *Dialect) DefaultVarcharLen() int {
return 0
}

Expand Down
5 changes: 5 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
6 changes: 3 additions & 3 deletions query_table_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type CreateTableQuery struct {

temp bool
ifNotExists bool

// varchar changes the default length for VARCHAR columns.
// Because some dialects require that length is always specified for VARCHAR type,
// we will use the exact user-defined type if length is set explicitly, as in `bun:",type:varchar(5)"`,
// but assume the new default length when it's omitted, e.g. `bun:",type:varchar"`.
varchar uint
varchar int

fks []schema.QueryWithArgs
partitionBy schema.QueryWithArgs
Expand Down Expand Up @@ -90,7 +90,7 @@ func (q *CreateTableQuery) IfNotExists() *CreateTableQuery {
}

// Varchar sets default length for VARCHAR columns.
func (q *CreateTableQuery) Varchar(n uint) *CreateTableQuery {
func (q *CreateTableQuery) Varchar(n int) *CreateTableQuery {
q.varchar = n
return q
}
Expand Down
4 changes: 2 additions & 2 deletions schema/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Dialect interface {
// DefaultVarcharLen should be returned for dialects in which specifying VARCHAR length
// is mandatory in queries that modify the schema (CREATE TABLE / ADD COLUMN, etc).
// Dialects that do not have such requirement may return 0, which should be interpreted so by the caller.
DefaultVarcharLen() uint
DefaultVarcharLen() int
}

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -174,6 +174,6 @@ func (d *nopDialect) IdentQuote() byte {
return '"'
}

func (d *nopDialect) DefaultVarcharLen() uint {
func (d *nopDialect) DefaultVarcharLen() int {
return 0
}

0 comments on commit 36e43ae

Please sign in to comment.