(no title)
mbw234 | 5 months ago
Our library does allow this a little bit, in addition to a Swift API for building queries. You can write SQL as a string while still using the schema information exposed from the @Table macro. For example, a query to select all reminders lists along with a count of the reminders in each list:
@Table struct RemindersList {
let id: UUID
var title = ""
}
@Table struct Reminder {
let id: UUID
var title = ""
var remindersListID: RemindersList.ID
}
#sql("""
SELECT \(RemindersList.title), \(Reminder.id.count())
FROM \(RemindersList.self)
LEFT JOIN \(Reminder.self) ON \(RemindersList.id) = \(Reminder.remindersListID)
GROUP BY \(RemindersList.id)
""",
as: (String, Int).self
)
dgllghr|5 months ago