Skip to content

Commit 689781d

Browse files
committed
refactor: add @_disfavoredOverload to .min()/.max() methods in BasicMath
Added `@_disfavoredOverload` attribute to QueryExpression.min() and QueryExpression.max() methods to prevent conflicts with Swift's stdlib Sequence.min() and Sequence.max() methods. Changes: - Added @_disfavoredOverload to all four .min()/.max() methods in BasicMath.swift - Added documentation explaining the disambiguation approach - Created comprehensive test suite (BasicMathTests.swift) with 25 tests - Tests demonstrate both Swift stdlib and SQL methods working together - All 860 tests passing (including 25 new tests) Benefits: - Users can use Swift's .min()/.max() on regular Swift collections - Users can use SQL's .min()/.max() on QueryExpression types - No explicit type annotations needed - Consistent with existing .joined() disambiguation pattern
1 parent bc06e1f commit 689781d

File tree

3 files changed

+380
-0
lines changed

3 files changed

+380
-0
lines changed

Sources/StructuredQueriesPostgres/Functions/Mathematical/BasicMath.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ extension QueryExpression where QueryValue: Comparable & QueryBindable {
278278
/// ```
279279
///
280280
/// > Note: For finding minimum across multiple values, use `least()` function.
281+
/// > The `@_disfavoredOverload` attribute ensures Swift's stdlib `Sequence.min()` is preferred
282+
/// > for regular Swift collections, while this method is available for QueryExpressions.
283+
@_disfavoredOverload
281284
public func min(_ other: QueryValue) -> some QueryExpression<QueryValue> {
282285
SQLQueryExpression(
283286
"least(\(self.queryFragment), \(bind: other))",
@@ -288,6 +291,10 @@ extension QueryExpression where QueryValue: Comparable & QueryBindable {
288291
/// Returns the smaller of two expression values
289292
///
290293
/// PostgreSQL's `least()` function for two values.
294+
///
295+
/// > Note: The `@_disfavoredOverload` attribute ensures Swift's stdlib `Sequence.min()` is preferred
296+
/// > for regular Swift collections, while this method is available for QueryExpressions.
297+
@_disfavoredOverload
291298
public func min(_ other: some QueryExpression<QueryValue>) -> some QueryExpression<QueryValue> {
292299
SQLQueryExpression(
293300
"least(\(self.queryFragment), \(other.queryFragment))",
@@ -305,6 +312,9 @@ extension QueryExpression where QueryValue: Comparable & QueryBindable {
305312
/// ```
306313
///
307314
/// > Note: For finding maximum across multiple values, use `greatest()` function.
315+
/// > The `@_disfavoredOverload` attribute ensures Swift's stdlib `Sequence.max()` is preferred
316+
/// > for regular Swift collections, while this method is available for QueryExpressions.
317+
@_disfavoredOverload
308318
public func max(_ other: QueryValue) -> some QueryExpression<QueryValue> {
309319
SQLQueryExpression(
310320
"greatest(\(self.queryFragment), \(bind: other))",
@@ -315,6 +325,10 @@ extension QueryExpression where QueryValue: Comparable & QueryBindable {
315325
/// Returns the larger of two expression values
316326
///
317327
/// PostgreSQL's `greatest()` function for two values.
328+
///
329+
/// > Note: The `@_disfavoredOverload` attribute ensures Swift's stdlib `Sequence.max()` is preferred
330+
/// > for regular Swift collections, while this method is available for QueryExpressions.
331+
@_disfavoredOverload
318332
public func max(_ other: some QueryExpression<QueryValue>) -> some QueryExpression<QueryValue> {
319333
SQLQueryExpression(
320334
"greatest(\(self.queryFragment), \(other.queryFragment))",

0 commit comments

Comments
 (0)