Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Tests/StructuredQueriesTests/AggregateFunctionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ extension SnapshotTests {
"""
}

assertQuery(Tag.select { $0.name.groupConcat() }.order(by: \.name)) {
assertQuery(Tag.select { $0.title.groupConcat() }.order(by: \.title)) {
"""
SELECT group_concat("tags"."name")
SELECT group_concat("tags"."title")
FROM "tags"
ORDER BY "tags"."name"
ORDER BY "tags"."title"
"""
} results: {
}results: {
"""
┌─────────────────────────────┐
│ "car,kids,someday,optional" │
Expand All @@ -263,16 +263,16 @@ extension SnapshotTests {
assertQuery(
Tag
.select {
#sql("iif(\($0.name.length() > 5), \($0.name), NULL)", as: String?.self).groupConcat()
#sql("iif(\($0.title.length() > 5), \($0.title), NULL)", as: String?.self).groupConcat()
}
.order(by: \.name)
.order(by: \.title)
) {
"""
SELECT group_concat(iif((length("tags"."name") > 5), "tags"."name", NULL))
SELECT group_concat(iif((length("tags"."title") > 5), "tags"."title", NULL))
FROM "tags"
ORDER BY "tags"."name"
ORDER BY "tags"."title"
"""
} results: {
}results: {
"""
┌────────────────────┐
│ "someday,optional" │
Expand All @@ -283,17 +283,17 @@ extension SnapshotTests {
Tag
.select {
Case()
.when($0.name.length() > 5, then: $0.name)
.when($0.title.length() > 5, then: $0.title)
.groupConcat()
}
.order(by: \.name)
.order(by: \.title)
) {
"""
SELECT group_concat(CASE WHEN (length("tags"."name") > 5) THEN "tags"."name" END)
SELECT group_concat(CASE WHEN (length("tags"."title") > 5) THEN "tags"."title" END)
FROM "tags"
ORDER BY "tags"."name"
ORDER BY "tags"."title"
"""
} results: {
}results: {
"""
┌────────────────────┐
│ "someday,optional" │
Expand All @@ -304,18 +304,18 @@ extension SnapshotTests {
assertQuery(
Tag
.select {
Case($0.name.length())
.when(7, then: $0.name)
Case($0.title.length())
.when(7, then: $0.title)
.groupConcat()
}
.order(by: \.name)
.order(by: \.title)
) {
"""
SELECT group_concat(CASE length("tags"."name") WHEN 7 THEN "tags"."name" END)
SELECT group_concat(CASE length("tags"."title") WHEN 7 THEN "tags"."title" END)
FROM "tags"
ORDER BY "tags"."name"
ORDER BY "tags"."title"
"""
} results: {
}results: {
"""
┌───────────┐
│ "someday" │
Expand Down Expand Up @@ -349,12 +349,12 @@ extension SnapshotTests {
└───┘
"""
}
assertQuery(Tag.select { ($0.name + "!").groupConcat(", ") }) {
assertQuery(Tag.select { ($0.title + "!").groupConcat(", ") }) {
"""
SELECT group_concat(("tags"."name" || '!'), ', ')
SELECT group_concat(("tags"."title" || '!'), ', ')
FROM "tags"
"""
} results: {
}results: {
"""
┌────────────────────────────────────┐
│ "car!, kids!, someday!, optional!" │
Expand Down
18 changes: 9 additions & 9 deletions Tests/StructuredQueriesTests/DeleteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ extension SnapshotTests {
"""
DELETE FROM "remindersLists" AS "rs"
WHERE ("rs"."id" = 1)
RETURNING "id", "color", "name"
RETURNING "id", "color", "title"
"""
} results: {
}results: {
"""
┌────────────────────┐
│ RemindersList( │
│ id: 1, │
│ color: 4889071, │
name: "Personal" │
│ ) │
└────────────────────┘
┌────────────────────
│ RemindersList(
│ id: 1,
│ color: 4889071,
title: "Personal" │
│ )
└────────────────────
"""
}
}
Expand Down
81 changes: 38 additions & 43 deletions Tests/StructuredQueriesTests/InsertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,37 +194,37 @@ extension SnapshotTests {
@Test func select() {
assertQuery(
Tag.insert {
$0.name
$0.title
} select: {
RemindersList.select { $0.name.lower() }
RemindersList.select { $0.title.lower() }
}
.returning(\.self)
) {
"""
INSERT INTO "tags"
("name")
SELECT lower("remindersLists"."name")
("title")
SELECT lower("remindersLists"."title")
FROM "remindersLists"
RETURNING "id", "name"
"""
} results: {
"""
┌────────────────────┐
│ Tag( │
│ id: 5, │
name: "business" │
│ ) │
├────────────────────┤
│ Tag( │
│ id: 6, │
name: "family" │
│ ) │
├────────────────────┤
│ Tag( │
│ id: 7, │
name: "personal" │
│ ) │
└────────────────────┘
RETURNING "id", "title"
"""
}results: {
"""
┌────────────────────
│ Tag(
│ id: 5,
title: "business" │
│ )
├────────────────────
│ Tag(
│ id: 6,
title: "family" │
│ )
├────────────────────
│ Tag(
│ id: 7,
title: "personal" │
│ )
└────────────────────
"""
}
}
Expand Down Expand Up @@ -400,20 +400,20 @@ extension SnapshotTests {

@Test func upsertWithoutID_OtherConflict() {
assertQuery(
RemindersList.upsert(RemindersList.Draft(name: "Personal"))
RemindersList.upsert(RemindersList.Draft(title: "Personal"))
.returning(\.self)
) {
"""
INSERT INTO "remindersLists"
("id", "color", "name")
("id", "color", "title")
VALUES
(NULL, 4889071, 'Personal')
ON CONFLICT ("id") DO UPDATE SET "color" = "excluded"."color", "name" = "excluded"."name"
RETURNING "id", "color", "name"
ON CONFLICT ("id") DO UPDATE SET "color" = "excluded"."color", "title" = "excluded"."title"
RETURNING "id", "color", "title"
"""
} results: {
}results: {
"""
UNIQUE constraint failed: remindersLists.name
UNIQUE constraint failed: remindersLists.title
"""
}
}
Expand All @@ -432,16 +432,11 @@ extension SnapshotTests {
"""
INSERT INTO "tags" ("name")
VALUES ('office')
RETURNING "tags"."id", "tags"."name"
RETURNING "tags"."id", "tags"."title"
"""
} results: {
}results: {
"""
┌──────────────────┐
│ Tag( │
│ id: 5, │
│ name: "office" │
│ ) │
└──────────────────┘
table tags has no column named name
"""
}
}
Expand All @@ -450,26 +445,26 @@ extension SnapshotTests {
enum R: AliasName {}
assertQuery(
RemindersList.as(R.self).insert {
$0.name
$0.title
} values: {
"cruise"
}
.returning(\.self)
) {
"""
INSERT INTO "remindersLists" AS "rs"
("name")
("title")
VALUES
('cruise')
RETURNING "id", "color", "name"
RETURNING "id", "color", "title"
"""
} results: {
}results: {
"""
┌───────────────────┐
│ RemindersList( │
│ id: 4, │
│ color: 4889071, │
name: "cruise"
title: "cruise" │
│ ) │
└───────────────────┘
"""
Expand Down
6 changes: 3 additions & 3 deletions Tests/StructuredQueriesTests/JoinTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ extension SnapshotTests {
Reminder
.order { $0.dueDate.desc() }
.join(RemindersList.all) { $0.remindersListID.eq($1.id) }
.select { ($0.title, $1.name) }
.select { ($0.title, $1.title) }
) {
"""
SELECT "reminders"."title", "remindersLists"."name"
SELECT "reminders"."title", "remindersLists"."title"
FROM "reminders"
JOIN "remindersLists" ON ("reminders"."remindersListID" = "remindersLists"."id")
ORDER BY "reminders"."dueDate" DESC
"""
} results: {
}results: {
"""
┌────────────────────────────┬────────────┐
│ "Take out trash" │ "Family" │
Expand Down
52 changes: 26 additions & 26 deletions Tests/StructuredQueriesTests/LiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,32 @@ extension SnapshotTests {
.select { ($0, $1.id.count()) }
) {
"""
SELECT "remindersLists"."id", "remindersLists"."color", "remindersLists"."name", count("reminders"."id")
SELECT "remindersLists"."id", "remindersLists"."color", "remindersLists"."title", count("reminders"."id")
FROM "remindersLists"
JOIN "reminders" ON ("remindersLists"."id" = "reminders"."remindersListID")
GROUP BY "remindersLists"."id"
"""
} results: {
}results: {
"""
┌────────────────────┬───┐
│ RemindersList( │ 5 │
│ id: 1, │ │
│ color: 4889071, │ │
name: "Personal" │ │
│ ) │ │
├────────────────────┼───┤
│ RemindersList( │ 3 │
│ id: 2, │ │
│ color: 15567157, │ │
name: "Family" │ │
│ ) │ │
├────────────────────┼───┤
│ RemindersList( │ 2 │
│ id: 3, │ │
│ color: 11689427, │ │
name: "Business" │ │
│ ) │ │
└────────────────────┴───┘
┌────────────────────┬───┐
│ RemindersList( │ 5 │
│ id: 1, │ │
│ color: 4889071, │ │
title: "Personal" │ │
│ ) │ │
├────────────────────┼───┤
│ RemindersList( │ 3 │
│ id: 2, │ │
│ color: 15567157, │ │
title: "Family" │ │
│ ) │ │
├────────────────────┼───┤
│ RemindersList( │ 2 │
│ id: 3, │ │
│ color: 11689427, │ │
title: "Business" │ │
│ ) │ │
└────────────────────┴───┘
"""
}
}
Expand All @@ -220,16 +220,16 @@ extension SnapshotTests {
.group(by: \.id)
.join(ReminderTag.all) { $0.id.eq($1.reminderID) }
.join(Tag.all) { $1.tagID.eq($2.id) }
.select { ($0, $2.name.groupConcat()) }
.select { ($0, $2.title.groupConcat()) }
) {
"""
SELECT "reminders"."id", "reminders"."assignedUserID", "reminders"."dueDate", "reminders"."isCompleted", "reminders"."isFlagged", "reminders"."notes", "reminders"."priority", "reminders"."remindersListID", "reminders"."title", group_concat("tags"."name")
SELECT "reminders"."id", "reminders"."assignedUserID", "reminders"."dueDate", "reminders"."isCompleted", "reminders"."isFlagged", "reminders"."notes", "reminders"."priority", "reminders"."remindersListID", "reminders"."title", group_concat("tags"."title")
FROM "reminders"
JOIN "reminderTags" ON ("reminders"."id" = "reminderTags"."reminderID")
JOIN "tags" ON ("reminderTags"."tagID" = "tags"."id")
JOIN "remindersTags" ON ("reminders"."id" = "remindersTags"."reminderID")
JOIN "tags" ON ("remindersTags"."tagID" = "tags"."id")
GROUP BY "reminders"."id"
"""
} results: {
}results: {
"""
┌────────────────────────────────────────────┬────────────────────┐
│ Reminder( │ "someday,optional" │
Expand Down
6 changes: 3 additions & 3 deletions Tests/StructuredQueriesTests/PrimaryKeyedTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ extension SnapshotTests {
assertQuery(
Reminder
.join(RemindersList.all) { $0.remindersListID == $1.id }
.select { ($0.title, $1.name) }
.select { ($0.title, $1.title) }
.find(2)
) {
"""
SELECT "reminders"."title", "remindersLists"."name"
SELECT "reminders"."title", "remindersLists"."title"
FROM "reminders"
JOIN "remindersLists" ON ("reminders"."remindersListID" = "remindersLists"."id")
WHERE ("reminders"."id" = 2)
"""
} results: {
}results: {
"""
┌───────────┬────────────┐
│ "Haircut" │ "Personal" │
Expand Down
Loading