@@ -12,20 +12,20 @@ struct WorldController {
1212 . get ( " updates " , use: updates)
1313 }
1414
15- /// In this test, each request is processed by fetching a single row from a
15+ /// In this test, each request is processed by fetching a single row from a
1616 /// simple database table. That row is then serialized as a JSON response.
1717 @Sendable func single( request: Request , context: Context ) async throws -> World {
1818 let id = Int32 . random ( in: 1 ... 10_000 )
1919 let rows = try await self . postgresClient. execute ( SelectWorldStatement ( id: id) )
20- guard let row = try await rows. first ( where: { _ in true } ) else {
20+ guard let row = try await rows. first ( where: { _ in true } ) else {
2121 throw HTTPError ( . notFound)
2222 }
2323 return World ( id: row. 0 , randomNumber: row. 1 )
2424 }
2525
26- /// In this test, each request is processed by fetching multiple rows from a
27- /// simple database table and serializing these rows as a JSON response. The
28- /// test is run multiple times: testing 1, 5, 10, 15, and 20 queries per request.
26+ /// In this test, each request is processed by fetching multiple rows from a
27+ /// simple database table and serializing these rows as a JSON response. The
28+ /// test is run multiple times: testing 1, 5, 10, 15, and 20 queries per request.
2929 /// All tests are run at 512 concurrency.
3030 @Sendable func multiple( request: Request , context: Context ) async throws -> [ World ] {
3131 let queries = ( request. uri. queryParameters. get ( " queries " , as: Int . self) ?? 1 ) . bound ( 1 , 500 )
@@ -34,23 +34,24 @@ struct WorldController {
3434 result. reserveCapacity ( queries)
3535 for _ in 0 ..< queries {
3636 let id = Int32 . random ( in: 1 ... 10_000 )
37- let rows = try await conn. execute ( SelectWorldStatement ( id: id) , logger: context. logger)
38- guard let row = try await rows. first ( where: { _ in true } ) else {
37+ let rows = try await conn. execute (
38+ SelectWorldStatement ( id: id) , logger: context. logger)
39+ guard let row = try await rows. first ( where: { _ in true } ) else {
3940 throw HTTPError ( . notFound)
4041 }
41- result. append ( World ( id: row. 0 , randomNumber: row. 1 ) )
42+ result. append ( World ( id: row. 0 , randomNumber: row. 1 ) )
4243 }
4344 return result
4445 }
4546 }
4647
47- /// This test exercises database writes. Each request is processed by fetching
48- /// multiple rows from a simple database table, converting the rows to in-memory
49- /// objects, modifying one attribute of each object in memory, updating each
50- /// associated row in the database individually, and then serializing the list
51- /// of objects as a JSON response. The test is run multiple times: testing 1, 5,
52- /// 10, 15, and 20 updates per request. Note that the number of statements per
53- /// request is twice the number of updates since each update is paired with one
48+ /// This test exercises database writes. Each request is processed by fetching
49+ /// multiple rows from a simple database table, converting the rows to in-memory
50+ /// objects, modifying one attribute of each object in memory, updating each
51+ /// associated row in the database individually, and then serializing the list
52+ /// of objects as a JSON response. The test is run multiple times: testing 1, 5,
53+ /// 10, 15, and 20 updates per request. Note that the number of statements per
54+ /// request is twice the number of updates since each update is paired with one
5455 /// query to fetch the object. All tests are run at 512 concurrency.
5556 @Sendable func updates( request: Request , context: Context ) async throws -> [ World ] {
5657 let queries = ( request. uri. queryParameters. get ( " queries " , as: Int . self) ?? 1 ) . bound ( 1 , 500 )
@@ -59,12 +60,15 @@ struct WorldController {
5960 result. reserveCapacity ( queries)
6061 for _ in 0 ..< queries {
6162 let id = Int32 . random ( in: 1 ... 10_000 )
62- let rows = try await conn. execute ( SelectWorldStatement ( id: id) , logger: context. logger)
63- guard let row = try await rows. first ( where: { _ in true } ) else {
63+ let rows = try await conn. execute (
64+ SelectWorldStatement ( id: id) , logger: context. logger)
65+ guard let row = try await rows. first ( where: { _ in true } ) else {
6466 throw HTTPError ( . notFound)
6567 }
6668 let randomNumber = Int32 . random ( in: 1 ... 10_000 )
67- _ = try await conn. execute ( UpdateWorldStatement ( id: id, randomNumber: randomNumber) , logger: context. logger)
69+ _ = try await conn. execute (
70+ UpdateWorldStatement ( id: id, randomNumber: randomNumber) , logger: context. logger
71+ )
6872 result. append ( World ( id: row. 0 , randomNumber: randomNumber) )
6973 }
7074 return result
@@ -76,7 +80,7 @@ struct WorldController {
7680
7781 let id : Int32
7882
79- static var sql = " SELECT id, randomnumber FROM World WHERE id = $1 "
83+ static let sql = " SELECT id, randomnumber FROM World WHERE id = $1 "
8084
8185 func makeBindings( ) throws -> PostgresNIO . PostgresBindings {
8286 var bindings = PostgresNIO . PostgresBindings ( capacity: 1 )
@@ -93,7 +97,7 @@ struct WorldController {
9397 let id : Int32
9498 let randomNumber : Int32
9599
96- static var sql = " UPDATE World SET randomnumber = $2 WHERE id = $1 "
100+ static let sql = " UPDATE World SET randomnumber = $2 WHERE id = $1 "
97101
98102 func makeBindings( ) throws -> PostgresNIO . PostgresBindings {
99103 var bindings = PostgresNIO . PostgresBindings ( capacity: 2 )
0 commit comments