chore: fmt

This commit is contained in:
Reinaldy Rafli 2021-11-09 12:16:31 +07:00
parent 070280bdf7
commit a891b58ffb
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
4 changed files with 18 additions and 18 deletions

2
bob.go
View File

@ -191,4 +191,4 @@ func CreateIndex(name string) IndexBuilder {
// CreateIndexIfNotExists creates an index with CreateIndexBuilder interface, if the index doesn't exists. // CreateIndexIfNotExists creates an index with CreateIndexBuilder interface, if the index doesn't exists.
func CreateIndexIfNotExists(name string) IndexBuilder { func CreateIndexIfNotExists(name string) IndexBuilder {
return BobStmtBuilder.CreateIndexIfNotExists(name) return BobStmtBuilder.CreateIndexIfNotExists(name)
} }

View File

@ -10,18 +10,18 @@ import (
type IndexBuilder builder.Builder type IndexBuilder builder.Builder
type indexData struct { type indexData struct {
Unique bool Unique bool
Spatial bool Spatial bool
Fulltext bool Fulltext bool
Name string Name string
TableName string TableName string
Columns []IndexColumn Columns []IndexColumn
IfNotExists bool IfNotExists bool
} }
type IndexColumn struct { type IndexColumn struct {
Name string Name string
Extras []string Extras []string
Collate string Collate string
} }
@ -76,7 +76,7 @@ func (i *indexData) ToSql() (sqlStr string, args []interface{}, err error) {
err = errors.New("should at least specify one column for create index statement") err = errors.New("should at least specify one column for create index statement")
return return
} }
var sql strings.Builder var sql strings.Builder
sql.WriteString("CREATE ") sql.WriteString("CREATE ")
@ -121,7 +121,7 @@ func (i *indexData) ToSql() (sqlStr string, args []interface{}, err error) {
sql.WriteString("(") sql.WriteString("(")
sql.WriteString(strings.Join(columns, ", ")) sql.WriteString(strings.Join(columns, ", "))
sql.WriteString(");") sql.WriteString(");")
sqlStr = sql.String() sqlStr = sql.String()
return return
} }

View File

@ -58,7 +58,7 @@ func TestCreateIndex_Error(t *testing.T) {
t.Fatal("error is not equal to result:", err.Error()) t.Fatal("error is not equal to result:", err.Error())
} }
}) })
t.Run("without table name", func(t *testing.T) { t.Run("without table name", func(t *testing.T) {
_, _, err := bob. _, _, err := bob.
CreateIndex("name"). CreateIndex("name").
@ -88,4 +88,4 @@ func TestCreateIndex_Error(t *testing.T) {
t.Fatal("error is not equal to result:", err.Error()) t.Fatal("error is not equal to result:", err.Error())
} }
}) })
} }

View File

@ -189,10 +189,10 @@ func TestUpsert_WithoutReplacePlaceHolder(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
desiredSql := "IF NOT EXISTS (SELECT * FROM \"users\" WHERE \"email\" = @p1) INSERT INTO \"users\" (\"name\", \"email\") VALUES (@p2, @p3) ELSE UPDATE \"users\" SET \"name\" = @p4 WHERE \"email\" = @p5;" desiredSql := "IF NOT EXISTS (SELECT * FROM \"users\" WHERE \"email\" = @p1) INSERT INTO \"users\" (\"name\", \"email\") VALUES (@p2, @p3) ELSE UPDATE \"users\" SET \"name\" = @p4 WHERE \"email\" = @p5;"
desiredArgs := []interface{}{"john@doe.com", "John Doe", "john@doe.com", "John Does", "john@doe.com"} desiredArgs := []interface{}{"john@doe.com", "John Doe", "john@doe.com", "John Does", "john@doe.com"}
if sql != desiredSql { if sql != desiredSql {
t.Error("sql is not the same as result: ", sql) t.Error("sql is not the same as result: ", sql)
} }
@ -200,7 +200,7 @@ func TestUpsert_WithoutReplacePlaceHolder(t *testing.T) {
t.Error("args is not the same as result: ", args) t.Error("args is not the same as result: ", args)
} }
}) })
t.Run("SQLite", func(t *testing.T) { t.Run("SQLite", func(t *testing.T) {
sql, args, err := bob. sql, args, err := bob.
Upsert("users", bob.SQLite). Upsert("users", bob.SQLite).
@ -223,4 +223,4 @@ func TestUpsert_WithoutReplacePlaceHolder(t *testing.T) {
t.Error("args is not the same as result: ", args) t.Error("args is not the same as result: ", args)
} }
}) })
} }