@@ -101,3 +101,164 @@ func (c *ProxyClient) QueryWithTx(ctx context.Context, tx string, commit bool, r
101
101
err := PostWithClientAndDecode (ctx , c .Client , c .Url + "/query?tx=" + tx + sc , stm , & result , c .Log )
102
102
return err
103
103
}
104
+
105
+ func (c * ProxyClient ) Insert (ctx context.Context , table string , model interface {}, options ... func (int ) string ) (int64 , error ) {
106
+ var buildParam func (int ) string
107
+ if len (options ) > 0 {
108
+ buildParam = options [0 ]
109
+ } else {
110
+ buildParam = sql .BuildDollarParam
111
+ }
112
+ s , values := sql .BuildToInsert (table , model , buildParam )
113
+ return c .Exec (ctx , s , values ... )
114
+ }
115
+ func (c * ProxyClient ) Update (ctx context.Context , table string , model interface {}, options ... func (int ) string ) (int64 , error ) {
116
+ var buildParam func (int ) string
117
+ if len (options ) > 0 {
118
+ buildParam = options [0 ]
119
+ } else {
120
+ buildParam = sql .BuildDollarParam
121
+ }
122
+ s , values := sql .BuildToUpdate (table , model , buildParam )
123
+ return c .Exec (ctx , s , values ... )
124
+ }
125
+ func (c * ProxyClient ) Save (ctx context.Context , table string , model interface {}, options ... string ) (int64 , error ) {
126
+ driver := sql .DriverPostgres
127
+ var buildParam func (int ) string
128
+ if len (options ) > 0 {
129
+ driver = options [0 ]
130
+ }
131
+ buildParam = sql .GetBuildByDriver (driver )
132
+ s , values , err := sql .BuildToSave (table , model , driver , buildParam )
133
+ if err != nil {
134
+ return - 1 , err
135
+ }
136
+ return c .Exec (ctx , s , values ... )
137
+ }
138
+ func (c * ProxyClient ) InsertBatch (ctx context.Context , table string , models interface {}, options ... string ) (int64 , error ) {
139
+ driver := sql .DriverPostgres
140
+ var buildParam func (int ) string
141
+ if len (options ) > 0 {
142
+ driver = options [0 ]
143
+ }
144
+ buildParam = sql .GetBuildByDriver (driver )
145
+ s , values , err := sql .BuildToInsertBatch (table , models , driver , buildParam )
146
+ if err != nil {
147
+ return - 1 , err
148
+ }
149
+ return c .Exec (ctx , s , values ... )
150
+ }
151
+ func (c * ProxyClient ) UpdateBatch (ctx context.Context , table string , models interface {}, options ... string ) (int64 , error ) {
152
+ driver := sql .DriverPostgres
153
+ var buildParam func (int ) string
154
+ if len (options ) > 0 {
155
+ driver = options [0 ]
156
+ }
157
+ buildParam = sql .GetBuildByDriver (driver )
158
+ s , err := sql .BuildToUpdateBatch (table , models , buildParam , driver )
159
+ if err != nil {
160
+ return - 1 , err
161
+ }
162
+ if len (s ) > 0 {
163
+ return c .ExecBatch (ctx , false , s ... )
164
+ } else {
165
+ return 0 , nil
166
+ }
167
+ }
168
+ func (c * ProxyClient ) SaveBatch (ctx context.Context , table string , models interface {}, options ... string ) (int64 , error ) {
169
+ driver := sql .DriverPostgres
170
+ var buildParam func (int ) string
171
+ if len (options ) > 0 {
172
+ driver = options [0 ]
173
+ }
174
+ buildParam = sql .GetBuildByDriver (driver )
175
+ s , err := sql .BuildToSaveBatch (table , models , driver , buildParam )
176
+ if err != nil {
177
+ return - 1 , err
178
+ }
179
+ if len (s ) > 0 {
180
+ return c .ExecBatch (ctx , false , s ... )
181
+ } else {
182
+ return 0 , nil
183
+ }
184
+ }
185
+ func (c * ProxyClient ) InsertWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, options ... func (int ) string ) (int64 , error ) {
186
+ var buildParam func (int ) string
187
+ if len (options ) > 0 {
188
+ buildParam = options [0 ]
189
+ } else {
190
+ buildParam = sql .BuildDollarParam
191
+ }
192
+ s , values := sql .BuildToInsert (table , model , buildParam )
193
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
194
+ }
195
+ func (c * ProxyClient ) UpdateWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, options ... func (int ) string ) (int64 , error ) {
196
+ var buildParam func (int ) string
197
+ if len (options ) > 0 {
198
+ buildParam = options [0 ]
199
+ } else {
200
+ buildParam = sql .BuildDollarParam
201
+ }
202
+ s , values := sql .BuildToUpdate (table , model , buildParam )
203
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
204
+ }
205
+ func (c * ProxyClient ) SaveWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, options ... string ) (int64 , error ) {
206
+ driver := sql .DriverPostgres
207
+ var buildParam func (int ) string
208
+ if len (options ) > 0 {
209
+ driver = options [0 ]
210
+ }
211
+ buildParam = sql .GetBuildByDriver (driver )
212
+ s , values , err := sql .BuildToSave (table , model , driver , buildParam )
213
+ if err != nil {
214
+ return - 1 , err
215
+ }
216
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
217
+ }
218
+ func (c * ProxyClient ) InsertBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, options ... string ) (int64 , error ) {
219
+ driver := sql .DriverPostgres
220
+ var buildParam func (int ) string
221
+ if len (options ) > 0 {
222
+ driver = options [0 ]
223
+ }
224
+ buildParam = sql .GetBuildByDriver (driver )
225
+ s , values , err := sql .BuildToInsertBatch (table , models , driver , buildParam )
226
+ if err != nil {
227
+ return - 1 , err
228
+ }
229
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
230
+ }
231
+ func (c * ProxyClient ) UpdateBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, options ... string ) (int64 , error ) {
232
+ driver := sql .DriverPostgres
233
+ var buildParam func (int ) string
234
+ if len (options ) > 0 {
235
+ driver = options [0 ]
236
+ }
237
+ buildParam = sql .GetBuildByDriver (driver )
238
+ s , err := sql .BuildToUpdateBatch (table , models , buildParam , driver )
239
+ if err != nil {
240
+ return - 1 , err
241
+ }
242
+ if len (s ) > 0 {
243
+ return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
244
+ } else {
245
+ return 0 , nil
246
+ }
247
+ }
248
+ func (c * ProxyClient ) SaveBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, options ... string ) (int64 , error ) {
249
+ driver := sql .DriverPostgres
250
+ var buildParam func (int ) string
251
+ if len (options ) > 0 {
252
+ driver = options [0 ]
253
+ }
254
+ buildParam = sql .GetBuildByDriver (driver )
255
+ s , err := sql .BuildToSaveBatch (table , models , driver , buildParam )
256
+ if err != nil {
257
+ return - 1 , err
258
+ }
259
+ if len (s ) > 0 {
260
+ return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
261
+ } else {
262
+ return 0 , nil
263
+ }
264
+ }
0 commit comments