Revision 2352
Added by Aaron Marcuse-Kubitza over 12 years ago
sql_gen.py | ||
---|---|---|
172 | 172 |
|
173 | 173 |
##### Joins |
174 | 174 |
|
175 |
join_using = object() # tells Join to join the column with USING
|
|
175 |
join_same = object() # tells Join the left and right columns have the same name
|
|
176 | 176 |
|
177 | 177 |
filter_out = object() # tells Join to filter out rows that match the join |
178 | 178 |
|
... | ... | |
180 | 180 |
def __init__(self, table, mapping, type_=None): |
181 | 181 |
''' |
182 | 182 |
@param mapping dict(right_table_col=left_table_col, ...) |
183 |
* if left_table_col is join_using: left_table_col = right_table_col
|
|
183 |
* if left_table_col is join_same: left_table_col = right_table_col
|
|
184 | 184 |
@param type_ None (for plain join)|str (e.g. 'LEFT')|filter_out |
185 | 185 |
* filter_out: equivalent to 'LEFT' with the query filtered by |
186 | 186 |
`table_pkey IS NULL` (indicating no match) |
... | ... | |
199 | 199 |
# Note that right_table_col is on the left in the comparison |
200 | 200 |
|
201 | 201 |
# Parse special values |
202 |
if left_table_col is join_using: left_table_col = right_table_col
|
|
202 |
if left_table_col is join_same: left_table_col = right_table_col
|
|
203 | 203 |
|
204 | 204 |
cond = as_ValueCond(left_table_col, left_table) |
205 | 205 |
return cond.to_str(db, as_Col(right_table_col, self.table)) |
... | ... | |
208 | 208 |
type_ = self.type_ |
209 | 209 |
joins = self.mapping |
210 | 210 |
if type_ is not filter_out and reduce(operator.and_, |
211 |
(v is join_using for v in joins.itervalues())):
|
|
211 |
(v is join_same for v in joins.itervalues())):
|
|
212 | 212 |
# all cols w/ USING, so can use simpler USING syntax |
213 | 213 |
cols = (as_Col(v).to_str(db) for v in joins.iterkeys()) |
214 | 214 |
join_cond = 'USING ('+(', '.join(cols))+')' |
Also available in: Unified diff
sql_gen.py: Renamed join_using to join_same to reflect that it can also be used without USING