forked from huandu/go-sqlbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flavor_test.go
43 lines (35 loc) · 948 Bytes
/
flavor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2018 Huan Du. All rights reserved.
// Copyright 2022 OOO SuperJob. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package sphinxql
import (
"fmt"
"testing"
"github.com/huandu/go-assert"
)
func TestFlavor(t *testing.T) {
a := assert.New(t)
cases := map[Flavor]string{
0: "<invalid>",
SphinxSearch: "SphinxSearch",
}
for f, expected := range cases {
actual := f.String()
a.Equal(actual, expected)
}
}
func ExampleFlavor_Interpolate_sphinxSearch() {
sb := SphinxSearch.NewSelectBuilder()
sb.Select("name").From("user").Where(
sb.NE("id", 1234),
sb.E("name", "Charmy Liu"),
sb.Like("desc", "%mother's day%"),
)
sql, args := sb.Build()
query, err := SphinxSearch.Interpolate(sql, args)
fmt.Println(query)
fmt.Println(err)
// Output:
// SELECT name FROM user WHERE id <> 1234 AND name = 'Charmy Liu' AND desc LIKE '%mother\'s day%'
// <nil>
}