Skip to content

Commit ef78c0b

Browse files
author
Reinaldy Rafli
committed
fix(breaking): ToSQL > ToSql for compat with Squirrel
1 parent e675c80 commit ef78c0b

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
db := pgx.Connect()
2525

2626
// Check if a table is exists
27-
sql, args, err = bob.HasTable("users").PlaceholderFormat(bob.Dollar).ToSQL()
27+
sql, args, err = bob.HasTable("users").PlaceholderFormat(bob.Dollar).ToSql()
2828
if err != nil {
2929
log.Fatal(err)
3030
}
@@ -47,7 +47,7 @@ func main() {
4747
Types("varchar(36)", "varchar(255)", "varchar(255)", "text", "date").
4848
Primary("id").
4949
Unique("email")
50-
ToSQL()
50+
ToSql()
5151
if err != nil {
5252
log.Fatal(err)
5353
}

bob.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import "github.com/lann/builder"
55
// BobBuilderType is the type for BobBuilder
66
type BobBuilderType builder.Builder
77

8-
// BobBuilder interface wraps the ToSQL method
8+
// BobBuilder interface wraps the ToSql method
99
type BobBuilder interface {
10-
ToSQL() (string, []interface{}, error)
10+
ToSql() (string, []interface{}, error)
1111
}
1212

1313
// CreateTable creates a table with CreateBuilder interface

create.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func (b CreateBuilder) Unique(column string) CreateBuilder {
6161
return builder.Set(b, "Unique", column).(CreateBuilder)
6262
}
6363

64-
// ToSQL returns 3 variables filled out with the correct values based on bindings, etc.
65-
func (b CreateBuilder) ToSQL() (string, []interface{}, error) {
64+
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
65+
func (b CreateBuilder) ToSql() (string, []interface{}, error) {
6666
data := builder.GetStruct(b).(createData)
67-
return data.ToSQL()
67+
return data.ToSql()
6868
}
6969

70-
// ToSQL returns 3 variables filled out with the correct values based on bindings, etc.
71-
func (d *createData) ToSQL() (sqlStr string, args []interface{}, err error) {
70+
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
71+
func (d *createData) ToSql() (sqlStr string, args []interface{}, err error) {
7272
if len(d.TableName) == 0 || d.TableName == "" {
7373
err = errors.New("create statements must specify a table")
7474
return

create_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func TestCreate(t *testing.T) {
1010
t.Run("should return correct sql string with basic columns and types", func(t *testing.T) {
11-
sql, _, err := bob.CreateTable("users").Columns("name", "password", "date").Types("varchar(255)", "text", "date").ToSQL()
11+
sql, _, err := bob.CreateTable("users").Columns("name", "password", "date").Types("varchar(255)", "text", "date").ToSql()
1212
if err != nil {
1313
t.Fatal(err.Error())
1414
}
@@ -24,7 +24,7 @@ func TestCreate(t *testing.T) {
2424
Types("uuid", "varchar(255)", "varchar(255)", "text", "date").
2525
Primary("id").
2626
Unique("email").
27-
ToSQL()
27+
ToSql()
2828
if err != nil {
2929
t.Fatal(err.Error())
3030
}
@@ -35,7 +35,7 @@ func TestCreate(t *testing.T) {
3535
})
3636

3737
t.Run("should be able to have a schema name", func(t *testing.T) {
38-
sql, _, err := bob.CreateTable("users").WithSchema("private").Columns("name", "password", "date").Types("varchar(255)", "text", "date").ToSQL()
38+
sql, _, err := bob.CreateTable("users").WithSchema("private").Columns("name", "password", "date").Types("varchar(255)", "text", "date").ToSql()
3939
if err != nil {
4040
t.Fatal(err.Error())
4141
}
@@ -49,35 +49,35 @@ func TestCreate(t *testing.T) {
4949
_, _, err := bob.CreateTable("users").
5050
Columns("id", "name", "email", "password", "date").
5151
Types("uuid", "varchar(255)", "varchar(255)", "date").
52-
ToSQL()
52+
ToSql()
5353
if err.Error() != "columns and types should have equal length" {
5454
t.Fatal("should throw an error, it didn't:", err.Error())
5555
}
5656
})
5757

5858
t.Run("should emit error on empty table name", func(t *testing.T) {
59-
_, _, err := bob.CreateTable("").Columns("name").Types("text").ToSQL()
59+
_, _, err := bob.CreateTable("").Columns("name").Types("text").ToSql()
6060
if err.Error() != "create statements must specify a table" {
6161
t.Fatal("should throw an error, it didn't:", err.Error())
6262
}
6363
})
6464

6565
t.Run("should emit error for primary key not in columns", func(t *testing.T) {
66-
_, _, err := bob.CreateTable("users").Columns("name").Types("text").Primary("id").ToSQL()
66+
_, _, err := bob.CreateTable("users").Columns("name").Types("text").Primary("id").ToSql()
6767
if err.Error() != "supplied primary column name doesn't exists on columns" {
6868
t.Fatal("should throw an error, it didn't:", err.Error())
6969
}
7070
})
7171

7272
t.Run("should emit error for unique key not in columns", func(t *testing.T) {
73-
_, _, err := bob.CreateTable("users").Columns("name").Types("text").Unique("id").ToSQL()
73+
_, _, err := bob.CreateTable("users").Columns("name").Types("text").Unique("id").ToSql()
7474
if err.Error() != "supplied unique column name doesn't exists on columns" {
7575
t.Fatal("should throw an error, it didn't:", err.Error())
7676
}
7777
})
7878

7979
t.Run("should emit create if not exists", func(t *testing.T) {
80-
sql, _, err := bob.CreateTableIfNotExists("users").Columns("name").Types("text").ToSQL()
80+
sql, _, err := bob.CreateTableIfNotExists("users").Columns("name").Types("text").ToSql()
8181
if err != nil {
8282
t.Fatal(err.Error())
8383
}

has.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func (h HasBuilder) PlaceholderFormat(f string) HasBuilder {
4444
return builder.Set(h, "Placeholder", f).(HasBuilder)
4545
}
4646

47-
// ToSQL returns 3 variables filled out with the correct values based on bindings, etc.
48-
func (h HasBuilder) ToSQL() (string, []interface{}, error) {
47+
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
48+
func (h HasBuilder) ToSql() (string, []interface{}, error) {
4949
data := builder.GetStruct(h).(hasData)
50-
return data.ToSQL()
50+
return data.ToSql()
5151
}
5252

53-
// ToSQL returns 3 variables filled out with the correct values based on bindings, etc.
54-
func (d *hasData) ToSQL() (sqlStr string, args []interface{}, err error) {
53+
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
54+
func (d *hasData) ToSql() (sqlStr string, args []interface{}, err error) {
5555
sql := &bytes.Buffer{}
5656
if d.Name == "" {
5757
err = errors.New("has statement should have a table name")

has_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestHas(t *testing.T) {
1212
t.Run("should be able to create a hasTable query", func(t *testing.T) {
13-
sql, args, err := bob.HasTable("users").ToSQL()
13+
sql, args, err := bob.HasTable("users").ToSql()
1414
if err != nil {
1515
t.Fatal(err.Error())
1616
}
@@ -26,7 +26,7 @@ func TestHas(t *testing.T) {
2626
})
2727

2828
t.Run("should be able to create a hasColumn query", func(t *testing.T) {
29-
sql, args, err := bob.HasTable("users").HasColumn("name").ToSQL()
29+
sql, args, err := bob.HasTable("users").HasColumn("name").ToSql()
3030
if err != nil {
3131
t.Fatal(err.Error())
3232
}
@@ -42,7 +42,7 @@ func TestHas(t *testing.T) {
4242
})
4343

4444
t.Run("should be able to create a hasColumn query (but reversed)", func(t *testing.T) {
45-
sql, args, err := bob.HasColumn("name").HasTable("users").ToSQL()
45+
sql, args, err := bob.HasColumn("name").HasTable("users").ToSql()
4646
if err != nil {
4747
t.Fatal(err.Error())
4848
}
@@ -58,7 +58,7 @@ func TestHas(t *testing.T) {
5858
})
5959

6060
t.Run("should be able to create a hasTable query with schema", func(t *testing.T) {
61-
sql, args, err := bob.HasTable("users").WithSchema("private").ToSQL()
61+
sql, args, err := bob.HasTable("users").WithSchema("private").ToSql()
6262
if err != nil {
6363
t.Fatal(err.Error())
6464
}
@@ -74,7 +74,7 @@ func TestHas(t *testing.T) {
7474
})
7575

7676
t.Run("should be able to have a different placeholder", func(t *testing.T) {
77-
sql, args, err := bob.HasTable("users").HasColumn("name").PlaceholderFormat(bob.Dollar).ToSQL()
77+
sql, args, err := bob.HasTable("users").HasColumn("name").PlaceholderFormat(bob.Dollar).ToSql()
7878
if err != nil {
7979
t.Fatal(err.Error())
8080
}
@@ -90,7 +90,7 @@ func TestHas(t *testing.T) {
9090
})
9191

9292
t.Run("should expect an error for no table name", func(t *testing.T) {
93-
_, _, err := bob.HasTable("").ToSQL()
93+
_, _, err := bob.HasTable("").ToSql()
9494
if err.Error() != "has statement should have a table name" {
9595
t.Fatal("error is different:", err.Error())
9696
}

0 commit comments

Comments
 (0)