The little things that make the SQLite library GRDB.swift different.
Given two database tables, persons and books, one often expects that an object mapping should give two isolated classes: Person and Book.
Well, this does not have to be that way.
GRDB distinguishes the ability to be fetched from the ability to be persisted in the database. They can match, of course, and involve a single identical database table. But fetchable types can actually feed on any fetch request.
For example, our Person type below can load a “bookCount” property that is not a column of the “persons” table:
Now it’s natural to fetch persons and their book count without fetching all their books, using a simple join query:
Oh, and since the bookCount property is optional, a Person can be loaded from requests that do not contain the “bookCount” column as well: