Skip to content

Commit

Permalink
back quotationからdouble quotationへ変更
Browse files Browse the repository at this point in the history
  • Loading branch information
flat35hd99 committed Apr 29, 2024
1 parent 23d02d5 commit d49f298
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion group_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func newGroupByClause(columnName string) groupByClause {
}

func (clause groupByClause) String() string {
return fmt.Sprintf("GROUP BY `%s`", clause.columnName)
return fmt.Sprintf(`GROUP BY "%s"`, clause.columnName)
}
6 changes: 3 additions & 3 deletions select_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Column struct {
}

func (c Column) String() string {
return fmt.Sprintf("`%s`", c.V)
return fmt.Sprintf(`"%s"`, c.V)
}

func newSelectExpressions(exps ...SelectExpression) selectExpressions {
Expand All @@ -47,9 +47,9 @@ type Count struct {

func (c Count) String() string {
if c.aliasName == "" {
return fmt.Sprintf("COUNT(`%s`)", c.columnName)
return fmt.Sprintf(`COUNT("%s")`, c.columnName)
} else {
return fmt.Sprintf("COUNT(`%s`) AS `%s`", c.columnName, c.aliasName)
return fmt.Sprintf(`COUNT("%s") AS "%s"`, c.columnName, c.aliasName)
}
}

Expand Down
28 changes: 14 additions & 14 deletions select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,64 @@ import (
)

func TestSelect(t *testing.T) {
t.Run("SELECT * FROM `users` WHERE `id` = 1;", func(t *testing.T) {
t.Run(`SELECT * FROM "users" WHERE "id" = 1;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 1}).From("users").ToSQL()

expected := "SELECT * FROM `users` WHERE `id` = 1;"
expected := `SELECT * FROM "users" WHERE "id" = 1;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT * FROM `users` WHERE `id` = 2;", func(t *testing.T) {
t.Run(`SELECT * FROM "users" WHERE "id" = 2;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 2}).From("users").ToSQL()

expected := "SELECT * FROM `users` WHERE `id` = 2;"
expected := `SELECT * FROM "users" WHERE "id" = 2;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT * FROM `todos` WHERE `id` = 2;", func(t *testing.T) {
t.Run(`SELECT * FROM "todos" WHERE "id" = 2;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 2}).From("todos").ToSQL()

expected := "SELECT * FROM `todos` WHERE `id` = 2;"
expected := `SELECT * FROM "todos" WHERE "id" = 2;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT * FROM `todos` WHERE `id` = 2 LIMIT 1;", func(t *testing.T) {
t.Run(`SELECT * FROM "todos" WHERE "id" = 2 LIMIT 1;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 2}).From("todos").Limit(1).ToSQL()

expected := "SELECT * FROM `todos` WHERE `id` = 2 LIMIT 1;"
expected := `SELECT * FROM "todos" WHERE "id" = 2 LIMIT 1;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT `id` FROM `users` WHERE `id` = 1;", func(t *testing.T) {
t.Run(`SELECT "id" FROM "users" WHERE "id" = 1;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 1}).Select(gooqu.Column{"id"}).From("users").ToSQL()

expected := "SELECT `id` FROM `users` WHERE `id` = 1;"
expected := `SELECT "id" FROM "users" WHERE "id" = 1;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT `id`, `name` FROM `users` WHERE `id` = 1;", func(t *testing.T) {
t.Run(`SELECT "id", "name" FROM "users" WHERE "id" = 1;`, func(t *testing.T) {
query := gooqu.Where(gooqu.Record{"id": 1}).Select(gooqu.Column{"id"}, gooqu.Column{"name"}).From("users").ToSQL()

expected := "SELECT `id`, `name` FROM `users` WHERE `id` = 1;"
expected := `SELECT "id", "name" FROM "users" WHERE "id" = 1;`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
})

t.Run("SELECT COUNT(`id`), `name` FROM `users` GROUP BY `age`;", func(t *testing.T) {
t.Run(`SELECT COUNT("id") FROM "users" GROUP BY "age";`, func(t *testing.T) {
query := gooqu.Select(gooqu.COUNT("id").As("count")).From("users").GroupBy("age").ToSQL()

expected := "SELECT COUNT(`id`) AS `count` FROM `users` GROUP BY `age`;"
expected := `SELECT COUNT("id") AS "count" FROM "users" GROUP BY "age";`
if query != expected {
t.Errorf("expected %s but got %s", expected, query)
}
Expand Down
2 changes: 1 addition & 1 deletion table_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func newTableReferences(tableName string) tableReferences {
}

func (tr tableReferences) String() string {
return fmt.Sprintf("`%s`", tr.tableName)
return fmt.Sprintf(`"%s"`, tr.tableName)
}
6 changes: 3 additions & 3 deletions where_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func (expr expression) String() string {
var columnValue string
switch v := expr.columnValue.(type) {
case string:
columnValue = fmt.Sprintf("`%s`", v)
columnValue = fmt.Sprintf(`"%s"`, v)
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
columnValue = fmt.Sprintf("%d", v)
case float32, float64:
columnValue = fmt.Sprintf("%f", v)
default:
columnValue = fmt.Sprintf("`%v`", v)
columnValue = fmt.Sprintf(`"%v"`, v)
}
return fmt.Sprintf("`%s` = %s", expr.columnName, columnValue)
return fmt.Sprintf(`"%s" = %s`, expr.columnName, columnValue)
}

0 comments on commit d49f298

Please sign in to comment.