Skip to content

Commit 0059a7a

Browse files
authored
SWIFT-711 remove DropIndexesResult (#393)
1 parent f051cdd commit 0059a7a

File tree

4 files changed

+37
-66
lines changed

4 files changed

+37
-66
lines changed

Sources/MongoSwift/MongoCollection+Indexes.swift

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,17 @@ extension MongoCollection {
255255
* - options: Optional `DropIndexOptions` to use for the command
256256
* - session: Optional `ClientSession` to use when executing this command
257257
*
258-
* - Returns: An `EventLoopFuture` containing the result of dropping the index.
259-
*
260-
* - Throws:
261-
* - `WriteError` if an error occurs while performing the command.
262-
* - `CommandError` if an error occurs that prevents the command from executing.
263-
* - `InvalidArgumentError` if the options passed in form an invalid combination.
264-
* - `EncodingError` if an error occurs while encoding the options.
258+
* - Returns: An `EventLoopFuture<Void>`. On failure, contains:
259+
* - `WriteError` if an error occurs while performing the command.
260+
* - `CommandError` if an error occurs that prevents the command from executing.
261+
* - `InvalidArgumentError` if the options passed in form an invalid combination.
262+
* - `EncodingError` if an error occurs while encoding the options.
265263
*/
266264
public func dropIndex(
267265
_ name: String,
268266
options: DropIndexOptions? = nil,
269267
session: ClientSession? = nil
270-
) -> EventLoopFuture<DropIndexesResult> {
268+
) -> EventLoopFuture<Void> {
271269
guard name != "*" else {
272270
return self._client.operationExecutor.makeFailedFuture(InvalidArgumentError(
273271
message: "Invalid index name '*'; use dropIndexes() to drop all indexes"
@@ -284,20 +282,18 @@ extension MongoCollection {
284282
* - options: Optional `DropIndexOptions` to use for the command
285283
* - session: Optional `ClientSession` to use when executing this command
286284
*
287-
* - Returns: An `EventLoopFuture` containing the result of dropping the index.
288-
*
289-
* - Throws:
290-
* - `WriteError` if an error occurs while performing the command.
291-
* - `CommandError` if an error occurs that prevents the command from executing.
292-
* - `InvalidArgumentError` if the options passed in form an invalid combination.
293-
* - `LogicError` if the provided session is inactive.
294-
* - `EncodingError` if an error occurs while encoding the options.
285+
* - Returns: An `EventLoopFuture<Void>`. On failure, contains:
286+
* - `WriteError` if an error occurs while performing the command.
287+
* - `CommandError` if an error occurs that prevents the command from executing.
288+
* - `InvalidArgumentError` if the options passed in form an invalid combination.
289+
* - `LogicError` if the provided session is inactive.
290+
* - `EncodingError` if an error occurs while encoding the options.
295291
*/
296292
public func dropIndex(
297293
_ keys: Document,
298294
options: DropIndexOptions? = nil,
299295
session: ClientSession? = nil
300-
) -> EventLoopFuture<DropIndexesResult> {
296+
) -> EventLoopFuture<Void> {
301297
return self._dropIndexes(index: .document(keys), options: options, session: session)
302298
}
303299

@@ -309,20 +305,18 @@ extension MongoCollection {
309305
* - options: Optional `DropIndexOptions` to use for the command
310306
* - session: Optional `ClientSession` to use when executing this command
311307
*
312-
* - Returns: An `EventLoopFuture` containing the result of dropping the index.
313-
*
314-
* - Throws:
315-
* - `WriteError` if an error occurs while performing the command.
316-
* - `CommandError` if an error occurs that prevents the command from executing.
317-
* - `InvalidArgumentError` if the options passed in form an invalid combination.
318-
* - `LogicError` if the provided session is inactive.
319-
* - `EncodingError` if an error occurs while encoding the options.
308+
* - Returns: An `EventLoopFuture<Void>`. On failure, contains:
309+
* - `WriteError` if an error occurs while performing the command.
310+
* - `CommandError` if an error occurs that prevents the command from executing.
311+
* - `InvalidArgumentError` if the options passed in form an invalid combination.
312+
* - `LogicError` if the provided session is inactive.
313+
* - `EncodingError` if an error occurs while encoding the options.
320314
*/
321315
public func dropIndex(
322316
_ model: IndexModel,
323317
options: DropIndexOptions? = nil,
324318
session: ClientSession? = nil
325-
) -> EventLoopFuture<DropIndexesResult> {
319+
) -> EventLoopFuture<Void> {
326320
return self._dropIndexes(index: .document(model.keys), options: options, session: session)
327321
}
328322

@@ -333,19 +327,17 @@ extension MongoCollection {
333327
* - options: Optional `DropIndexOptions` to use for the command
334328
* - session: Optional `ClientSession` to use when executing this command
335329
*
336-
* - Returns: An `EventLoopFuture` containing the result of dropping the indexes.
337-
*
338-
* - Throws:
339-
* - `WriteError` if an error occurs while performing the command.
340-
* - `CommandError` if an error occurs that prevents the command from executing.
341-
* - `InvalidArgumentError` if the options passed in form an invalid combination.
342-
* - `LogicError` if the provided session is inactive.
343-
* - `EncodingError` if an error occurs while encoding the options.
330+
* - Returns: An `EventLoopFuture<Void>`. On failure, contains:
331+
* - `WriteError` if an error occurs while performing the command.
332+
* - `CommandError` if an error occurs that prevents the command from executing.
333+
* - `InvalidArgumentError` if the options passed in form an invalid combination.
334+
* - `LogicError` if the provided session is inactive.
335+
* - `EncodingError` if an error occurs while encoding the options.
344336
*/
345337
public func dropIndexes(
346338
options: DropIndexOptions? = nil,
347339
session: ClientSession? = nil
348-
) -> EventLoopFuture<DropIndexesResult> {
340+
) -> EventLoopFuture<Void> {
349341
return self._dropIndexes(index: "*", options: options, session: session)
350342
}
351343

@@ -355,7 +347,7 @@ extension MongoCollection {
355347
index: BSON,
356348
options: DropIndexOptions?,
357349
session: ClientSession?
358-
) -> EventLoopFuture<DropIndexesResult> {
350+
) -> EventLoopFuture<Void> {
359351
let operation = DropIndexesOperation(collection: self, index: index, options: options)
360352
return self._client.operationExecutor.execute(operation, client: self._client, session: session)
361353
}

Sources/MongoSwift/Operations/DropIndexesOperation.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ public struct DropIndexOptions: Encodable {
1515
}
1616
}
1717

18-
/// The result of performing a "dropIndexes" command.
19-
public struct DropIndexesResult: Decodable {
20-
/// The number of indexes that were present in the collection prior to performing the drop.
21-
public let nIndexesWas: Int
22-
}
23-
2418
/// An operation corresponding to a "dropIndexes" command.
2519
internal struct DropIndexesOperation<T: Codable>: Operation {
2620
private let collection: MongoCollection<T>
@@ -33,7 +27,7 @@ internal struct DropIndexesOperation<T: Codable>: Operation {
3327
self.options = options
3428
}
3529

36-
internal func execute(using connection: Connection, session: ClientSession?) throws -> DropIndexesResult {
30+
internal func execute(using connection: Connection, session: ClientSession?) throws {
3731
let command: Document = ["dropIndexes": .string(self.collection.name), "index": self.index]
3832
let opts = try encodeOptions(options: self.options, session: session)
3933
var reply = Document()
@@ -46,7 +40,5 @@ internal struct DropIndexesOperation<T: Codable>: Operation {
4640
guard success else {
4741
throw extractMongoError(error: error, reply: reply)
4842
}
49-
50-
return try self.collection.decoder.decode(DropIndexesResult.self, from: reply)
5143
}
5244
}

Sources/MongoSwiftSync/Exports.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
@_exported import struct MongoSwift.DropCollectionOptions
5959
@_exported import struct MongoSwift.DropDatabaseOptions
6060
@_exported import struct MongoSwift.DropIndexOptions
61-
@_exported import struct MongoSwift.DropIndexesResult
6261
@_exported import struct MongoSwift.EstimatedDocumentCountOptions
6362
@_exported import struct MongoSwift.FindOneAndDeleteOptions
6463
@_exported import struct MongoSwift.FindOneAndReplaceOptions

Sources/MongoSwiftSync/MongoCollection+Indexes.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,18 @@ extension MongoCollection {
9494
* - options: Optional `DropIndexOptions` to use for the command
9595
* - session: Optional `ClientSession` to use when executing this command
9696
*
97-
* - Returns: The result of dropping the index.
98-
*
9997
* - Throws:
10098
* - `WriteError` if an error occurs while performing the command.
10199
* - `CommandError` if an error occurs that prevents the command from executing.
102100
* - `InvalidArgumentError` if the options passed in form an invalid combination.
103101
* - `EncodingError` if an error occurs while encoding the options.
104102
*/
105-
@discardableResult
106103
public func dropIndex(
107104
_ name: String,
108105
options: DropIndexOptions? = nil,
109106
session: ClientSession? = nil
110-
) throws -> DropIndexesResult {
111-
return try self.asyncColl.dropIndex(name, options: options, session: session?.asyncSession).wait()
107+
) throws {
108+
try self.asyncColl.dropIndex(name, options: options, session: session?.asyncSession).wait()
112109
}
113110

114111
/**
@@ -119,22 +116,19 @@ extension MongoCollection {
119116
* - options: Optional `DropIndexOptions` to use for the command
120117
* - session: Optional `ClientSession` to use when executing this command
121118
*
122-
* - Returns: The result of dropping the index.
123-
*
124119
* - Throws:
125120
* - `WriteError` if an error occurs while performing the command.
126121
* - `CommandError` if an error occurs that prevents the command from executing.
127122
* - `InvalidArgumentError` if the options passed in form an invalid combination.
128123
* - `LogicError` if the provided session is inactive.
129124
* - `EncodingError` if an error occurs while encoding the options.
130125
*/
131-
@discardableResult
132126
public func dropIndex(
133127
_ keys: Document,
134128
options: DropIndexOptions? = nil,
135129
session: ClientSession? = nil
136-
) throws -> DropIndexesResult {
137-
return try self.asyncColl.dropIndex(keys, options: options, session: session?.asyncSession).wait()
130+
) throws {
131+
try self.asyncColl.dropIndex(keys, options: options, session: session?.asyncSession).wait()
138132
}
139133

140134
/**
@@ -145,22 +139,19 @@ extension MongoCollection {
145139
* - options: Optional `DropIndexOptions` to use for the command
146140
* - session: Optional `ClientSession` to use when executing this command
147141
*
148-
* - Returns: The result of dropping the index.
149-
*
150142
* - Throws:
151143
* - `WriteError` if an error occurs while performing the command.
152144
* - `CommandError` if an error occurs that prevents the command from executing.
153145
* - `InvalidArgumentError` if the options passed in form an invalid combination.
154146
* - `LogicError` if the provided session is inactive.
155147
* - `EncodingError` if an error occurs while encoding the options.
156148
*/
157-
@discardableResult
158149
public func dropIndex(
159150
_ model: IndexModel,
160151
options: DropIndexOptions? = nil,
161152
session: ClientSession? = nil
162-
) throws -> DropIndexesResult {
163-
return try self.asyncColl.dropIndex(model, options: options, session: session?.asyncSession).wait()
153+
) throws {
154+
try self.asyncColl.dropIndex(model, options: options, session: session?.asyncSession).wait()
164155
}
165156

166157
/**
@@ -170,21 +161,18 @@ extension MongoCollection {
170161
* - options: Optional `DropIndexOptions` to use for the command
171162
* - session: Optional `ClientSession` to use when executing this command
172163
*
173-
* - Returns: The result of dropping the indexes.
174-
*
175164
* - Throws:
176165
* - `WriteError` if an error occurs while performing the command.
177166
* - `CommandError` if an error occurs that prevents the command from executing.
178167
* - `InvalidArgumentError` if the options passed in form an invalid combination.
179168
* - `LogicError` if the provided session is inactive.
180169
* - `EncodingError` if an error occurs while encoding the options.
181170
*/
182-
@discardableResult
183171
public func dropIndexes(
184172
options: DropIndexOptions? = nil,
185173
session: ClientSession? = nil
186-
) throws -> DropIndexesResult {
187-
return try self.asyncColl.dropIndexes(options: options, session: session?.asyncSession).wait()
174+
) throws {
175+
try self.asyncColl.dropIndexes(options: options, session: session?.asyncSession).wait()
188176
}
189177

190178
/**

0 commit comments

Comments
 (0)