Skip to content

Commit

Permalink
Enhance documentation for features brought by #690
Browse files Browse the repository at this point in the history
  • Loading branch information
groue authored Feb 25, 2020
1 parent 4c8574a commit f746589
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Documentation/SQLInterpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f746589

Please sign in to comment.