Skip to content

Commit 8279881

Browse files
committed
Store JOIN metadata
We can defer expansion to statement compile time. We need this data intact to properly expand "SELECT *" and "SELECT table.*". Signed-off-by: Stephen Celis <stephen@stephencelis.com>
1 parent 270e7e4 commit 8279881

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

SQLite Common/Query.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public struct Query {
5252
private var distinct: Bool = false
5353
internal var tableName: String
5454
private var alias: String?
55-
private var joins = [Expressible]()
55+
private var joins: [(type: JoinType, table: Query, condition: Expression<Bool>)] = []
5656
private var filter: Expression<Bool>?
5757
private var group: Expressible?
5858
private var order = [Expressible]()
@@ -138,9 +138,8 @@ public struct Query {
138138
/// :returns: A query with the given JOIN clause applied.
139139
public func join(type: JoinType, _ table: Query, on: Expression<Bool>) -> Query {
140140
var query = self
141-
let condition = table.filter.map { on && $0 } ?? on
142-
let expression = Expression<()>("\(type.rawValue) JOIN \(table) ON \(condition.SQL)", condition.bindings)
143-
query.joins.append(expression)
141+
let join = (type: type, table: table, condition: table.filter.map { on && $0 } ?? on)
142+
query.joins.append(join)
144143
return query
145144
}
146145

@@ -385,7 +384,9 @@ public struct Query {
385384

386385
private var joinClause: Expressible? {
387386
if joins.count == 0 { return nil }
388-
return SQLite.join(" ", joins)
387+
return SQLite.join(" ", joins.map { type, table, condition in
388+
Expression<()>("\(type.rawValue) JOIN \(table) ON \(condition.SQL)", condition.bindings)
389+
})
389390
}
390391

391392
internal var whereClause: Expressible? {

0 commit comments

Comments
 (0)