-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathrequest.go
366 lines (318 loc) · 11.8 KB
/
request.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package holoclient
/*
#cgo CFLAGS: -I./include
#cgo LDFLAGS: -L./lib -lholo-client
#include "request.h"
#include "table_schema.h"
#include <stdlib.h>
#include <stdbool.h>
*/
import "C"
import "unsafe"
type HoloMutationMode C.HoloMutationMode
const (
PUT HoloMutationMode = C.PUT
DELETE HoloMutationMode = C.DELETE
)
type HoloTableSchema struct {
ctableSchema *C.HoloTableSchema
}
func (schema *HoloTableSchema) NumColumns() int {
res := schema.ctableSchema.nColumns
return int(res)
}
func (schema *HoloTableSchema) GetColumnNameByColIndex(colIndex int) string {
return C.GoString(C.holo_client_get_column_name(schema.ctableSchema, C.int(colIndex)))
}
func (schema *HoloTableSchema) GetColumnTypeByColIndex(colIndex int) string {
return C.GoString(C.holo_client_get_column_type_name(schema.ctableSchema, C.int(colIndex)))
}
type mutationRequest struct {
cmutation C.HoloMutation
}
func NewMutationRequest(schema *HoloTableSchema) *mutationRequest {
m := new(mutationRequest)
m.cmutation = C.holo_client_new_mutation_request(schema.ctableSchema)
return m
}
func (mutation *mutationRequest) SetRequestMode(mode HoloMutationMode) {
C.holo_client_set_request_mode(mutation.cmutation, C.HoloMutationMode(mode))
}
// Set value by Colindex (recommended)
// 所有类型都可以以string类型设置
func (mutation *mutationRequest) SetValWithTextByColIndex(colIndex int, value string, len int) int {
cvalue := C.CString(value)
res := C.holo_client_set_req_val_with_text_by_colindex(mutation.cmutation, C.int(colIndex), cvalue, C.int(len))
C.free(unsafe.Pointer(cvalue))
return int(res)
}
// smallint
func (mutation *mutationRequest) SetInt16ValByColIndex(colIndex int, value int16) int {
res := C.holo_client_set_req_int16_val_by_colindex(mutation.cmutation, C.int(colIndex), C.int16_t(value))
return int(res)
}
// int
func (mutation *mutationRequest) SetInt32ValByColIndex(colIndex int, value int32) int {
res := C.holo_client_set_req_int32_val_by_colindex(mutation.cmutation, C.int(colIndex), C.int32_t(value))
return int(res)
}
// bigint
func (mutation *mutationRequest) SetInt64ValByColIndex(colIndex int, value int64) int {
res := C.holo_client_set_req_int64_val_by_colindex(mutation.cmutation, C.int(colIndex), C.int64_t(value))
return int(res)
}
// bool
func (mutation *mutationRequest) SetBoolValByColIndex(colIndex int, value bool) int {
res := C.holo_client_set_req_bool_val_by_colindex(mutation.cmutation, C.int(colIndex), C.bool(value))
return int(res)
}
// real(float4)
func (mutation *mutationRequest) SetFloat32ValByColIndex(colIndex int, value float32) int {
res := C.holo_client_set_req_float_val_by_colindex(mutation.cmutation, C.int(colIndex), C.float(value))
return int(res)
}
// float(float8 double precision)
func (mutation *mutationRequest) SetFloat64ValByColIndex(colIndex int, value float64) int {
res := C.holo_client_set_req_double_val_by_colindex(mutation.cmutation, C.int(colIndex), C.double(value))
return int(res)
}
// text
func (mutation *mutationRequest) SetTextValByColIndex(colIndex int, value string, len int) int {
cvalue := C.CString(value)
res := C.holo_client_set_req_text_val_by_colindex(mutation.cmutation, C.int(colIndex), cvalue, C.int(len))
C.free(unsafe.Pointer(cvalue))
return int(res)
}
// timestamp
func (mutation *mutationRequest) SetTimestampValByColIndex(colIndex int, value int64) int {
res := C.holo_client_set_req_timestamp_val_by_colindex(mutation.cmutation, C.int(colIndex), C.int64_t(value))
return int(res)
}
// timestamptz
func (mutation *mutationRequest) SetTimestamptzValByColIndex(colIndex int, value int64) int {
res := C.holo_client_set_req_timestamptz_val_by_colindex(mutation.cmutation, C.int(colIndex), C.int64_t(value))
return int(res)
}
// int[]
func (mutation *mutationRequest) SetInt32ArrayValByColIndex(colIndex int, value []int32) int {
var dataPtr *C.int32_t
if len(value) == 0 {
dataPtr = (*C.int32_t)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.int32_t)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_int32_array_val_by_colindex(mutation.cmutation, C.int(colIndex), dataPtr, C.int(len(value)))
return int(res)
}
// bigint[]
func (mutation *mutationRequest) SetInt64ArrayValByColIndex(colIndex int, value []int64) int {
var dataPtr *C.int64_t
if len(value) == 0 {
dataPtr = (*C.int64_t)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.int64_t)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_int64_array_val_by_colindex(mutation.cmutation, C.int(colIndex), dataPtr, C.int(len(value)))
return int(res)
}
// bool[]
func (mutation *mutationRequest) SetBoolArrayValByColIndex(colIndex int, value []bool) int {
var dataPtr *C.bool
if len(value) == 0 {
dataPtr = (*C.bool)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.bool)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_bool_array_val_by_colindex(mutation.cmutation, C.int(colIndex), dataPtr, C.int(len(value)))
return int(res)
}
// float4[]
func (mutation *mutationRequest) SetFloat32ArrayValByColIndex(colIndex int, value []float32) int {
var dataPtr *C.float
if len(value) == 0 {
dataPtr = (*C.float)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.float)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_float_array_val_by_colindex(mutation.cmutation, C.int(colIndex), dataPtr, C.int(len(value)))
return int(res)
}
// float8[]
func (mutation *mutationRequest) SetFloat64ArrayValByColIndex(colIndex int, value []float64) int {
var dataPtr *C.double
if len(value) == 0 {
dataPtr = (*C.double)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.double)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_double_array_val_by_colindex(mutation.cmutation, C.int(colIndex), dataPtr, C.int(len(value)))
return int(res)
}
func (mutation *mutationRequest) SetNullValByColIndex(colIndex int) int {
res := C.holo_client_set_req_null_val_by_colindex(mutation.cmutation, C.int(colIndex))
return int(res)
}
// Set value by Colname
// 所有类型
func (mutation *mutationRequest) SetValWithTextByColName(colName string, value string, len int) int {
cname := C.CString(colName)
cvalue := C.CString(value)
res := C.holo_client_set_req_val_with_text_by_colname(mutation.cmutation, cname, cvalue, C.int(len))
C.free(unsafe.Pointer(cvalue))
C.free(unsafe.Pointer(cname))
return int(res)
}
// smallint
func (mutation *mutationRequest) SetInt16ValByColName(colName string, value int16) int {
cname := C.CString(colName)
res := C.holo_client_set_req_int16_val_by_colname(mutation.cmutation, cname, C.int16_t(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// int
func (mutation *mutationRequest) SetInt32ValByColName(colName string, value int32) int {
cname := C.CString(colName)
res := C.holo_client_set_req_int32_val_by_colname(mutation.cmutation, cname, C.int32_t(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// bigint
func (mutation *mutationRequest) SetInt64ValByColName(colName string, value int64) int {
cname := C.CString(colName)
res := C.holo_client_set_req_int64_val_by_colname(mutation.cmutation, cname, C.int64_t(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// bool
func (mutation *mutationRequest) SetBoolValByColName(colName string, value bool) int {
cname := C.CString(colName)
res := C.holo_client_set_req_bool_val_by_colname(mutation.cmutation, cname, C.bool(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// real(float4)
func (mutation *mutationRequest) SetFloat32ValByColName(colName string, value float32) int {
cname := C.CString(colName)
res := C.holo_client_set_req_float_val_by_colname(mutation.cmutation, cname, C.float(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// float(float8 double precision)
func (mutation *mutationRequest) SetFloat64ValByColName(colName string, value float64) int {
cname := C.CString(colName)
res := C.holo_client_set_req_double_val_by_colname(mutation.cmutation, cname, C.double(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// text
func (mutation *mutationRequest) SetTextValByColName(colName string, value string, len int) int {
cname := C.CString(colName)
cvalue := C.CString(value)
res := C.holo_client_set_req_text_val_by_colname(mutation.cmutation, cname, cvalue, C.int(len))
C.free(unsafe.Pointer(cvalue))
C.free(unsafe.Pointer(cname))
return int(res)
}
// timestamp
func (mutation *mutationRequest) SetTimestampValByColName(colName string, value int64) int {
cname := C.CString(colName)
res := C.holo_client_set_req_timestamp_val_by_colname(mutation.cmutation, cname, C.int64_t(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// timestamptz
func (mutation *mutationRequest) SetTimestamptzValByColName(colName string, value int64) int {
cname := C.CString(colName)
res := C.holo_client_set_req_timestamptz_val_by_colname(mutation.cmutation, cname, C.int64_t(value))
C.free(unsafe.Pointer(cname))
return int(res)
}
// int[]
func (mutation *mutationRequest) SetInt32ArrayValByColName(colName string, value []int32) int {
cname := C.CString(colName)
var dataPtr *C.int32_t
if len(value) == 0 {
dataPtr = (*C.int32_t)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.int32_t)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_int32_array_val_by_colname(mutation.cmutation, cname, dataPtr, C.int(len(value)))
C.free(unsafe.Pointer(cname))
return int(res)
}
// bigint[]
func (mutation *mutationRequest) SetInt64ArrayValByColName(colName string, value []int64) int {
cname := C.CString(colName)
var dataPtr *C.int64_t
if len(value) == 0 {
dataPtr = (*C.int64_t)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.int64_t)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_int64_array_val_by_colname(mutation.cmutation, cname, dataPtr, C.int(len(value)))
C.free(unsafe.Pointer(cname))
return int(res)
}
// bool[]
func (mutation *mutationRequest) SetBoolArrayValByColName(colName string, value []bool) int {
cname := C.CString(colName)
var dataPtr *C.bool
if len(value) == 0 {
dataPtr = (*C.bool)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.bool)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_bool_array_val_by_colname(mutation.cmutation, cname, dataPtr, C.int(len(value)))
C.free(unsafe.Pointer(cname))
return int(res)
}
// float4[]
func (mutation *mutationRequest) SetFloat32ArrayValByColName(colName string, value []float32) int {
cname := C.CString(colName)
var dataPtr *C.float
if len(value) == 0 {
dataPtr = (*C.float)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.float)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_float_array_val_by_colname(mutation.cmutation, cname, dataPtr, C.int(len(value)))
C.free(unsafe.Pointer(cname))
return int(res)
}
// float8[]
func (mutation *mutationRequest) SetFloat64ArrayValByColName(colName string, value []float64) int {
cname := C.CString(colName)
var dataPtr *C.double
if len(value) == 0 {
dataPtr = (*C.double)(unsafe.Pointer(&value))
} else {
dataPtr = (*C.double)(unsafe.Pointer(&value[0]))
}
res := C.holo_client_set_req_double_array_val_by_colname(mutation.cmutation, cname, dataPtr, C.int(len(value)))
C.free(unsafe.Pointer(cname))
return int(res)
}
func (mutation *mutationRequest) SetNullValByColName(colName string) int {
cname := C.CString(colName)
res := C.holo_client_set_req_null_val_by_colname(mutation.cmutation, cname)
C.free(unsafe.Pointer(cname))
return int(res)
}
type GetRequest struct {
cget C.HoloGet
}
func NewGetRequest(schema *HoloTableSchema) *GetRequest {
get := new(GetRequest)
get.cget = C.holo_client_new_get_request(schema.ctableSchema)
return get
}
// 必须以string的形式设置值
func (get *GetRequest) SetGetValByColIndex(colIndex int, value string, len int) int {
cvalue := C.CString(value)
res := C.holo_client_set_get_val_with_text_by_colindex(get.cget, C.int(colIndex), cvalue, C.int(len))
C.free(unsafe.Pointer(cvalue))
return int(res)
}
func (get *GetRequest) DestroyGet() {
C.holo_client_destroy_get_request(get.cget)
}