mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Merge branch 'development' into dev/migration
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
efcc3a3dfb
4 files changed
+39
-2
No files matched your search
@@ -65,6 +65,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
|
||||
**New**
|
||||
|
||||
- [#706](https://github.com/groue/GRDB.swift/pull/706): Enhance SQLLiteral and SQL interpolation again
|
||||
- [#709](https://github.com/groue/GRDB.swift/pull/709): Simplify DatabaseMigrator API
|
||||
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ Such literal expressions can be returned by Swift functions:
|
||||
|
||||
```swift
|
||||
func date(_ value: SQLExpressible) -> SQLExpression {
|
||||
SQLLiteral("DATE(\(lhs.sqlExpression))").sqlExpression
|
||||
SQLLiteral("DATE(\(value))").sqlExpression
|
||||
}
|
||||
|
||||
// SELECT * FROM "player" WHERE DATE("createdAt") = '2020-01-23'
|
||||
|
||||
@@ -57,7 +57,16 @@ extension SQLInterpolation {
|
||||
/// let request: SQLRequest<Int> = """
|
||||
/// SELECT score + \(bonus) FROM player
|
||||
/// """
|
||||
public mutating func appendInterpolation<T: SQLExpressible>(_ expressible: T?) {
|
||||
///
|
||||
/// You can also derive literal expressions from other expressions:
|
||||
///
|
||||
/// func date(_ value: SQLExpressible) -> SQLExpression {
|
||||
/// SQLLiteral("DATE(\(value))").sqlExpression
|
||||
/// }
|
||||
///
|
||||
/// // SELECT * FROM player WHERE DATE(createdAt) = '2020-02-25'
|
||||
/// let request = Player.filter(date(Column("createdAt")) == "2020-02-25")
|
||||
public mutating func appendInterpolation(_ expressible: SQLExpressible?) {
|
||||
if let expressible = expressible {
|
||||
elements.append(.expression(expressible.sqlExpression))
|
||||
} else {
|
||||
|
||||
@@ -473,6 +473,33 @@ extension SQLLiteralTests {
|
||||
SELECT * FROM "player" WHERE (DATE("createdAt")) = '2020-01-23'
|
||||
""")
|
||||
}
|
||||
|
||||
do {
|
||||
// Here we test that users can define functions that return
|
||||
// literal expressions.
|
||||
func date(_ value: SQLExpressible) -> SQLExpression {
|
||||
return SQLLiteral("DATE(\(value))").sqlExpression
|
||||
}
|
||||
let createdAt = Column("createdAt")
|
||||
let request = Player.filter(date(createdAt) == "2020-01-23")
|
||||
try assertEqualSQL(db, request, """
|
||||
SELECT * FROM "player" WHERE (DATE("createdAt")) = '2020-01-23'
|
||||
""")
|
||||
}
|
||||
|
||||
do {
|
||||
// Here we test that users can still define functions that
|
||||
// return literal expressions with the previously
|
||||
// supported technique.
|
||||
func date(_ value: SQLExpressible) -> SQLExpression {
|
||||
return SQLLiteral("DATE(\(value.sqlExpression))").sqlExpression
|
||||
}
|
||||
let createdAt = Column("createdAt")
|
||||
let request = Player.filter(date(createdAt) == "2020-01-23")
|
||||
try assertEqualSQL(db, request, """
|
||||
SELECT * FROM "player" WHERE (DATE("createdAt")) = '2020-01-23'
|
||||
""")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user