mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Merge pull request #722 from groue/dev/SE-0253
SE-0253: Callable values of user-defined nominal types
This commit is contained in:
5 files changed
+16
-10
No files matched your search
@@ -93,6 +93,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
- [#719](https://github.com/groue/GRDB.swift/pull/719): Bump required Swift version to 5.2
|
||||
- [#720](https://github.com/groue/GRDB.swift/pull/720): Turn deprecated APIs into unavailable ones
|
||||
- [#721](https://github.com/groue/GRDB.swift/pull/721): SE-0249: Key Path Expressions as Functions
|
||||
- [#722](https://github.com/groue/GRDB.swift/pull/722): SE-0253: Callable values of user-defined nominal types
|
||||
|
||||
|
||||
## 4.11.0
|
||||
|
||||
@@ -20,6 +20,12 @@ extension AssociationAggregate {
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
extension DatabaseFunction {
|
||||
@available(*, unavailable, renamed: "callAsFunction(_:)")
|
||||
public func apply(_ arguments: SQLExpressible...) -> SQLExpression
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
extension DatabaseMigrator {
|
||||
@available(*, unavailable, renamed: "registerMigration(_:migrate:)")
|
||||
public mutating func registerMigrationWithDeferredForeignKeyCheck(
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// MARK: - Custom Functions
|
||||
|
||||
extension DatabaseFunction {
|
||||
// TODO: rename call (https://forums.swift.org/t/se-0253-callable-values-of-user-defined-nominal-types/24177)
|
||||
/// Returns an SQL expression that applies the function.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-functions
|
||||
public func apply(_ arguments: SQLExpressible...) -> SQLExpression {
|
||||
public func callAsFunction(_ arguments: SQLExpressible...) -> SQLExpression {
|
||||
return SQLExpressionFunction(SQLFunctionName(name), arguments: arguments.map(\.sqlExpression))
|
||||
}
|
||||
}
|
||||
@@ -156,7 +155,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.capitalized)
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var capitalized: SQLExpression {
|
||||
return DatabaseFunction.capitalize.apply(sqlExpression)
|
||||
return DatabaseFunction.capitalize(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -166,7 +165,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.lowercased())
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var lowercased: SQLExpression {
|
||||
return DatabaseFunction.lowercase.apply(sqlExpression)
|
||||
return DatabaseFunction.lowercase(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -176,7 +175,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.uppercased())
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var uppercased: SQLExpression {
|
||||
return DatabaseFunction.uppercase.apply(sqlExpression)
|
||||
return DatabaseFunction.uppercase(sqlExpression)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +189,7 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedCapitalized: SQLExpression {
|
||||
return DatabaseFunction.localizedCapitalize.apply(sqlExpression)
|
||||
return DatabaseFunction.localizedCapitalize(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -201,7 +200,7 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedLowercased: SQLExpression {
|
||||
return DatabaseFunction.localizedLowercase.apply(sqlExpression)
|
||||
return DatabaseFunction.localizedLowercase(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -212,6 +211,6 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedUppercased: SQLExpression {
|
||||
return DatabaseFunction.localizedUppercase.apply(sqlExpression)
|
||||
return DatabaseFunction.localizedUppercase(sqlExpression)
|
||||
}
|
||||
}
|
||||
@@ -1836,7 +1836,7 @@ try dbQueue.read { db in
|
||||
|
||||
```swift
|
||||
// SELECT reverseString("name") FROM player
|
||||
Player.select(reverseString.apply(nameColumn))
|
||||
Player.select(reverseString(nameColumn))
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -1168,7 +1168,7 @@ class QueryInterfaceExpressionsTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
XCTAssertEqual(
|
||||
sql(dbQueue, tableRequest.select(customFunction.apply(Col.age, 1, 2))),
|
||||
sql(dbQueue, tableRequest.select(customFunction(Col.age, 1, 2))),
|
||||
"SELECT avgOf(\"age\", 1, 2) FROM \"readers\"")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user