@@ -4,7 +4,8 @@ where TableColumns: PrimaryKeyedTableDefinition<PrimaryKey> {
44 /// A type representing this table's primary key.
55 ///
66 /// For auto-incrementing tables, this is typically `Int`.
7- associatedtype PrimaryKey : QueryBindable where PrimaryKey. QueryValue == PrimaryKey
7+ associatedtype PrimaryKey : QueryRepresentable & QueryExpression
8+ where PrimaryKey. QueryValue == PrimaryKey
89
910 /// A type that represents this type, but with an optional primary key.
1011 ///
@@ -48,10 +49,13 @@ where QueryValue: PrimaryKeyedTable {
4849 /// A type representing this table's primary key.
4950 ///
5051 /// For auto-incrementing tables, this is typically `Int`.
51- associatedtype PrimaryKey : QueryBindable where PrimaryKey. QueryValue == PrimaryKey
52+ associatedtype PrimaryKey : QueryRepresentable & QueryExpression
53+ where PrimaryKey. QueryValue == PrimaryKey
54+
55+ associatedtype PrimaryKeyColumn : _TableColumnExpression < QueryValue , PrimaryKey >
5256
5357 /// The column representing this table's primary key.
54- var primaryKey : TableColumn < QueryValue , PrimaryKey > { get }
58+ var primaryKey : PrimaryKeyColumn { get }
5559}
5660
5761extension TableDefinition where QueryValue: TableDraft {
@@ -62,7 +66,7 @@ extension TableDefinition where QueryValue: TableDraft {
6266 }
6367}
6468
65- extension PrimaryKeyedTableDefinition {
69+ extension PrimaryKeyedTableDefinition where PrimaryKeyColumn : TableColumnExpression {
6670 /// A query expression representing the number of rows in this table.
6771 ///
6872 /// - Parameters:
@@ -78,15 +82,16 @@ extension PrimaryKeyedTableDefinition {
7882 }
7983}
8084
81- extension PrimaryKeyedTable {
85+ // TODO: Support composite keys.
86+ extension PrimaryKeyedTable where PrimaryKey: QueryBindable {
8287 /// A where clause filtered by a primary key.
8388 ///
8489 /// - Parameter primaryKey: A primary key identifying a table row.
8590 /// - Returns: A `WHERE` clause.
8691 public static func find(
8792 _ primaryKey: some QueryExpression < TableColumns . PrimaryKey >
8893 ) -> Where < Self > {
89- Self . find ( [ primaryKey] )
94+ find ( [ primaryKey] )
9095 }
9196
9297 /// A where clause filtered by primary keys.
@@ -104,7 +109,8 @@ extension PrimaryKeyedTable {
104109 }
105110}
106111
107- extension TableDraft {
112+ // TODO: Support composite keys.
113+ extension TableDraft where PrimaryTable. PrimaryKey: QueryBindable {
108114 /// A where clause filtered by a primary key.
109115 ///
110116 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -126,7 +132,8 @@ extension TableDraft {
126132 }
127133}
128134
129- extension Where where From: PrimaryKeyedTable {
135+ // TODO: Support composite keys.
136+ extension Where where From: PrimaryKeyedTable , From. PrimaryKey: QueryBindable {
130137 /// Adds a primary key condition to a where clause.
131138 ///
132139 /// - Parameter primaryKey: A primary key.
@@ -146,7 +153,8 @@ extension Where where From: PrimaryKeyedTable {
146153 }
147154}
148155
149- extension Where where From: TableDraft {
156+ // TODO: Support composite keys.
157+ extension Where where From: TableDraft , From. PrimaryTable. PrimaryKey: QueryBindable {
150158 /// Adds a primary key condition to a where clause.
151159 ///
152160 /// - Parameter primaryKey: A primary key.
@@ -168,7 +176,8 @@ extension Where where From: TableDraft {
168176 }
169177}
170178
171- extension Select where From: PrimaryKeyedTable {
179+ // TODO: Support composite keys.
180+ extension Select where From: PrimaryKeyedTable , From. PrimaryKey: QueryBindable {
172181 /// A select statement filtered by a primary key.
173182 ///
174183 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -188,7 +197,8 @@ extension Select where From: PrimaryKeyedTable {
188197 }
189198}
190199
191- extension Select where From: TableDraft {
200+ // TODO: Support composite keys.
201+ extension Select where From: TableDraft , From. PrimaryTable. PrimaryKey: QueryBindable {
192202 /// A select statement filtered by a primary key.
193203 ///
194204 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -210,7 +220,8 @@ extension Select where From: TableDraft {
210220 }
211221}
212222
213- extension Update where From: PrimaryKeyedTable {
223+ // TODO: Support composite keys.
224+ extension Update where From: PrimaryKeyedTable , From. PrimaryKey: QueryBindable {
214225 /// An update statement filtered by a primary key.
215226 ///
216227 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -230,7 +241,8 @@ extension Update where From: PrimaryKeyedTable {
230241 }
231242}
232243
233- extension Update where From: TableDraft {
244+ // TODO: Support composite keys.
245+ extension Update where From: TableDraft , From. PrimaryTable. PrimaryKey: QueryBindable {
234246 /// An update statement filtered by a primary key.
235247 ///
236248 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -252,7 +264,8 @@ extension Update where From: TableDraft {
252264 }
253265}
254266
255- extension Delete where From: PrimaryKeyedTable {
267+ // TODO: Support composite keys.
268+ extension Delete where From: PrimaryKeyedTable , From. PrimaryKey: QueryBindable {
256269 /// A delete statement filtered by a primary key.
257270 ///
258271 /// - Parameter primaryKey: A primary key identifying a table row.
@@ -272,7 +285,8 @@ extension Delete where From: PrimaryKeyedTable {
272285 }
273286}
274287
275- extension Delete where From: TableDraft {
288+ // TODO: Support composite keys.
289+ extension Delete where From: TableDraft , From. PrimaryTable. PrimaryKey: QueryBindable {
276290 /// A delete statement filtered by a primary key.
277291 ///
278292 /// - Parameter primaryKey: A primary key identifying a table row.
0 commit comments