forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_database_operation.go
84 lines (66 loc) · 2.29 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
package ravendb
import (
"encoding/json"
"net/http"
"time"
)
var (
_ IMaintenanceOperation = &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 {
o.Command = NewDeleteDatabaseCommand(conventions, o.parameters)
return o.Command
}
var _ RavenCommand = &DeleteDatabaseCommand{}
type DeleteDatabaseCommand struct {
RavenCommandBase
parameters []byte
Result *DeleteDatabaseResult
}
func NewDeleteDatabaseCommand(conventions *DocumentConventions, parameters *DeleteDatabaseParameters) *DeleteDatabaseCommand {
d, err := json.Marshal(parameters)
must(err)
cmd := &DeleteDatabaseCommand{
RavenCommandBase: NewRavenCommandBase(),
parameters: d,
}
return cmd
}
func (c *DeleteDatabaseCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.GetUrl() + "/admin/databases"
return NewHttpDelete(url, c.parameters)
}
func (c *DeleteDatabaseCommand) SetResponse(response []byte, fromCache bool) error {
return json.Unmarshal(response, &c.Result)
}