Skip to content

Commit 9e6a764

Browse files
committed
Convert Build
1 parent 624f254 commit 9e6a764

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

Sources/App/Commands/DeleteBuilds.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Vapor
1616

1717

18-
struct DeleteBuildsCommand: Command {
18+
struct DeleteBuildsCommand: AsyncCommand {
1919
struct Signature: CommandSignature {
2020
@Option(name: "version-id", short: "v")
2121
var versionId: UUID?
@@ -27,25 +27,21 @@ struct DeleteBuildsCommand: Command {
2727

2828
var help: String { "Delete build records" }
2929

30-
func run(using context: CommandContext, signature: Signature) throws {
30+
func run(using context: CommandContext, signature: Signature) async throws {
3131

3232
switch (signature.versionId, signature.packageId) {
3333
case let (versionId?, .none):
3434
context.console.info("Deleting builds for version id \(versionId) ...")
35-
let count = try Build.delete(on: context.application.db,
36-
versionId: versionId).wait()
35+
let count = try await Build.delete(on: context.application.db, versionId: versionId)
3736
context.console.info("Deleted \(pluralizedCount: count, singular: "record")")
3837

3938
case let (.none, packageId?):
4039
context.console.info("Deleting builds for package id \(packageId) ...")
4140
let count: Int
4241
if let kind = signature.latest {
43-
count = try Build.delete(on: context.application.db,
44-
packageId: packageId,
45-
versionKind: kind).wait()
42+
count = try await Build.delete(on: context.application.db, packageId: packageId, versionKind: kind)
4643
} else {
47-
count = try Build.delete(on: context.application.db,
48-
packageId: packageId).wait()
44+
count = try await Build.delete(on: context.application.db, packageId: packageId)
4945
}
5046
context.console.info("Deleted \(pluralizedCount: count, singular: "record")")
5147

Sources/App/Models/Build.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ extension Build {
221221
// MARK: - Deletion
222222

223223
extension Build {
224-
static func delete(on database: Database, versionId: Version.Id) -> EventLoopFuture<Int> {
225-
delete(on: database, deleteSQL: """
224+
static func delete(on database: Database, versionId: Version.Id) async throws -> Int {
225+
try await delete(on: database, deleteSQL: """
226226
DELETE
227227
FROM builds b
228228
USING versions v
@@ -233,8 +233,8 @@ extension Build {
233233
}
234234

235235
static func delete(on database: Database,
236-
packageId: Package.Id) -> EventLoopFuture<Int> {
237-
delete(on: database, deleteSQL: """
236+
packageId: Package.Id) async throws -> Int {
237+
try await delete(on: database, deleteSQL: """
238238
DELETE
239239
FROM builds b
240240
USING versions v, packages p
@@ -247,8 +247,8 @@ extension Build {
247247

248248
static func delete(on database: Database,
249249
packageId: Package.Id,
250-
versionKind: Version.Kind) -> EventLoopFuture<Int> {
251-
delete(on: database, deleteSQL: """
250+
versionKind: Version.Kind) async throws -> Int {
251+
try await delete(on: database, deleteSQL: """
252252
DELETE
253253
FROM builds b
254254
USING versions v, packages p
@@ -261,13 +261,13 @@ extension Build {
261261
}
262262

263263
static func delete(on database: Database,
264-
deleteSQL: SQLQueryString) -> EventLoopFuture<Int> {
264+
deleteSQL: SQLQueryString) async throws -> Int {
265265
guard let db = database as? SQLDatabase else {
266266
fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)")
267267
}
268-
return db.raw(deleteSQL)
268+
return try await db.raw(deleteSQL)
269269
.all()
270-
.map { $0.count }
270+
.count
271271
}
272272

273273
}

Tests/AppTests/BuildTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class BuildTests: AppTestCase {
320320
.save(on: app.db)
321321

322322
// MUT
323-
let count = try await Build.delete(on: app.db, versionId: vid2).get()
323+
let count = try await Build.delete(on: app.db, versionId: vid2)
324324

325325
// validate
326326
XCTAssertEqual(count, 1)
@@ -350,7 +350,7 @@ class BuildTests: AppTestCase {
350350

351351

352352
// MUT
353-
let count = try await Build.delete(on: app.db, packageId: pkgId2).get()
353+
let count = try await Build.delete(on: app.db, packageId: pkgId2)
354354

355355
// validate
356356
XCTAssertEqual(count, 1)
@@ -383,7 +383,7 @@ class BuildTests: AppTestCase {
383383
.save(on: app.db)
384384

385385
// MUT
386-
let count = try await Build.delete(on: app.db, packageId: pkgId2, versionKind: .defaultBranch).get()
386+
let count = try await Build.delete(on: app.db, packageId: pkgId2, versionKind: .defaultBranch)
387387

388388
// validate
389389
XCTAssertEqual(count, 1)

0 commit comments

Comments
 (0)