Last active
May 7, 2026 00:39
-
-
Save dreymonde/079faa7a79701752b9ef6be39e37f7d9 to your computer and use it in GitHub Desktop.
StructuredQueries_ColumnPrefix.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Table | |
| private struct FullReminderAndList { | |
| @Column(prefix: "r_") | |
| let reminder: Reminder | |
| @Column(prefix: "rl_") | |
| let list: RemindersList | |
| } | |
| // how the test cases would look: | |
| @Test func viewWithDuplicateColumnWithinSubtables() { | |
| assertQuery( | |
| FullReminderAndList.createTemporaryView( | |
| as: | |
| Reminder | |
| .join(RemindersList.all) { $0.remindersListID.eq($1.id) } | |
| .select { | |
| FullReminderAndList.Columns(reminder: $0, list: $1) | |
| } | |
| ) | |
| ) { | |
| """ | |
| CREATE TEMPORARY VIEW | |
| "fullReminderAndLists" | |
| ("r_id", "r_assignedUserID", "r_dueDate", "r_isCompleted", "r_isFlagged", "r_notes", "r_priority", "r_remindersListID", "r_title", "r_updatedAt", "rl_id", "rl_color", "rl_title", "rl_position") | |
| AS | |
| SELECT "reminders"."id" AS "r_id", "reminders"."assignedUserID" AS "r_assignedUserID", "reminders"."dueDate" AS "r_dueDate", "reminders"."isCompleted" AS "r_isCompleted", "reminders"."isFlagged" AS "r_isFlagged", "reminders"."notes" AS "r_notes", "reminders"."priority" AS "r_priority", "reminders"."remindersListID" AS "r_remindersListID", "reminders"."title" AS "r_title", "reminders"."updatedAt" AS "r_updatedAt", "remindersLists"."id" AS "rl_id", "remindersLists"."color" AS "rl_color", "remindersLists"."title" AS "rl_title", "remindersLists"."position" AS "rl_position" | |
| FROM "reminders" | |
| JOIN "remindersLists" ON ("reminders"."remindersListID") = ("remindersLists"."id") | |
| """ | |
| } | |
| assertQuery( | |
| FullReminderAndList.limit(1) | |
| .select { | |
| ReminderAndListID.Columns(reminderID: $0.reminder.id, remindersListID: $0.list.id) | |
| } | |
| ) { | |
| """ | |
| SELECT "fullReminderAndLists"."r_id", "fullReminderAndLists"."rl_id" | |
| FROM "fullReminderAndLists" | |
| LIMIT 1 | |
| """ | |
| } results: { | |
| """ | |
| ┌──────────────────────┐ | |
| │ ReminderAndListID( │ | |
| │ reminderID: 1, │ | |
| │ remindersListID: 1 │ | |
| │ ) │ | |
| └──────────────────────┘ | |
| """ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment