-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsql_test.go
118 lines (106 loc) · 3.54 KB
/
gsql_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2021 BlueStorm
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package gsql
import (
"database/sql"
"testing"
)
var serve = NewDrive(MySql, func() (db *sql.DB, err error) {
return
}).Config(50, 60)
type options struct {
Id int `json:"id,string" sql:"primary key,auto_increment 1000"`
Text string `json:",string" sql:"varchar(20) default null"`
Value string
}
func TestCount(t *testing.T) {
option := &options{Id: 1, Text: "test"}
orm := serve.NewStruct("table_options", option)
command, values := orm.Count().Where("Id=?").GetSQL()
command, values = orm.Select().Where("Id=?").GetSQL()
t.Log("[", orm.Id, "]")
t.Log("[", command, "]")
for k, v := range values {
t.Log("[", k, "=", v.Val, "]", v.Tag)
}
}
func TestSelect(t *testing.T) {
option := &options{Id: 1, Text: "test"}
orm := serve.NewStruct("table_options", option)
command, values := orm.Select("*").Where("Id=?", "Text=?").OrderBy("id desc").Page(20, 1).GetSQL()
t.Log("[", orm.Id, "]")
t.Log("[", command, "]")
for k, v := range values {
t.Log("[", k, "=", v.Val, "]", v.Tag)
}
}
func TestGroup(t *testing.T) {
option := &options{Id: 1, Text: "test"}
orm := serve.NewStruct("table_options", option)
command, values := orm.Select("*").Where("Id=?").GroupBy("Text").GetSQL()
t.Log("[", orm.Id, "]")
t.Log("[", command, "]")
for k, v := range values {
t.Log("[", k, "=", v.Val, "]", v.Tag)
}
}
func TestInsert(t *testing.T) {
option := &options{Id: 1, Text: "test"}
orm := serve.NewStruct("table_options", option)
command, values := orm.Insert("Text").GetSQL()
t.Log("[", orm.Id, "]")
t.Log("[", command, "]")
for k, v := range values {
t.Log("[", k, "=", v.Val, "]", v.Tag)
}
}
func TestUpdate(t *testing.T) {
option := &options{Id: 1, Text: "test"}
orm := serve.NewStruct("table_options", option)
command, values := orm.Update("Text").Where("Id=?").GetSQL()
t.Log("[", orm.Id, "]")
t.Log("[", command, "]")
for k, v := range values {
t.Log("[", k, "=", v.Val, "]", v.Tag)
}
}
func Benchmark_Tester(b *testing.B) {
option := &options{Id: 1, Text: "test"}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
orm := serve.NewStruct("table_options", option)
orm.Select().Where("Id=?").OrderBy("id desc").Page(20, 1).GetSQL()
b.Log(orm.Id)
}
})
}
func TestSetStruct(t *testing.T) {
type teststruct struct {
Id int
Name string
}
t1 := &teststruct{}
t.Log(t1)
mp := []map[string]interface{}{{"Id": 1, "Name1": "word"}, {"Id": 2, "Name1": "www"}}
var tt = make([]*teststruct, len(mp))
t.Log(tt)
// setStruct(tt, mp)
t.Log(tt)
}