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

Type inference of selected columns #656

Merged
merged 3 commits into from
Dec 7, 2019

Conversation

groue
Copy link
Owner

@groue groue commented Nov 22, 2019

This pull request allows to omit the as: parameter of the select(_:as:) request derivation method. It can be convenient.

For example:

extension QueryInterfaceRequest where RowDecoder == Player {
    static func maximumScore(): QueryInterfaceRequest<Int?> {
        select(max(Column("score"))) // previously we needed `, as: Int.self`
    }
}

let maxScore: Int? = try dbQueue.read { db in
    try Player.all().maximumScore().fetchOne(db)
}

This also applies to RxGRDB and GRDBCombine:

extension PlayerDatabase {
    func maximumScorePublisher() -> AnyPublisher<Int?, Error> {
        ValueObservation
            .tracking(value: Player.select(max(Column("score"))).fetchOne) // previously we needed `, as: Int.self`
            .publisher(in: dbReader)
            .eraseToAnyPublisher()
    }
}

@groue groue changed the base branch from master to development November 22, 2019 17:38
@groue groue changed the title Request selection inference Type inference of selected columns Nov 22, 2019
@groue groue force-pushed the dev/request-selection-inference branch from 300c3de to b6ede15 Compare December 7, 2019 09:37
@groue groue marked this pull request as ready for review December 7, 2019 11:55
@groue groue merged commit 16354be into development Dec 7, 2019
@groue groue deleted the dev/request-selection-inference branch December 7, 2019 18:36
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