-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfluent_select.go
More file actions
130 lines (106 loc) · 2.74 KB
/
fluent_select.go
File metadata and controls
130 lines (106 loc) · 2.74 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
package goquery
import (
"bufio"
"bytes"
"io"
)
type OutputFormat uint8
type FluentSelect struct {
store DataStore
tx *Tx
qi QueryInput
qo QueryOutput
dest interface{}
}
func (s *FluentSelect) DataSet(ds DataSet) *FluentSelect {
s.qi.DataSet = ds
return s
}
func (s *FluentSelect) Tx(tx *Tx) *FluentSelect {
s.tx = tx
return s
}
func (s *FluentSelect) StatementKey(key string) *FluentSelect {
s.qi.StatementKey = key
return s
}
func (s *FluentSelect) Apply(vals ...interface{}) *FluentSelect {
s.qi.StmtAppends = vals
return s
}
func (s *FluentSelect) Dest(dest interface{}) *FluentSelect {
s.dest = dest
s.qo.OutputFormat = DEST
return s
}
func (s *FluentSelect) CamelCase(useCamelCase bool) *FluentSelect {
s.qo.Options.ToCamelCase = useCamelCase
return s
}
func (s *FluentSelect) DateFormat(dateFormat string) *FluentSelect {
s.qo.Options.DateFormat = dateFormat
return s
}
func (s *FluentSelect) OmitNull(omitnull bool) *FluentSelect {
s.qo.Options.OmitNull = omitnull
return s
}
func (s *FluentSelect) IsJsonArray(isJsonArray bool) *FluentSelect {
s.qo.Options.IsArray = isJsonArray
return s
}
func (s *FluentSelect) PanicOnErr(panicOnErr bool) *FluentSelect {
s.qi.PanicOnErr = panicOnErr
return s
}
func (s *FluentSelect) LogSql(logsql bool) *FluentSelect {
s.qi.LogSql = logsql
return s
}
func (s *FluentSelect) Suffix(suffix string) *FluentSelect {
s.qi.Suffix = suffix
return s
}
func (s *FluentSelect) Params(params ...interface{}) *FluentSelect {
s.qi.BindParams = params
return s
}
func (s *FluentSelect) OutputJson(writer io.Writer) *FluentSelect {
s.qo.Writer = writer
s.qo.OutputFormat = JSON
return s
}
func (s *FluentSelect) OutputCsv(writer io.Writer) *FluentSelect {
s.qo.Writer = writer
s.qo.OutputFormat = CSV
return s
}
func (s *FluentSelect) ForEachRow(rf RowFunction) *FluentSelect {
s.qo.rowFunction = rf
return s
}
func (s *FluentSelect) Fetch() error {
error := s.store.Fetch(s.tx, s.qi, s.qo, s.dest)
return error
}
func (s *FluentSelect) FetchRows() (Rows, error) {
return s.store.FetchRows(s.tx, s.qi)
}
// @deprecated: This method will be removed in the next version. Use Fetch()
func (s *FluentSelect) FetchI() (interface{}, error) {
dest := s.qi.DataSet.FieldSlice()
error := s.store.Fetch(s.tx, s.qi, s.qo, dest)
return dest, error
}
// @deprecated: This method will be removed in the next version. Use Fetch()
func (s *FluentSelect) FetchJSON() ([]byte, error) {
var b bytes.Buffer
writer := bufio.NewWriter(&b)
err := s.store.GetJSON(writer, s.qi, s.qo.Options)
writer.Flush()
return b.Bytes(), err
}
// @deprecated: This method will be removed in the next version. Use Fetch()
func (s *FluentSelect) FetchCSV() (string, error) {
return s.store.GetCSV(s.qi, s.qo.Options)
}