forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.go
55 lines (45 loc) · 1.37 KB
/
database.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
package aiven
import "fmt"
type (
// Database represents a database type on Aiven.
Database struct {
Database string `json:"database"`
LcCollate string `json:"lc_collate,omitempty"`
LcType string `json:"lc_type,omitempty"`
}
// DatabasesHandler is the client which interacts with the Aiven database
// endpoints.
DatabasesHandler struct {
client *Client
}
// CreateDatabaseRequest are the parameters used to create a database.
CreateDatabaseRequest struct {
Database string `json:"database"`
LcCollate string `json:"lc_collate,omitempty"`
LcType string `json:"lc_type,omitempty"`
}
)
// Create creates a database with the given parameters.
func (h *DatabasesHandler) Create(project, service string, req CreateDatabaseRequest) (*Database, error) {
bts, err := h.client.doPostRequest(fmt.Sprintf("/project/%s/service/%s/db", project, service), req)
if err != nil {
return nil, err
}
rsp, err := handleAPIResponse(bts)
if err != nil {
return nil, err
}
if len(rsp.Errors) != 0 {
return nil, rsp.Errors[0]
}
db := Database(req)
return &db, nil
}
// Delete deletes the specified database.
func (h *DatabasesHandler) Delete(project, service, database string) error {
bts, err := h.client.doDeleteRequest(fmt.Sprintf("/project/%s/service/%s/db/%s", project, service, database), nil)
if err != nil {
return err
}
return handleDeleteResponse(bts)
}