...
1
2
3
4
5
6
7 package operation
8
9 import (
10 "context"
11 "errors"
12
13 "go.mongodb.org/mongo-driver/event"
14 "go.mongodb.org/mongo-driver/internal/driverutil"
15 "go.mongodb.org/mongo-driver/mongo/description"
16 "go.mongodb.org/mongo-driver/mongo/writeconcern"
17 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
18 "go.mongodb.org/mongo-driver/x/mongo/driver"
19 "go.mongodb.org/mongo-driver/x/mongo/driver/session"
20 )
21
22
23 type DropDatabase struct {
24 session *session.Client
25 clock *session.ClusterClock
26 monitor *event.CommandMonitor
27 crypt driver.Crypt
28 database string
29 deployment driver.Deployment
30 selector description.ServerSelector
31 writeConcern *writeconcern.WriteConcern
32 serverAPI *driver.ServerAPIOptions
33 }
34
35
36 func NewDropDatabase() *DropDatabase {
37 return &DropDatabase{}
38 }
39
40
41 func (dd *DropDatabase) Execute(ctx context.Context) error {
42 if dd.deployment == nil {
43 return errors.New("the DropDatabase operation must have a Deployment set before Execute can be called")
44 }
45
46 return driver.Operation{
47 CommandFn: dd.command,
48 Client: dd.session,
49 Clock: dd.clock,
50 CommandMonitor: dd.monitor,
51 Crypt: dd.crypt,
52 Database: dd.database,
53 Deployment: dd.deployment,
54 Selector: dd.selector,
55 WriteConcern: dd.writeConcern,
56 ServerAPI: dd.serverAPI,
57 Name: driverutil.DropDatabaseOp,
58 }.Execute(ctx)
59
60 }
61
62 func (dd *DropDatabase) command(dst []byte, _ description.SelectedServer) ([]byte, error) {
63
64 dst = bsoncore.AppendInt32Element(dst, "dropDatabase", 1)
65 return dst, nil
66 }
67
68
69 func (dd *DropDatabase) Session(session *session.Client) *DropDatabase {
70 if dd == nil {
71 dd = new(DropDatabase)
72 }
73
74 dd.session = session
75 return dd
76 }
77
78
79 func (dd *DropDatabase) ClusterClock(clock *session.ClusterClock) *DropDatabase {
80 if dd == nil {
81 dd = new(DropDatabase)
82 }
83
84 dd.clock = clock
85 return dd
86 }
87
88
89 func (dd *DropDatabase) CommandMonitor(monitor *event.CommandMonitor) *DropDatabase {
90 if dd == nil {
91 dd = new(DropDatabase)
92 }
93
94 dd.monitor = monitor
95 return dd
96 }
97
98
99 func (dd *DropDatabase) Crypt(crypt driver.Crypt) *DropDatabase {
100 if dd == nil {
101 dd = new(DropDatabase)
102 }
103
104 dd.crypt = crypt
105 return dd
106 }
107
108
109 func (dd *DropDatabase) Database(database string) *DropDatabase {
110 if dd == nil {
111 dd = new(DropDatabase)
112 }
113
114 dd.database = database
115 return dd
116 }
117
118
119 func (dd *DropDatabase) Deployment(deployment driver.Deployment) *DropDatabase {
120 if dd == nil {
121 dd = new(DropDatabase)
122 }
123
124 dd.deployment = deployment
125 return dd
126 }
127
128
129 func (dd *DropDatabase) ServerSelector(selector description.ServerSelector) *DropDatabase {
130 if dd == nil {
131 dd = new(DropDatabase)
132 }
133
134 dd.selector = selector
135 return dd
136 }
137
138
139 func (dd *DropDatabase) WriteConcern(writeConcern *writeconcern.WriteConcern) *DropDatabase {
140 if dd == nil {
141 dd = new(DropDatabase)
142 }
143
144 dd.writeConcern = writeConcern
145 return dd
146 }
147
148
149 func (dd *DropDatabase) ServerAPI(serverAPI *driver.ServerAPIOptions) *DropDatabase {
150 if dd == nil {
151 dd = new(DropDatabase)
152 }
153
154 dd.serverAPI = serverAPI
155 return dd
156 }
157
View as plain text