-
Notifications
You must be signed in to change notification settings - Fork 16
/
delete_database_operation.go
89 lines (71 loc) · 2.37 KB
/
delete_database_operation.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
package ravendb
import (
"net/http"
"time"
)
var (
_ IServerOperation = &DeleteDatabasesOperation{}
)
type DeleteDatabasesOperation struct {
parameters *DeleteDatabaseParameters
Command *DeleteDatabaseCommand
}
type DeleteDatabaseParameters struct {
DatabaseNames []string `json:"DatabaseNames"`
HardDelete bool `json:"HardDelete"`
FromNodes []string `json:"FromNodes"`
TimeToWaitForConfirmation *time.Duration `json:"TimeToWaitForConfirmation"`
}
func NewDeleteDatabasesOperation(databaseName string, hardDelete bool) *DeleteDatabasesOperation {
return NewDeleteDatabasesOperation2(databaseName, hardDelete, "", 0)
}
func NewDeleteDatabasesOperation2(databaseName string, hardDelete bool, fromNode string, timeToWaitForConfirmation time.Duration) *DeleteDatabasesOperation {
parameters := &DeleteDatabaseParameters{
DatabaseNames: []string{databaseName},
HardDelete: hardDelete,
}
if timeToWaitForConfirmation != 0 {
parameters.TimeToWaitForConfirmation = &timeToWaitForConfirmation
}
if fromNode != "" {
parameters.FromNodes = []string{fromNode}
}
return NewDeleteDatabasesOperationWithParameters(parameters)
}
func NewDeleteDatabasesOperationWithParameters(parameters *DeleteDatabaseParameters) *DeleteDatabasesOperation {
return &DeleteDatabasesOperation{
parameters: parameters,
}
}
func (o *DeleteDatabasesOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) {
var err error
o.Command, err = NewDeleteDatabaseCommand(conventions, o.parameters)
if err != nil {
return nil, err
}
return o.Command, nil
}
var _ RavenCommand = &DeleteDatabaseCommand{}
type DeleteDatabaseCommand struct {
RavenCommandBase
parameters []byte
Result *DeleteDatabaseResult
}
func NewDeleteDatabaseCommand(conventions *DocumentConventions, parameters *DeleteDatabaseParameters) (*DeleteDatabaseCommand, error) {
d, err := jsonMarshal(parameters)
if err != nil {
return nil, err
}
cmd := &DeleteDatabaseCommand{
RavenCommandBase: NewRavenCommandBase(),
parameters: d,
}
return cmd, nil
}
func (c *DeleteDatabaseCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/admin/databases"
return newHttpDelete(url, c.parameters)
}
func (c *DeleteDatabaseCommand) SetResponse(response []byte, fromCache bool) error {
return jsonUnmarshal(response, &c.Result)
}