mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Enhance documentation for features brought by #690
This commit is contained in:
1 parent
4c8574aa4c
commit
f7465896fa
1 file changed
+16
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user