-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.go
151 lines (122 loc) · 4.95 KB
/
client.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
package dsunit
import (
"github.com/viant/dsc"
"github.com/viant/toolbox"
)
type serviceClient struct {
serverURL string
}
//Registry returns registry of registered database managers
func (c *serviceClient) Registry() dsc.ManagerRegistry {
return dsc.NewManagerRegistry()
}
//Register register database connection
func (c *serviceClient) Register(request *RegisterRequest) *RegisterResponse {
var response = &RegisterResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+registerURI, request, response)
response.SetError(err)
return response
}
//Recreate remove and creates datastore
func (c *serviceClient) Recreate(request *RecreateRequest) *RecreateResponse {
var response = &RecreateResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+recreateURI, request, response)
response.SetError(err)
return response
}
func (c *serviceClient) CheckSchema(request *CheckSchemaRequest) *CheckSchemaResponse {
var response = &CheckSchemaResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+schemaURI, request, response)
response.SetError(err)
return response
}
//RunSQL runs supplied SQL
func (c *serviceClient) RunSQL(request *RunSQLRequest) *RunSQLResponse {
var response = &RunSQLResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+sqlURI, request, response)
response.SetError(err)
return response
}
//RunScript runs supplied SQL scripts
func (c *serviceClient) RunScript(request *RunScriptRequest) *RunSQLResponse {
var response = &RunSQLResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+scriptURI, request, response)
response.SetError(err)
return response
}
//Add table mapping
func (c *serviceClient) AddTableMapping(request *MappingRequest) *MappingResponse {
var response = &MappingResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+mappingURI, request, response)
response.SetError(err)
return response
}
func (c *serviceClient) Init(request *InitRequest) *InitResponse {
var response = &InitResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+initURI, request, response)
response.SetError(err)
return response
}
//Populate database with datasets
func (c *serviceClient) Prepare(request *PrepareRequest) *PrepareResponse {
var response = &PrepareResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+prepareURI, request, response)
response.SetError(err)
return response
}
//Verify datastore with supplied expected datasets
func (c *serviceClient) Expect(request *ExpectRequest) *ExpectResponse {
var response = &ExpectResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+expectURI, request, response)
response.SetError(err)
return response
}
//Query returns query from database
func (c *serviceClient) Query(request *QueryRequest) *QueryResponse {
var response = &QueryResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+queryURI, request, response)
response.SetError(err)
return response
}
//Freeze create a dataset from existing database
func (c *serviceClient) Freeze(request *FreezeRequest) *FreezeResponse {
var response = &FreezeResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+freezeURI, request, response)
response.SetError(err)
return response
}
//Dump creates schema from existing database
func (c *serviceClient) Dump(request *DumpRequest) *DumpResponse {
var response = &DumpResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+freezeURI, request, response)
response.SetError(err)
return response
}
//Sequence returns sequence for supplied tables
func (c *serviceClient) Sequence(request *SequenceRequest) *SequenceResponse {
var response = &SequenceResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+sequenceURI, request, response)
response.SetError(err)
return response
}
func (s *serviceClient) SetContext(context toolbox.Context) {
}
//Compare compares supplied SQLs data
func (c *serviceClient) Compare(request *CompareRequest) *CompareResponse {
var response = &CompareResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("post", c.serverURL+sequenceURI, request, response)
response.SetError(err)
return response
}
//Compare compares supplied SQLs data
func (c *serviceClient) Ping(request *PingRequest) *PingResponse {
var response = &PingResponse{BaseResponse: NewBaseOkResponse()}
err := toolbox.RouteToService("ping", c.serverURL+sequenceURI, request, response)
response.SetError(err)
return response
}
//NewServiceClient returns a new dsunit service client
func NewServiceClient(serverURL string) Service {
var result Service = &serviceClient{serverURL: serverURL}
return result
}