Skip to content

Commit b6644f4

Browse files
committed
Allow 'find' to work with query expressions.
1 parent 3e8a556 commit b6644f4

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Sources/StructuredQueriesCore/PrimaryKeyed.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ extension PrimaryKeyedTable {
8181
///
8282
/// - Parameter primaryKey: A primary key identifying a table row.
8383
/// - Returns: A `WHERE` clause.
84-
public static func find(_ primaryKey: TableColumns.PrimaryKey.QueryOutput) -> Where<Self> {
85-
Self.where { $0.primaryKey.eq(TableColumns.PrimaryKey(queryOutput: primaryKey)) }
84+
public static func find(
85+
_ primaryKey: some QueryExpression<TableColumns.PrimaryKey>
86+
) -> Where<Self> {
87+
Self.where { $0.primaryKey.eq(primaryKey) }
8688
}
8789
}
8890

@@ -92,12 +94,10 @@ extension TableDraft {
9294
/// - Parameter primaryKey: A primary key identifying a table row.
9395
/// - Returns: A `WHERE` clause.
9496
public static func find(
95-
_ primaryKey: PrimaryTable.TableColumns.PrimaryKey.QueryOutput
97+
_ primaryKey: some QueryExpression<PrimaryTable.TableColumns.PrimaryKey>
9698
) -> Where<Self> {
9799
Self.where { _ in
98-
PrimaryTable.columns.primaryKey.eq(
99-
PrimaryTable.TableColumns.PrimaryKey(queryOutput: primaryKey)
100-
)
100+
PrimaryTable.columns.primaryKey.eq(primaryKey)
101101
}
102102
}
103103
}
@@ -107,8 +107,8 @@ extension Where where From: PrimaryKeyedTable {
107107
///
108108
/// - Parameter primaryKey: A primary key.
109109
/// - Returns: A where clause with the added primary key.
110-
public func find(_ primaryKey: From.TableColumns.PrimaryKey.QueryOutput) -> Self {
111-
self.where { $0.primaryKey.eq(From.TableColumns.PrimaryKey(queryOutput: primaryKey)) }
110+
public func find(_ primaryKey: some QueryExpression<From.TableColumns.PrimaryKey>) -> Self {
111+
self.where { $0.primaryKey.eq(primaryKey) }
112112
}
113113
}
114114

@@ -131,7 +131,7 @@ extension Select where From: PrimaryKeyedTable {
131131
///
132132
/// - Parameter primaryKey: A primary key identifying a table row.
133133
/// - Returns: A select statement filtered by the given key.
134-
public func find(_ primaryKey: From.TableColumns.PrimaryKey.QueryOutput) -> Self {
134+
public func find(_ primaryKey: some QueryExpression<From.TableColumns.PrimaryKey>) -> Self {
135135
self.and(From.find(primaryKey))
136136
}
137137
}
@@ -141,7 +141,9 @@ extension Select where From: TableDraft {
141141
///
142142
/// - Parameter primaryKey: A primary key identifying a table row.
143143
/// - Returns: A select statement filtered by the given key.
144-
public func find(_ primaryKey: From.PrimaryTable.TableColumns.PrimaryKey.QueryOutput) -> Self {
144+
public func find(
145+
_ primaryKey: some QueryExpression<From.PrimaryTable.TableColumns.PrimaryKey>
146+
) -> Self {
145147
self.and(From.find(primaryKey))
146148
}
147149
}
@@ -151,8 +153,8 @@ extension Update where From: PrimaryKeyedTable {
151153
///
152154
/// - Parameter primaryKey: A primary key identifying a table row.
153155
/// - Returns: An update statement filtered by the given key.
154-
public func find(_ primaryKey: From.TableColumns.PrimaryKey.QueryOutput) -> Self {
155-
self.where { $0.primaryKey.eq(From.TableColumns.PrimaryKey(queryOutput: primaryKey)) }
156+
public func find(_ primaryKey: some QueryExpression<From.TableColumns.PrimaryKey>) -> Self {
157+
self.where { $0.primaryKey.eq(primaryKey) }
156158
}
157159
}
158160

@@ -175,8 +177,8 @@ extension Delete where From: PrimaryKeyedTable {
175177
///
176178
/// - Parameter primaryKey: A primary key identifying a table row.
177179
/// - Returns: A delete statement filtered by the given key.
178-
public func find(_ primaryKey: From.TableColumns.PrimaryKey.QueryOutput) -> Self {
179-
self.where { $0.primaryKey.eq(From.TableColumns.PrimaryKey(queryOutput: primaryKey)) }
180+
public func find(_ primaryKey: some QueryExpression<From.TableColumns.PrimaryKey>) -> Self {
181+
self.where { $0.primaryKey.eq(primaryKey) }
180182
}
181183
}
182184

0 commit comments

Comments
 (0)