Skip to content

Commit d1a2cb0

Browse files
committed
All closures that accept DatabaseComponents can throw
1 parent a5a1be2 commit d1a2cb0

File tree

9 files changed

+150
-152
lines changed

9 files changed

+150
-152
lines changed

GRDB/QueryInterface/Request/Association/Association.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ extension AssociationToOne {
305305
///
306306
/// ### Building Association Aggregates
307307
///
308-
/// - ``average(_:)-4n3up``
308+
/// - ``average(_:)-1ehdb``
309309
/// - ``count``
310310
/// - ``isEmpty``
311-
/// - ``max(_:)-1upp8``
312-
/// - ``min(_:)-7xc49``
313-
/// - ``sum(_:)-5p74s``
314-
/// - ``total(_:)-hudm``
311+
/// - ``max(_:)-a32j``
312+
/// - ``min(_:)-41jp8``
313+
/// - ``sum(_:)-47yg7``
314+
/// - ``total(_:)-6dd9d``
315315
///
316316
/// - ``AssociationAggregate``
317317
///

GRDB/QueryInterface/Request/Association/AssociationAggregate.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ extension AssociationToMany {
179179
/// }
180180
/// ```
181181
public func average(
182-
_ expression: (DatabaseComponents) -> some SQLSpecificExpressible
183-
) -> AssociationAggregate<OriginRowDecoder>
182+
_ expression: (DatabaseComponents) throws -> some SQLSpecificExpressible
183+
) rethrows -> AssociationAggregate<OriginRowDecoder>
184184
where RowDecoder: TableRecord
185185
{
186-
average(expression(RowDecoder.databaseComponents))
186+
try average(expression(RowDecoder.databaseComponents))
187187
}
188188

189189
/// Returns the maximum value of the given expression in associated records.
@@ -276,11 +276,11 @@ extension AssociationToMany {
276276
/// }
277277
/// ```
278278
public func max(
279-
_ expression: (DatabaseComponents) -> some SQLSpecificExpressible
280-
) -> AssociationAggregate<OriginRowDecoder>
279+
_ expression: (DatabaseComponents) throws -> some SQLSpecificExpressible
280+
) rethrows -> AssociationAggregate<OriginRowDecoder>
281281
where RowDecoder: TableRecord
282282
{
283-
max(expression(RowDecoder.databaseComponents))
283+
try max(expression(RowDecoder.databaseComponents))
284284
}
285285

286286
/// Returns the minimum value of the given expression in associated records.
@@ -373,11 +373,11 @@ extension AssociationToMany {
373373
/// }
374374
/// ```
375375
public func min(
376-
_ expression: (DatabaseComponents) -> some SQLSpecificExpressible
377-
) -> AssociationAggregate<OriginRowDecoder>
376+
_ expression: (DatabaseComponents) throws -> some SQLSpecificExpressible
377+
) rethrows -> AssociationAggregate<OriginRowDecoder>
378378
where RowDecoder: TableRecord
379379
{
380-
min(expression(RowDecoder.databaseComponents))
380+
try min(expression(RowDecoder.databaseComponents))
381381
}
382382

383383
/// Returns the sum of the given expression in associated records.
@@ -434,7 +434,7 @@ extension AssociationToMany {
434434
/// Returns the sum of the given expression in associated records.
435435
///
436436
/// This aggregate invokes the `SUM` SQL function.
437-
/// See also ``AssociationToMany/total(_:)-hudm`` and
437+
/// See also ``AssociationToMany/total(_:)-6dd9d`` and
438438
/// <https://www.sqlite.org/lang_aggfunc.html#sumunc>.
439439
///
440440
/// For example:
@@ -478,11 +478,11 @@ extension AssociationToMany {
478478
/// }
479479
/// ```
480480
public func sum(
481-
_ expression: (DatabaseComponents) -> some SQLSpecificExpressible
482-
) -> AssociationAggregate<OriginRowDecoder>
481+
_ expression: (DatabaseComponents) throws -> some SQLSpecificExpressible
482+
) rethrows -> AssociationAggregate<OriginRowDecoder>
483483
where RowDecoder: TableRecord
484484
{
485-
sum(expression(RowDecoder.databaseComponents))
485+
try sum(expression(RowDecoder.databaseComponents))
486486
}
487487

488488
/// Returns the sum of the given expression in associated records.
@@ -541,7 +541,7 @@ extension AssociationToMany {
541541
/// Returns the sum of the given expression in associated records.
542542
///
543543
/// This aggregate invokes the `TOTAL` SQL function.
544-
/// See also ``AssociationToMany/sum(_:)-5p74s`` and
544+
/// See also ``AssociationToMany/sum(_:)-47yg7`` and
545545
/// <https://www.sqlite.org/lang_aggfunc.html#sumunc>.
546546
///
547547
/// For example:
@@ -585,11 +585,11 @@ extension AssociationToMany {
585585
/// }
586586
/// ```
587587
public func total(
588-
_ expression: (DatabaseComponents) -> some SQLSpecificExpressible
589-
) -> AssociationAggregate<OriginRowDecoder>
588+
_ expression: (DatabaseComponents) throws -> some SQLSpecificExpressible
589+
) rethrows -> AssociationAggregate<OriginRowDecoder>
590590
where RowDecoder: TableRecord
591591
{
592-
total(expression(RowDecoder.databaseComponents))
592+
try total(expression(RowDecoder.databaseComponents))
593593
}
594594
}
595595

GRDB/QueryInterface/Request/QueryInterfaceRequest.swift

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/// ### Changing The Type of Fetched Results
5858
///
5959
/// - ``asRequest(of:)``
60-
/// - ``select(_:as:)-74lsr``
60+
/// - ``select(_:as:)-4cj9h``
6161
/// - ``select(literal:as:)``
6262
/// - ``select(sql:arguments:as:)``
6363
/// - ``selectID()``
@@ -228,12 +228,12 @@ extension QueryInterfaceRequest: SelectionRequest {
228228
///
229229
/// Any previous selection is discarded.
230230
public func select<T>(
231-
_ selection: (DatabaseComponents) -> any SQLSelectable,
232-
as type: T.Type = T.self)
233-
-> QueryInterfaceRequest<T>
231+
_ selection: (DatabaseComponents) throws -> any SQLSelectable,
232+
as type: T.Type = T.self
233+
) rethrows -> QueryInterfaceRequest<T>
234234
where RowDecoder: TableRecord
235235
{
236-
select(selection).asRequest(of: T.self)
236+
try select(selection).asRequest(of: T.self)
237237
}
238238

239239
/// Defines the result columns with an SQL string, and defines the type of
@@ -702,8 +702,8 @@ extension QueryInterfaceRequest {
702702
/// - precondition: The result of `select` is not empty.
703703
public func deleteAndFetchStatement(
704704
_ db: Database,
705-
select: (DatabaseComponents) -> [any SQLSelectable])
706-
throws -> Statement
705+
select: (DatabaseComponents) throws -> [any SQLSelectable]
706+
) throws -> Statement
707707
where RowDecoder: TableRecord
708708
{
709709
try deleteAndFetchStatement(db, selection: select(RowDecoder.databaseComponents))
@@ -887,8 +887,8 @@ extension QueryInterfaceRequest {
887887
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) // SQLite 3.35.0+
888888
public func deleteAndFetchStatement(
889889
_ db: Database,
890-
select: (DatabaseComponents) -> [any SQLSelectable])
891-
throws -> Statement
890+
select: (DatabaseComponents) throws -> [any SQLSelectable]
891+
) throws -> Statement
892892
where RowDecoder: TableRecord
893893
{
894894
try deleteAndFetchStatement(db, selection: select(RowDecoder.databaseComponents))
@@ -1059,7 +1059,7 @@ extension QueryInterfaceRequest {
10591059
public func updateAll(
10601060
_ db: Database,
10611061
onConflict conflictResolution: Database.ConflictResolution? = nil,
1062-
assignment: (DatabaseComponents) -> ColumnAssignment
1062+
assignment: (DatabaseComponents) throws -> ColumnAssignment
10631063
) throws -> Int
10641064
where RowDecoder: TableRecord
10651065
{
@@ -1094,7 +1094,7 @@ extension QueryInterfaceRequest {
10941094
public func updateAll(
10951095
_ db: Database,
10961096
onConflict conflictResolution: Database.ConflictResolution? = nil,
1097-
assignments: (DatabaseComponents) -> [ColumnAssignment]
1097+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
10981098
) throws -> Int
10991099
where RowDecoder: TableRecord
11001100
{
@@ -1208,9 +1208,9 @@ extension QueryInterfaceRequest {
12081208
public func updateAndFetchStatement(
12091209
_ db: Database,
12101210
onConflict conflictResolution: Database.ConflictResolution? = nil,
1211-
assignments: (DatabaseComponents) -> [ColumnAssignment],
1212-
select: (DatabaseComponents) -> [any SQLSelectable])
1213-
throws -> Statement
1211+
assignments: (DatabaseComponents) throws -> [ColumnAssignment],
1212+
select: (DatabaseComponents) -> [any SQLSelectable]
1213+
) throws -> Statement
12141214
where RowDecoder: TableRecord
12151215
{
12161216
try updateAndFetchStatement(
@@ -1303,8 +1303,8 @@ extension QueryInterfaceRequest {
13031303
public func updateAndFetchCursor(
13041304
_ db: Database,
13051305
onConflict conflictResolution: Database.ConflictResolution? = nil,
1306-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1307-
throws -> RecordCursor<RowDecoder>
1306+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1307+
) throws -> RecordCursor<RowDecoder>
13081308
where RowDecoder: FetchableRecord & TableRecord
13091309
{
13101310
try updateAndFetchCursor(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))
@@ -1382,8 +1382,8 @@ extension QueryInterfaceRequest {
13821382
public func updateAndFetchAll(
13831383
_ db: Database,
13841384
onConflict conflictResolution: Database.ConflictResolution? = nil,
1385-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1386-
throws -> [RowDecoder]
1385+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1386+
) throws -> [RowDecoder]
13871387
where RowDecoder: FetchableRecord & TableRecord
13881388
{
13891389
try updateAndFetchAll(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))
@@ -1453,8 +1453,8 @@ extension QueryInterfaceRequest {
14531453
public func updateAndFetchSet(
14541454
_ db: Database,
14551455
onConflict conflictResolution: Database.ConflictResolution? = nil,
1456-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1457-
throws -> Set<RowDecoder>
1456+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1457+
) throws -> Set<RowDecoder>
14581458
where RowDecoder: FetchableRecord & TableRecord & Hashable
14591459
{
14601460
try updateAndFetchSet(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))
@@ -1532,9 +1532,9 @@ extension QueryInterfaceRequest {
15321532
public func updateAndFetchStatement(
15331533
_ db: Database,
15341534
onConflict conflictResolution: Database.ConflictResolution? = nil,
1535-
assignments: (DatabaseComponents) -> [ColumnAssignment],
1536-
select: (DatabaseComponents) -> [any SQLSelectable])
1537-
throws -> Statement
1535+
assignments: (DatabaseComponents) throws -> [ColumnAssignment],
1536+
select: (DatabaseComponents) throws -> [any SQLSelectable]
1537+
) throws -> Statement
15381538
where RowDecoder: TableRecord
15391539
{
15401540
try updateAndFetchStatement(
@@ -1629,8 +1629,8 @@ extension QueryInterfaceRequest {
16291629
public func updateAndFetchCursor(
16301630
_ db: Database,
16311631
onConflict conflictResolution: Database.ConflictResolution? = nil,
1632-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1633-
throws -> RecordCursor<RowDecoder>
1632+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1633+
) throws -> RecordCursor<RowDecoder>
16341634
where RowDecoder: FetchableRecord & TableRecord
16351635
{
16361636
try updateAndFetchCursor(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))
@@ -1710,8 +1710,8 @@ extension QueryInterfaceRequest {
17101710
public func updateAndFetchAll(
17111711
_ db: Database,
17121712
onConflict conflictResolution: Database.ConflictResolution? = nil,
1713-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1714-
throws -> [RowDecoder]
1713+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1714+
) throws -> [RowDecoder]
17151715
where RowDecoder: FetchableRecord & TableRecord
17161716
{
17171717
try updateAndFetchAll(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))
@@ -1783,8 +1783,8 @@ extension QueryInterfaceRequest {
17831783
public func updateAndFetchSet(
17841784
_ db: Database,
17851785
onConflict conflictResolution: Database.ConflictResolution? = nil,
1786-
assignments: (DatabaseComponents) -> [ColumnAssignment])
1787-
throws -> Set<RowDecoder>
1786+
assignments: (DatabaseComponents) throws -> [ColumnAssignment]
1787+
) throws -> Set<RowDecoder>
17881788
where RowDecoder: FetchableRecord & TableRecord & Hashable
17891789
{
17901790
try updateAndFetchSet(db, onConflict: conflictResolution, assignments(RowDecoder.databaseComponents))

0 commit comments

Comments
 (0)