Enhance documentation for features brought by #690

This commit is contained in:
Gwendal Roué authored and GitHub committed 2020-02-25 14:59:11 +01:00
1 parent 4c8574aa4c
commit f7465896fa
1 file changed
+16
+16
View File
@@ -137,13 +137,29 @@ For example:
```swift
// SELECT * FROM player WHERE name = 'O''Brien'
let request = Player.filter(literal: "name = \("O'Brien")")
```
You can also build literals from other values. For example, let's call the `DATE` SQLite function on a query interface column:
```swift
// SELECT * FROM "player" WHERE DATE("createdAt") = '2020-01-23'
let createdAt = Column("createdAt")
let creationDay = SQLLiteral("DATE(\(createdAt))").sqlExpression
let request = Player.filter(creationDay == "2020-01-23")
```
Such literals can be returned by Swift functions:
```swift
func date(_ value: SQLExpressible) -> SQLExpression {
SQLLiteral("DATE(\(lhs.sqlExpression)").sqlExpression
}
// SELECT * FROM "player" WHERE DATE("createdAt") = '2020-01-23'
let createdAt = Column("createdAt")
let request = Player.filter(date(createdAt) == "2020-01-23")
```
## SQL Interpolation and Record Protocols