Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance SQLLiteral and SQL interpolation again #706

Merged
merged 6 commits into from
Feb 26, 2020

Conversation

groue
Copy link
Owner

@groue groue commented Feb 25, 2020

This pull request improves over #690, so that it gets easier to define functions that build literal expressions with SQL interpolation:

func date(_ value: SQLExpressible) -> SQLExpression {
    SQLLiteral("DATE(\(value))").sqlExpression
}

The inspiration for this change comes from #705 by @martindufort. Support for the INSTR SQLite function can now be defined as below:

func instr(_ lhs: SQLExpressible, _ rhs: SQLExpressible) -> SQLExpression {
    SQLLiteral("INSTR(\(lhs), \(rhs))").sqlExpression
}

// Usage: SELECT * FROM "player" WHERE (INSTR("name", 'foo')) > 0
let players = try Player
    .filter(instr(Column("name"), "foo") > 0)
    .fetchAll(db)

@groue groue merged commit fefeb1e into development Feb 26, 2020
@groue groue deleted the dev/690-improvement branch February 26, 2020 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant