diff --git a/Documentation/SQLInterpolation.md b/Documentation/SQLInterpolation.md index a9fae482ea..20b0cb9f97 100644 --- a/Documentation/SQLInterpolation.md +++ b/Documentation/SQLInterpolation.md @@ -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