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

Introduce request derivation protocols #329

Merged
merged 2 commits into from
Apr 11, 2018
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Apr 10, 2018

This PR introduces the four protocols SelectionRequest, FilteredRequest, AggregatingRequest, and OrderedRequest, which provide basic request derivation API. QueryInterfaceRequest adopts those protocols:

let request = Player.select(...).filter(...).group(...).order(...)

This PR is a step towards the Associations API, where QueryInterfaceRequest will no longer be the only type that provides the select and filter methods:

// soon
let frenchAuthors = Book.author.filter(Column("countryCode") == "FR")
let frenchBooks: [Book] = try Book.joined(required: frenchAuthors).fetchAll(db)

Also in this PR: request.select(sql: "...") does no longer selects a SQLExpressionLiteral, but a SQLSelectionLiteral instead (a new, internal type). The new SQLExpressionLiteral will raise a fatal error when GRDB wants to know the number of selected columns, instead of letting SQLExpressionLiteral return an ill-advised 1. This fix will make handling of joined requests, where counting columns is important, more robust.

groue added 2 commits April 10, 2018 13:44
…OrderedRequest.

Those request protocols allow types that are not QueryInterfaceRequest to expose the same derivation API. This is a necessary step towards associations.
(Some expressions which were not safely wrapped inside parenthesis now are wrapped inside parenthesis)
@groue groue added this to the GRDB 3.0 milestone Apr 10, 2018
@groue groue mentioned this pull request Apr 10, 2018
29 tasks
@groue groue merged commit 75ab9d6 into GRDB3 Apr 11, 2018
@groue groue deleted the GRDB3-RequestDerivation branch April 11, 2018 06:04
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