-
Notifications
You must be signed in to change notification settings - Fork 3
/
query.go
105 lines (80 loc) · 2.88 KB
/
query.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
package query
// TypeType is the type for query type
type TypeType string
const (
// TypeExec is type of query which will executes db.Exec command
// https://golang.org/pkg/database/sql/#DB.Exec
TypeExec TypeType = "exec"
// TypeExecContext is type of query which will executes db.ExecContext command
// https://golang.org/pkg/database/sql/#DB.ExecContext
TypeExecContext TypeType = "exec_context"
// TypeQuery is type of query which will executes db.Query command
// https://golang.org/pkg/database/sql/#DB.Query
TypeQuery TypeType = "query"
// TypeQueryContext is type of query which will executes db.QueryContext command
// https://golang.org/pkg/database/sql/#DB.QueryContext
TypeQueryContext TypeType = "query_context"
)
// DataType is the data type of the query argument
type DataType string
const (
// DataTypeInteger is query argument with data type = integer.
// It is equivalent to Go's `int`
DataTypeInteger DataType = "integer"
// DataTypeString is query argument with data type = string.
// It is equivalent to Go's string
DataTypeString DataType = "string"
// DataTypeTime is query argument with data type = timestamp.
// It is equivalent to Go's time.Time and will always
// be converted to time.Now()
DataTypeTime DataType = "time"
)
// GenType is the method used to generate the argument
type GenType string
const (
// GenTypeSequential define argument generator in sequential mode
// integer: query number + Arg.Min
// string : prefix + query number
GenTypeSequential GenType = "sequential"
// GenTypeRandom define argument generator in random mode
// integer: between specified range (min-max)
// string : prefix + integer between specified range
GenTypeRandom GenType = "random"
)
// Query represents a database query
type Query struct {
// Name of the query, only used for informational purpose
Name string `yaml:"name"`
// Total number of queries which will be executed
NumQuery int `yaml:"num_query"`
// Query type
Type TypeType `yaml:"type"`
// Query string
QueryStr string `yaml:"query_str"`
// Query arguments
Args []Arg `yaml:"args"`
// True if we want to make it a prepared statement
Prepare bool `yaml:"prepare"`
// True if we want to prepare it once during the initialization.
// Otherwise we prepare it before executing the query
PrepareOnInit bool `yaml:"prepare_on_init"`
// True if the query contains placeholder
WithPlaceholder bool `yaml:"with_placeholder"`
}
// Arg represents a database query arg
type Arg struct {
// arg data type
DataType DataType `yaml:"data_type"`
// arg generation mode:
// sequential:
// random:
GenType GenType `yaml:"gen_type"`
// Prefix used to generate string arg
// the argument will be prefixed with the given prefix
// appended with query number
Prefix string `yaml:"prefix"`
// min value of generated argument
Min int `yaml:"min"`
// max value of generated random value
Max int `yaml:"max"`
}