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.
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue