Skip to content

Commit dcbc1ec

Browse files
committedNov 22, 2021
first method upgraded to async await
1 parent 220842d commit dcbc1ec

10 files changed

+110
-90
lines changed
 

‎Package.resolved

+65-47
Original file line numberDiff line numberDiff line change
@@ -6,179 +6,197 @@
66
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
77
"state": {
88
"branch": null,
9-
"revision": "48e284d1ea6d0e8baac1af1c4ad8bd298670caf6",
10-
"version": "1.0.1"
9+
"revision": "ec2e080d7011a81bd67f10bf41efe6104d7799d6",
10+
"version": "1.7.0"
1111
}
1212
},
1313
{
1414
"package": "async-kit",
1515
"repositoryURL": "https://github.com/vapor/async-kit.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "cb8e6ee62dc6684a95132f8d46511956e78ee0f1",
19-
"version": "1.0.0-beta.2"
18+
"revision": "748c026f4dc93c0b9d05fe43a07d3922ca126744",
19+
"version": "1.10.0"
2020
}
2121
},
2222
{
2323
"package": "console-kit",
2424
"repositoryURL": "https://github.com/vapor/console-kit.git",
2525
"state": {
2626
"branch": null,
27-
"revision": "535874e4654b17cebb422b9e17353e85d421a118",
28-
"version": "4.0.0-beta.2"
27+
"revision": "75ea3b627d88221440b878e5dfccc73fd06842ed",
28+
"version": "4.2.7"
2929
}
3030
},
3131
{
3232
"package": "fluent",
3333
"repositoryURL": "https://github.com/vapor/fluent.git",
3434
"state": {
3535
"branch": null,
36-
"revision": "5adacb3bd3e073fb2142b7713acce8992e3aadae",
37-
"version": "4.0.0-beta.2"
36+
"revision": "ea707ee318066a073c95b2b2df1aa640fcb67f9e",
37+
"version": "4.4.0"
3838
}
3939
},
4040
{
4141
"package": "fluent-kit",
4242
"repositoryURL": "https://github.com/vapor/fluent-kit.git",
4343
"state": {
4444
"branch": null,
45-
"revision": "c232981184891cb762f041d0c70f96b254d97a78",
46-
"version": "1.0.0-beta.2.5"
45+
"revision": "4dc196da17177d0099510c6a3e8b6db0e33466b5",
46+
"version": "1.16.2"
4747
}
4848
},
4949
{
5050
"package": "fluent-sqlite-driver",
5151
"repositoryURL": "https://github.com/vapor/fluent-sqlite-driver.git",
5252
"state": {
5353
"branch": null,
54-
"revision": "d2bb65b333a046e8ed64053312a6d6bdeb3a3590",
55-
"version": "4.0.0-beta.2"
54+
"revision": "9ca34be792979fb0f1dbd8e45b8af9f1e1440474",
55+
"version": "4.1.0"
5656
}
5757
},
5858
{
5959
"package": "multipart-kit",
6060
"repositoryURL": "https://github.com/vapor/multipart-kit.git",
6161
"state": {
6262
"branch": null,
63-
"revision": "b41a49b5756ac3fbf8f2b07228a7e75f9b60731a",
64-
"version": "4.0.0-beta.2"
65-
}
66-
},
67-
{
68-
"package": "open-crypto",
69-
"repositoryURL": "https://github.com/vapor/open-crypto.git",
70-
"state": {
71-
"branch": null,
72-
"revision": "90c49bc68ee6d992fa13cf84ca8fc54b97eaf4cc",
73-
"version": "4.0.0-beta.2"
63+
"revision": "2dd9368a3c9580792b77c7ef364f3735909d9996",
64+
"version": "4.5.1"
7465
}
7566
},
7667
{
7768
"package": "routing-kit",
7869
"repositoryURL": "https://github.com/vapor/routing-kit.git",
7970
"state": {
8071
"branch": null,
81-
"revision": "6a8a1636ad26494b03f3c72d74a420fc3a44949c",
82-
"version": "4.0.0-beta.3"
72+
"revision": "a0801a36a6ad501d5ad6285cbcd4774de6b0a734",
73+
"version": "4.3.0"
8374
}
8475
},
8576
{
8677
"package": "sql-kit",
8778
"repositoryURL": "https://github.com/vapor/sql-kit.git",
8879
"state": {
8980
"branch": null,
90-
"revision": "d09b5527fb0c341f6993e4f5233fadbb7dee1c76",
91-
"version": "3.0.0-beta.3"
81+
"revision": "dff8aba9973f2edd7ddb1d29d8d6994a516cf3c1",
82+
"version": "3.13.0"
9283
}
9384
},
9485
{
9586
"package": "sqlite-kit",
9687
"repositoryURL": "https://github.com/vapor/sqlite-kit.git",
9788
"state": {
9889
"branch": null,
99-
"revision": "9f3a7fb91c983b943edd239351ed9cd0cb75eda1",
100-
"version": "4.0.0-beta.3"
90+
"revision": "2ec279b9c845cec254646834b66338551a024561",
91+
"version": "4.0.2"
10192
}
10293
},
10394
{
10495
"package": "sqlite-nio",
10596
"repositoryURL": "https://github.com/vapor/sqlite-nio.git",
10697
"state": {
10798
"branch": null,
108-
"revision": "1bf9748cc62cd96d440a712a06cb301b66a27550",
109-
"version": "1.0.0-beta.2.1"
99+
"revision": "6481dd0b01112d082dd7eb362782126e81964138",
100+
"version": "1.1.0"
101+
}
102+
},
103+
{
104+
"package": "swift-backtrace",
105+
"repositoryURL": "https://github.com/swift-server/swift-backtrace.git",
106+
"state": {
107+
"branch": null,
108+
"revision": "d3e04a9d4b3833363fb6192065b763310b156d54",
109+
"version": "1.3.1"
110+
}
111+
},
112+
{
113+
"package": "swift-crypto",
114+
"repositoryURL": "https://github.com/apple/swift-crypto.git",
115+
"state": {
116+
"branch": null,
117+
"revision": "9b5ef28601a9c745c9cdb54d3f243e28ac830982",
118+
"version": "2.0.1"
110119
}
111120
},
112121
{
113122
"package": "swift-log",
114123
"repositoryURL": "https://github.com/apple/swift-log.git",
115124
"state": {
116125
"branch": null,
117-
"revision": "74d7b91ceebc85daf387ebb206003f78813f71aa",
118-
"version": "1.2.0"
126+
"revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
127+
"version": "1.4.2"
119128
}
120129
},
121130
{
122131
"package": "swift-metrics",
123132
"repositoryURL": "https://github.com/apple/swift-metrics.git",
124133
"state": {
125134
"branch": null,
126-
"revision": "3fefedaaef285830cc98ae80231140122076a7e0",
127-
"version": "1.2.0"
135+
"revision": "3edd2f57afc4e68e23c3e4956bc8b65ca6b5b2ff",
136+
"version": "2.2.0"
128137
}
129138
},
130139
{
131140
"package": "swift-nio",
132141
"repositoryURL": "https://github.com/apple/swift-nio.git",
133142
"state": {
134143
"branch": null,
135-
"revision": "f6487a11d80bfb9a0a0a752b7442847c7e3a8253",
136-
"version": "2.12.0"
144+
"revision": "addf69cfe60376c325397c8926589415576b1dd1",
145+
"version": "2.34.0"
137146
}
138147
},
139148
{
140149
"package": "swift-nio-extras",
141150
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
142151
"state": {
143152
"branch": null,
144-
"revision": "53808818c2015c45247cad74dc05c7a032c96a2f",
145-
"version": "1.3.2"
153+
"revision": "f73ca5ee9c6806800243f1ac415fcf82de9a4c91",
154+
"version": "1.10.2"
146155
}
147156
},
148157
{
149158
"package": "swift-nio-http2",
150159
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
151160
"state": {
152161
"branch": null,
153-
"revision": "c1bfb7ce3f201e41ff60ef38fa63e67e0eb66a24",
154-
"version": "1.9.0"
162+
"revision": "326f7f9a8c8c8402e3691adac04911cac9f9d87f",
163+
"version": "1.18.4"
155164
}
156165
},
157166
{
158167
"package": "swift-nio-ssl",
159168
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
160169
"state": {
161170
"branch": null,
162-
"revision": "b75ffaba05b2cffdb1420d558f1a90b4e6c46dcc",
163-
"version": "2.5.0"
171+
"revision": "36f6419f2b1b6490a8c0faa840298e28027cefe9",
172+
"version": "2.16.3"
173+
}
174+
},
175+
{
176+
"package": "swift-nio-transport-services",
177+
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
178+
"state": {
179+
"branch": null,
180+
"revision": "e7f5278a26442dc46783ba7e063643d524e414a0",
181+
"version": "1.11.3"
164182
}
165183
},
166184
{
167185
"package": "vapor",
168186
"repositoryURL": "https://github.com/vapor/vapor.git",
169187
"state": {
170188
"branch": null,
171-
"revision": "88bc369b95036fc02394f045efe0a36af3bfccdb",
172-
"version": "4.0.0-beta.3"
189+
"revision": "6a5a3b5244d39e2614382c77ddf62e63b712ad06",
190+
"version": "4.53.0"
173191
}
174192
},
175193
{
176194
"package": "websocket-kit",
177195
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
178196
"state": {
179197
"branch": null,
180-
"revision": "4c9da4fe7d8186243418254031288ab5ee0202e4",
181-
"version": "2.0.0-beta.2.1"
198+
"revision": "b1c4df8f6c848c2e977726903bbe6578eed723ad",
199+
"version": "2.2.0"
182200
}
183201
}
184202
]

‎Package.swift

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(
55
name: "CrudRouter",
66
platforms: [
7-
.macOS(.v10_14)
7+
.macOS(.v12)
88
],
99
products: [
1010
.library(name: "CrudRouter", targets: ["CrudRouter"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-beta.3"),
14-
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-beta.2"),
15-
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.0.0-beta.2"),
13+
.package(url: "https://github.com/vapor/vapor.git", from: "4.53.0"),
14+
.package(url: "https://github.com/vapor/fluent.git", from: "4.4.0"),
15+
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.1.0"),
1616
],
1717
targets: [
18-
.target(name: "CrudRouter", dependencies: ["Fluent", "FluentSQLiteDriver", "Vapor"]),
19-
.testTarget(name: "CrudRouterTests", dependencies: ["CrudRouter", "FluentSQLiteDriver", "XCTVapor"]),
18+
.target(name: "CrudRouter", dependencies: [
19+
.product(name: "Vapor", package: "vapor"),
20+
.product(name: "Fluent", package: "fluent"),
21+
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver")
22+
]),
23+
.testTarget(name: "CrudRouterTests", dependencies: [
24+
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
25+
.product(name: "XCTVapor", package: "vapor")
26+
]),
2027
]
2128
)

‎Sources/CrudRouter/ControllerProtocols/CrudChildrenControllerProtocol.swift

+15-20
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ import FluentKit
33
import Fluent
44
import NIOExtras
55

6-
extension EventLoopFuture where Value: Model {
7-
func delete(on db: Database) -> EventLoopFuture<Void> {
8-
return self.map { model in
9-
return model.delete(on: db)
10-
}
11-
}
12-
}
6+
//extension EventLoopFuture where Value: Model {
7+
// func delete(on db: Database) async -> Void {
8+
// return model.delete(on: db)
9+
// }
10+
//}
1311

1412
public protocol CrudChildrenControllerProtocol {
1513
associatedtype ParentType: Model & Content where ParentType.IDValue: LosslessStringConvertible
1614
associatedtype ChildType: Model & Content where ChildType.IDValue: LosslessStringConvertible
1715

18-
var children: KeyPath<ParentType, Children<ParentType, ChildType>> { get }
16+
var children: KeyPath<ParentType, ChildrenProperty<ParentType, ChildType>> { get }
1917

2018
func index(_ req: Request) throws -> EventLoopFuture<ChildType>
2119
func indexAll(_ req: Request) throws -> EventLoopFuture<[ChildType]>
@@ -82,19 +80,16 @@ public extension CrudChildrenControllerProtocol {
8280
}
8381
}
8482

85-
func delete(_ req: Request) throws -> EventLoopFuture<HTTPStatus> {
83+
func delete(_ req: Request) async throws -> HTTPStatus {
8684
let parentId = try req.getId(modelType: ParentType.self)
87-
88-
return try ParentType
89-
.find(parentId, on: req.db)
90-
.unwrap(or: Abort(.notFound))
91-
.throwingFlatMap { parent -> EventLoopFuture<HTTPStatus> in
92-
return try parent[keyPath: self.children]
93-
.query(on: req.db)
94-
.first()
95-
.unwrap(or: Abort(.notFound))
96-
.delete(on: req.db)
97-
.transform(to: HTTPStatus.ok)
85+
guard
86+
let parent = await ParentType.find(parentId, on: req.db),
87+
let child = try await parent[keyPath: self.children].query(on: req.db).first()
88+
{
89+
throw Abort(.notFound)
9890
}
91+
92+
try await child.delete(on: req.db)
93+
return HTTPStatus.ok
9994
}
10095
}

‎Sources/CrudRouter/ControllerProtocols/CrudParentControllerProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public protocol CrudParentControllerProtocol {
55
associatedtype ParentType: Model & Content where ParentType.IDValue: LosslessStringConvertible
66
associatedtype ChildType: Model & Content where ChildType.IDValue: LosslessStringConvertible
77

8-
var relation: KeyPath<ChildType, Parent<ParentType>> { get }
8+
var relation: KeyPath<ChildType, ParentProperty<ChildType, ParentType>> { get }
99

1010
func index(_ req: Request) throws -> EventLoopFuture<ParentType>
1111
func update(_ req: Request) throws -> EventLoopFuture<ParentType>

‎Sources/CrudRouter/ControllerProtocols/CrudSiblingsControllerProtocol.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public protocol CrudSiblingsControllerProtocol {
1919
associatedtype ChildType: Model & Content where ChildType.IDValue: LosslessStringConvertible
2020
associatedtype ThroughType: Model
2121

22-
var siblings: KeyPath<ParentType, Siblings<ParentType, ChildType, ThroughType>> { get }
22+
var siblings: KeyPath<ParentType, SiblingsProperty<ParentType, ChildType, ThroughType>> { get }
2323

2424
func index(_ req: Request) throws -> EventLoopFuture<ChildType>
2525
func indexAll(_ req: Request) throws -> EventLoopFuture<[ChildType]>
@@ -57,7 +57,7 @@ public extension CrudSiblingsControllerProtocol {
5757
.find(parentId, on: req.db)
5858
.unwrap(or: Abort(.notFound))
5959
.throwingFlatMap { parent -> EventLoopFuture<ChildType> in
60-
let siblings: Siblings<ParentType, ChildType, ThroughType> = parent[keyPath: self.siblings]
60+
let siblings: SiblingsProperty<ParentType, ChildType, ThroughType> = parent[keyPath: self.siblings]
6161
let siblingsQuery = try siblings.query(on: req.db)
6262
return siblingsQuery
6363
.first()

‎Sources/CrudRouter/ControllerProtocols/Crudable.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public protocol Crudable: ControllerProtocol {
66

77
func crud<ParentType>(
88
at path: PathComponent...,
9-
parent relation: KeyPath<ChildType, Parent<ParentType>>,
9+
parent relation: KeyPath<ChildType, ParentProperty<ChildType, ParentType>>,
1010
_ either: OnlyExceptEither<ParentRouterMethod>,
1111
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?
1212
) where
@@ -16,7 +16,7 @@ public protocol Crudable: ControllerProtocol {
1616

1717
func crud<ChildChildType>(
1818
at path: PathComponent...,
19-
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
19+
children relation: KeyPath<ChildType, ChildrenProperty<ChildType, ChildChildType>>,
2020
_ either: OnlyExceptEither<ChildrenRouterMethod>,
2121
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?
2222
) where
@@ -25,7 +25,7 @@ public protocol Crudable: ControllerProtocol {
2525

2626
func crud<ChildChildType, ThroughType>(
2727
at path: PathComponent...,
28-
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
28+
siblings relation: KeyPath<ChildType, SiblingsProperty<ChildType, ChildChildType, ThroughType>>,
2929
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod>,
3030
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?
3131
) where
@@ -51,7 +51,7 @@ public protocol Crudable: ControllerProtocol {
5151
extension Crudable {
5252
public func crud<ParentType>(
5353
at path: PathComponent...,
54-
parent relation: KeyPath<ChildType, Parent<ParentType>>,
54+
parent relation: KeyPath<ChildType, ParentProperty<ChildType, ParentType>>,
5555
_ either: OnlyExceptEither<ParentRouterMethod> = .only([.read, .update]),
5656
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?=nil
5757
) where
@@ -82,7 +82,7 @@ extension Crudable {
8282

8383
public func crud<ChildChildType>(
8484
at path: PathComponent...,
85-
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
85+
children relation: KeyPath<ChildType, ChildrenProperty<ChildType, ChildChildType>>,
8686
_ either: OnlyExceptEither<ChildrenRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
8787
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?=nil
8888
) where
@@ -112,7 +112,7 @@ extension Crudable {
112112

113113
public func crud<ChildChildType, ThroughType>(
114114
at path: PathComponent...,
115-
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
115+
siblings relation: KeyPath<ChildType, SiblingsProperty<ChildType, ChildChildType, ThroughType>>,
116116
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
117117
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?=nil
118118
) where

‎Sources/CrudRouter/CrudChildrenController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public struct CrudChildrenController<ChildT: Model & Content, ParentT: Model & C
88
public typealias ParentType = ParentT
99
public typealias ChildType = ChildT
1010

11-
public var children: KeyPath<ParentT, Children<ParentT, ChildT>>
11+
public var children: KeyPath<ParentT, ChildrenProperty<ParentT, ChildT>>
1212
public let path: [PathComponent]
1313
let activeMethods: Set<ChildrenRouterMethod>
1414

1515
init(
16-
childrenRelation: KeyPath<ParentT, Children<ParentT, ChildT>>,
16+
childrenRelation: KeyPath<ParentT, ChildrenProperty<ParentT, ChildT>>,
1717
path: [PathComponent],
1818
router: RoutesBuilder,
1919
activeMethods: Set<ChildrenRouterMethod>

‎Sources/CrudRouter/CrudParentController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ public struct CrudParentController<ChildT: Model & Content, ParentT: Model & Con
77
public typealias ParentType = ParentT
88
public typealias ChildType = ChildT
99

10-
public let relation: KeyPath<ChildType, Parent<ParentType>>
10+
public let relation: KeyPath<ChildType, ParentProperty<ChildType, ParentType>>
1111
public let path: [PathComponent]
1212
public let router: RoutesBuilder
1313
let activeMethods: Set<ParentRouterMethod>
1414

1515
init(
16-
relation: KeyPath<ChildType, Parent<ParentType>>,
16+
relation: KeyPath<ChildType, ParentProperty<ChildType, ParentType>>,
1717
path: [PathComponent],
1818
router: RoutesBuilder,
1919
activeMethods: Set<ParentRouterMethod>

‎Sources/CrudRouter/CrudSiblingsController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public struct CrudSiblingsController<
1313
public typealias ChildType = ChildType
1414
public typealias ThroughType = ThroughType
1515

16-
public var siblings: KeyPath<ParentType, Siblings<ParentType, ChildType, ThroughType>>
16+
public var siblings: KeyPath<ParentType, SiblingsProperty<ParentType, ChildType, ThroughType>>
1717
public let path: [PathComponent]
1818
public let router: RoutesBuilder
1919
let activeMethods: Set<ModifiableSiblingRouterMethod>
2020

2121
init(
22-
siblingRelation: KeyPath<ParentType, Siblings<ParentType, ChildType, ThroughType>>,
22+
siblingRelation: KeyPath<ParentType, SiblingsProperty<ParentType, ChildType, ThroughType>>,
2323
path: [PathComponent],
2424
router: RoutesBuilder,
2525
activeMethods: Set<ModifiableSiblingRouterMethod>

‎Tests/CrudRouterTests/TestModels/Galaxy.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vapor
2-
import FluentSQLiteDriver
2+
import FluentKit
33
import CrudRouter
44

55
public final class Galaxy: Model, Content {

0 commit comments

Comments
 (0)
Please sign in to comment.