mirror of https://github.com/aldy505/bob.git
chore: fmt
This commit is contained in:
parent
070280bdf7
commit
a891b58ffb
2
bob.go
2
bob.go
|
@ -191,4 +191,4 @@ func CreateIndex(name string) IndexBuilder {
|
|||
// CreateIndexIfNotExists creates an index with CreateIndexBuilder interface, if the index doesn't exists.
|
||||
func CreateIndexIfNotExists(name string) IndexBuilder {
|
||||
return BobStmtBuilder.CreateIndexIfNotExists(name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,18 +10,18 @@ import (
|
|||
type IndexBuilder builder.Builder
|
||||
|
||||
type indexData struct {
|
||||
Unique bool
|
||||
Spatial bool
|
||||
Fulltext bool
|
||||
Name string
|
||||
TableName string
|
||||
Columns []IndexColumn
|
||||
Unique bool
|
||||
Spatial bool
|
||||
Fulltext bool
|
||||
Name string
|
||||
TableName string
|
||||
Columns []IndexColumn
|
||||
IfNotExists bool
|
||||
}
|
||||
|
||||
type IndexColumn struct {
|
||||
Name string
|
||||
Extras []string
|
||||
Name string
|
||||
Extras []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")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var sql strings.Builder
|
||||
|
||||
sql.WriteString("CREATE ")
|
||||
|
@ -121,7 +121,7 @@ func (i *indexData) ToSql() (sqlStr string, args []interface{}, err error) {
|
|||
sql.WriteString("(")
|
||||
sql.WriteString(strings.Join(columns, ", "))
|
||||
sql.WriteString(");")
|
||||
|
||||
|
||||
sqlStr = sql.String()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestCreateIndex_Error(t *testing.T) {
|
|||
t.Fatal("error is not equal to result:", err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
t.Run("without table name", func(t *testing.T) {
|
||||
_, _, err := bob.
|
||||
CreateIndex("name").
|
||||
|
@ -88,4 +88,4 @@ func TestCreateIndex_Error(t *testing.T) {
|
|||
t.Fatal("error is not equal to result:", err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,10 +189,10 @@ func TestUpsert_WithoutReplacePlaceHolder(t *testing.T) {
|
|||
if err != nil {
|
||||
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;"
|
||||
desiredArgs := []interface{}{"john@doe.com", "John Doe", "john@doe.com", "John Does", "john@doe.com"}
|
||||
|
||||
|
||||
if sql != desiredSql {
|
||||
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.Run("SQLite", func(t *testing.T) {
|
||||
sql, args, err := bob.
|
||||
Upsert("users", bob.SQLite).
|
||||
|
@ -223,4 +223,4 @@ func TestUpsert_WithoutReplacePlaceHolder(t *testing.T) {
|
|||
t.Error("args is not the same as result: ", args)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue