flavor_test.go 804 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018 Huan Du. All rights reserved.
  2. // Licensed under the MIT license that can be found in the LICENSE file.
  3. package sqlbuilder
  4. import (
  5. "fmt"
  6. "testing"
  7. )
  8. func TestFlavor(t *testing.T) {
  9. cases := map[Flavor]string{
  10. 0: "<invalid>",
  11. MySQL: "MySQL",
  12. PostgreSQL: "PostgreSQL",
  13. }
  14. for f, expected := range cases {
  15. if actual := f.String(); actual != expected {
  16. t.Fatalf("invalid flavor name. [expected:%v] [actual:%v]", expected, actual)
  17. }
  18. }
  19. }
  20. func ExampleFlavor() {
  21. // Create a flavored builder.
  22. sb := PostgreSQL.NewSelectBuilder()
  23. sb.Select("name").From("user").Where(
  24. sb.E("id", 1234),
  25. sb.G("rank", 3),
  26. )
  27. sql, args := sb.Build()
  28. fmt.Println(sql)
  29. fmt.Println(args)
  30. // Output:
  31. // SELECT name FROM user WHERE id = $1 AND rank > $2
  32. // [1234 3]
  33. }