@@ -157,75 +157,75 @@ instance OrdB (Expression params tables ty) where
157157 (<*) = unsafeBinaryOp "<"
158158 (<=*) = unsafeBinaryOp "<="
159159
160−newtype TableRef
160+newtype JoinExpression
161161 (params :: [NullityType])
162162 (schema :: [(Symbol,[(Symbol,NullityType)])])
163163 (tables :: [(Symbol,[(Symbol,NullityType)])])
164− = UnsafeTableRef { renderTableRef :: ByteString }
164+ = UnsafeJoinExpression { renderJoinExpression :: ByteString }
165165
166166class KnownSymbol table => HasTable table tables columns
167167 | table tables -> columns where
168− getTable :: Proxy# table -> TableRef params tables '[table ::: columns]
169− getTable table = UnsafeTableRef $ fromString $ symbolVal' table
168+ getTable :: Proxy# table -> JoinExpression params tables '[table ::: columns]
169+ getTable table = UnsafeJoinExpression $ fromString $ symbolVal' table
170170instance {-# OVERLAPPING #-} KnownSymbol table
171171 => HasTable table ((table ::: columns) ': tables) columns
172172instance {-# OVERLAPPABLE #-}
173173 (KnownSymbol table, HasTable table schema columns)
174174 => HasTable table (table' ': schema) columns
175175
176−crossJoin
177− :: TableRef params schema '[table]
178− -> TableRef params schema tables
179− -> TableRef params schema (table ': tables)
180−crossJoin tab tabs = UnsafeTableRef $
181− renderTableRef tabs <> " CROSS JOIN " <> renderTableRef tab
176+cross
177+ :: JoinExpression params schema '[table]
178+ -> JoinExpression params schema tables
179+ -> JoinExpression params schema (table ': tables)
180+cross tab tabs = UnsafeJoinExpression $
181+ renderJoinExpression tabs <> " CROSS JOIN " <> renderJoinExpression tab
182182
183−innerJoin
184− :: TableRef params schema '[table]
183+inner
184+ :: JoinExpression params schema '[table]
185185 -> Expression params (table ': tables) ('NotNull 'PGBool)
186− -> TableRef params schema tables
187− -> TableRef params schema (table ': tables)
188−innerJoin tab on tabs = UnsafeTableRef $
189− renderTableRef tabs
186+ -> JoinExpression params schema tables
187+ -> JoinExpression params schema (table ': tables)
188+inner tab on tabs = UnsafeJoinExpression $
189+ renderJoinExpression tabs
190190 <> " INNER JOIN " <>
191− renderTableRef tab
191+ renderJoinExpression tab
192192 <> " ON " <>
193193 renderExpression on
194194
195−leftOuterJoin
196− :: TableRef params schema '[right]
197− -> Expression params (right ': tables) ('NotNull 'PGBool)
198− -> TableRef params schema (left : tables)
199− -> TableRef params schema (NullifyTable right ': left ': tables)
200−leftOuterJoin tab on tabs = UnsafeTableRef $
201− renderTableRef tabs
195+leftOuter
196+ :: JoinExpression params schema '[right]
197+ -> Expression params (right ': left : tables) ('NotNull 'PGBool)
198+ -> JoinExpression params schema (tables)
199+ -> JoinExpression params schema (NullifyTable right ': left ': tables)
200+leftOuter tab on tabs = UnsafeJoinExpression $
201+ renderJoinExpression tabs
202202 <> " LEFT OUTER JOIN " <>
203− renderTableRef tab
203+ renderJoinExpression tab
204204 <> " ON " <>
205205 renderExpression on
206206
207−rightOuterJoin
208− :: TableRef params schema '[right]
207+rightOuter
208+ :: JoinExpression params schema '[right]
209209 -> Expression params (right ': tables) ('NotNull 'PGBool)
210− -> TableRef params schema (left : tables)
211− -> TableRef params schema (right ': NullifyTable left ': tables)
212−rightOuterJoin tab on tabs = UnsafeTableRef $
213− renderTableRef tabs
210+ -> JoinExpression params schema (left : tables)
211+ -> JoinExpression params schema (right ': NullifyTable left ': tables)
212+rightOuter tab on tabs = UnsafeJoinExpression $
213+ renderJoinExpression tabs
214214 <> " RIGHT OUTER JOIN " <>
215− renderTableRef tab
215+ renderJoinExpression tab
216216 <> " ON " <>
217217 renderExpression on
218218
219−fullOuterJoin
220− :: TableRef params schema '[right]
221− -> Expression params (right ': tables) ('NotNull 'PGBool)
222− -> TableRef params schema (left : tables)
223− -> TableRef params schema
219+fullOuter
220+ :: JoinExpression params schema '[right]
221+ -> Expression params (right ': left ': tables) ('NotNull 'PGBool)
222+ -> JoinExpression params schema (left : tables)
223+ -> JoinExpression params schema
224224 (NullifyTable right ': NullifyTable left ': tables)
225−fullOuterJoin tab on tabs = UnsafeTableRef $
226− renderTableRef tabs
225+fullOuter tab on tabs = UnsafeJoinExpression $
226+ renderJoinExpression tabs
227227 <> " FULL OUTER JOIN " <>
228− renderTableRef tab
228+ renderJoinExpression tab
229229 <> " ON " <>
230230 renderExpression on
231231
@@ -255,55 +255,55 @@ instance Monoid (Clauses params tables) where
255255 (Just o1,Just o2) -> Just (o1 + o2)
256256 }
257257
258−data TableExpression
258+data FromExpression
259259 (params :: [NullityType])
260260 (schema :: [(Symbol,[(Symbol,NullityType)])])
261261 (tables :: [(Symbol,[(Symbol,NullityType)])])
262− = TableExpression
263− { tableRef :: TableRef params schema tables
262+ = FromExpression
263+ { joinExpression :: JoinExpression params schema tables
264264 , clauses :: Clauses params tables
265265 }
266266
267−tables
268− :: TableRef params schema tables
269− -> TableExpression params schema tables
270−tables tref = TableExpression tref mempty
267+join
268+ :: JoinExpression params schema tables
269+ -> FromExpression params schema tables
270+join tref = FromExpression tref mempty
271271
272−renderTabulation :: TableExpression params schema tables -> ByteString
273−renderTabulation (TableExpression tref (Clauses wh lim off))= mconcat
274− [ renderTableRef tref
272+renderTabulation :: FromExpression params schema tables -> ByteString
273+renderTabulation (FromExpression tref (Clauses wh lim off))= mconcat
274+ [ renderJoinExpression tref
275275 , maybe "" ((" WHERE " <>) . renderExpression) wh
276276 , maybe "" ((" LIMIT " <>) . renderExpression) lim
277277 , maybe "" ((" OFFSET " <>) . renderExpression) off
278278 ]
279279
280280instance (HasTable table schema columns, table ~ table')
281− => IsLabel table (TableRef params schema '[table' ::: columns]) where
281+ => IsLabel table (JoinExpression params schema '[table' ::: columns]) where
282282 fromLabel = getTable
283283
284284instance (HasTable table schema columns, table ~ table')
285− => IsLabel table (TableExpression params schema '[table' ::: columns]) where
286− fromLabel p = TableExpression (getTable p) mempty
285+ => IsLabel table (FromExpression params schema '[table' ::: columns]) where
286+ fromLabel p = FromExpression (getTable p) mempty
287287
288288where_
289289 :: Expression params tables ('NotNull 'PGBool)
290− -> TableExpression params schema tables
291− -> TableExpression params schema tables
292−where_ wh (TableExpression tabs clauses1) = TableExpression tabs
290+ -> FromExpression params schema tables
291+ -> FromExpression params schema tables
292+where_ wh (FromExpression tabs clauses1) = FromExpression tabs
293293 (clauses1 <> Clauses (Just wh) Nothing Nothing)
294294
295295limit
296296 :: Expression params '[] ('NotNull 'PGInt8)
297− -> TableExpression params schema tables
298− -> TableExpression params schema tables
299−limit lim (TableExpression tabs clauses1) = TableExpression tabs
297+ -> FromExpression params schema tables
298+ -> FromExpression params schema tables
299+limit lim (FromExpression tabs clauses1) = FromExpression tabs
300300 (clauses1 <> Clauses Nothing (Just lim) Nothing)
301301
302302offset
303303 :: Expression params '[] ('NotNull 'PGInt8)
304− -> TableExpression params schema tables
305− -> TableExpression params schema tables
306−offset off (TableExpression tabs clauses1) = TableExpression tabs
304+ -> FromExpression params schema tables
305+ -> FromExpression params schema tables
306+offset off (FromExpression tabs clauses1) = FromExpression tabs
307307 (clauses1 <> Clauses Nothing Nothing (Just off))
308308
309309newtype Selection
@@ -315,21 +315,21 @@ newtype Selection
315315
316316starFrom
317317 :: tables ~ '[table ::: columns]
318− => TableExpression params schema tables
318+ => FromExpression params schema tables
319319 -> Selection params schema columns
320320starFrom tabs = UnsafeSelection $ "* FROM " <> renderTabulation tabs
321321
322322dotStarFrom
323323 :: HasTable table tables columns
324324 => Alias table
325− -> TableExpression params schema tables
325+ -> FromExpression params schema tables
326326 -> Selection params schema columns
327327Alias tab `dotStarFrom` tabs = UnsafeSelection $
328328 fromString (symbolVal' tab) <> ".* FROM" <> renderTabulation tabs
329329
330330from
331331 :: Rec (Aliased (Expression params tables)) columns
332− -> TableExpression params schema tables
332+ -> FromExpression params schema tables
333333 -> Selection params schema columns
334334list `from` tabs = UnsafeSelection $
335335 renderList list <> " FROM " <> renderTabulation tabs
@@ -360,9 +360,9 @@ select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
360360
361361subselect
362362 :: Aliased (Selection params schema) table
363− -> TableExpression params schema '[table]
364−subselect selection = TableExpression
365− { tableRef = UnsafeTableRef . ("SELECT " <>) $
363+ -> FromExpression params schema '[table]
364+subselect selection = FromExpression
365+ { tableRef = UnsafeJoinExpression . ("SELECT " <>) $
366366 renderAliased renderSelection selection
367367 , clauses = mempty
368368 }