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

Rename aliased(_:) methods to forKey(_:) #577

Merged
merged 7 commits into from
Jul 27, 2019
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Jul 27, 2019

This PR renames the method that gives an alias to an SQL column from aliased(_:) to forKey(_:):

// SELECT (width * height) AS area FROM shape
let area = (Column("width") * Column("height")).forKey("area")
let request = Shape.select(area)
if let row = try Row.fetchOne(db, request) {
    let area: Int = row["area"]
}

// SELECT author.*,
//        COUNT(DISTINCT book.rowid) AS numberOfBooks,
// FROM author
// LEFT JOIN book ON book.authorId = author.id
// GROUP BY author.id
let aggregate = Author.books.count.forKey("numberOfBooks")
let request = Author.annotated(with: aggregate)
if let row = try Row.fetchOne(db, request) {
    let author = Author(row: row)
    let numberOfBooks: Int = row["numberOfBooks"]
}

The old aliased(_:) methods are still defined, but deprecated.

The goal of this PR is to increase API consistency:

  • The forKey(_:) method is now the unique way to rename values, associated records, and association aggregates, when one wants to customize the decoding of codable records, or the keys used for raw Row subscript.
  • The method aliased(_:) is now only used by table aliases.

@groue groue changed the base branch from master to development July 27, 2019 15:01
@groue groue added this to the GRDB 4.2.0 milestone Jul 27, 2019
@groue groue merged commit 2996a24 into development Jul 27, 2019
@groue groue deleted the dev/renameAliased branch July 27, 2019 20:59
groue added a commit that referenced this pull request Jul 27, 2019
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