-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresqlDB.go
80 lines (60 loc) · 1.93 KB
/
postgresqlDB.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
package sys11dbaassdk
import (
"encoding/json"
)
func (c *Client) GetPostgreSQLDB(grq *GetPostgreSQLRequest) (*GetPostgreSQLResponse, error) {
path := "/" + grq.Organization + "/" + grq.Project + "/v1/databases/" + grq.UUID
data, err := c.get(path, grq.Verbose)
if err != nil {
return nil, err
}
responseData := &GetPostgreSQLResponse{}
err = json.Unmarshal(data, responseData)
return responseData, err
}
func (c *Client) ListPostgreSQLDBs(grq *GetPostgreSQLsRequest) ([]*GetPostgreSQLResponse, error) {
path := "/" + grq.Organization + "/" + grq.Project + "/v1/databases"
data, err := c.get(path, grq.Verbose)
if err != nil {
return nil, err
}
responseData := make([]*GetPostgreSQLResponse, 0)
err = json.Unmarshal(data, &responseData)
return responseData, err
}
func (c *Client) CreatePostgreSQLDB(crq *CreatePostgreSQLRequest) (*CreatePostgreSQLResponse, error) {
path := "/" + crq.Organization + "/" + crq.Project + "/v1/databases"
data, err := json.Marshal(crq)
if err != nil {
return nil, err
}
responseData, err := c.post(path, data, crq.Verbose)
if err != nil {
return nil, err
}
response := &CreatePostgreSQLResponse{}
err = json.Unmarshal(responseData, response)
return response, err
}
func (c *Client) DeletePostgreSQLDB(drq *DeletePostgreSQLRequest) (*DeletePostgreSQLResponse, error) {
path := "/" + drq.Organization + "/" + drq.Project + "/v1/databases/" + drq.UUID
_, err := c.delete(path, drq.Verbose)
if err != nil {
return nil, err
}
response := &DeletePostgreSQLResponse{}
return response, err
}
func (c *Client) UpdatePostgreSQLDB(urq *UpdatePostgreSQLRequest) (*UpdatePostgreSQLResponse, error) {
path := "/" + urq.Organization + "/" + urq.Project + "/v1/databases/" + urq.UUID
data, err := json.Marshal(urq)
if err != nil {
return nil, err
}
_, err = c.patch(path, data, urq.Verbose)
if err != nil {
return nil, err
}
response := &UpdatePostgreSQLResponse{}
return response, err
}