on dev help sign in
renaming
b61ec70Eitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+68−68
@@ -157,75 +157,75 @@ instance OrdB (Expression params tables ty) where
157 (<*) = unsafeBinaryOp "<"
157 (<*) = unsafeBinaryOp "<"
158 (<=*) = unsafeBinaryOp "<="
158 (<=*) = unsafeBinaryOp "<="
159
159
160−newtype TableRef
160+newtype JoinExpression
161 (params :: [NullityType])
161 (params :: [NullityType])
162 (schema :: [(Symbol,[(Symbol,NullityType)])])
162 (schema :: [(Symbol,[(Symbol,NullityType)])])
163 (tables :: [(Symbol,[(Symbol,NullityType)])])
163 (tables :: [(Symbol,[(Symbol,NullityType)])])
164− = UnsafeTableRef { renderTableRef :: ByteString }
164+ = UnsafeJoinExpression { renderJoinExpression :: ByteString }
165
165
166class KnownSymbol table => HasTable table tables columns
166class KnownSymbol table => HasTable table tables columns
167 | table tables -> columns where
167 | table tables -> columns where
168− getTable :: Proxy# table -> TableRef params tables '[table ::: columns]
168+ getTable :: Proxy# table -> JoinExpression params tables '[table ::: columns]
169− getTable table = UnsafeTableRef $ fromString $ symbolVal' table
169+ getTable table = UnsafeJoinExpression $ fromString $ symbolVal' table
170instance {-# OVERLAPPING #-} KnownSymbol table
170instance {-# OVERLAPPING #-} KnownSymbol table
171 => HasTable table ((table ::: columns) ': tables) columns
171 => HasTable table ((table ::: columns) ': tables) columns
172instance {-# OVERLAPPABLE #-}
172instance {-# OVERLAPPABLE #-}
173 (KnownSymbol table, HasTable table schema columns)
173 (KnownSymbol table, HasTable table schema columns)
174 => HasTable table (table' ': schema) columns
174 => HasTable table (table' ': schema) columns
175
175
176−crossJoin
176+cross
177− :: TableRef params schema '[table]
177+ :: JoinExpression params schema '[table]
178− -> TableRef params schema tables
178+ -> JoinExpression params schema tables
179− -> TableRef params schema (table ': tables)
179+ -> JoinExpression params schema (table ': tables)
180−crossJoin tab tabs = UnsafeTableRef $
180+cross tab tabs = UnsafeJoinExpression $
181− renderTableRef tabs <> " CROSS JOIN " <> renderTableRef tab
181+ renderJoinExpression tabs <> " CROSS JOIN " <> renderJoinExpression tab
182
182
183−innerJoin
183+inner
184− :: TableRef params schema '[table]
184+ :: JoinExpression params schema '[table]
185 -> Expression params (table ': tables) ('NotNull 'PGBool)
185 -> Expression params (table ': tables) ('NotNull 'PGBool)
186− -> TableRef params schema tables
186+ -> JoinExpression params schema tables
187− -> TableRef params schema (table ': tables)
187+ -> JoinExpression params schema (table ': tables)
188−innerJoin tab on tabs = UnsafeTableRef $
188+inner tab on tabs = UnsafeJoinExpression $
189− renderTableRef tabs
189+ renderJoinExpression tabs
190 <> " INNER JOIN " <>
190 <> " INNER JOIN " <>
191− renderTableRef tab
191+ renderJoinExpression tab
192 <> " ON " <>
192 <> " ON " <>
193 renderExpression on
193 renderExpression on
194
194
195−leftOuterJoin
195+leftOuter
196− :: TableRef params schema '[right]
196+ :: JoinExpression params schema '[right]
197− -> Expression params (right ': tables) ('NotNull 'PGBool)
197+ -> Expression params (right ': left : tables) ('NotNull 'PGBool)
198− -> TableRef params schema (left : tables)
198+ -> JoinExpression params schema (tables)
199− -> TableRef params schema (NullifyTable right ': left ': tables)
199+ -> JoinExpression params schema (NullifyTable right ': left ': tables)
200−leftOuterJoin tab on tabs = UnsafeTableRef $
200+leftOuter tab on tabs = UnsafeJoinExpression $
201− renderTableRef tabs
201+ renderJoinExpression tabs
202 <> " LEFT OUTER JOIN " <>
202 <> " LEFT OUTER JOIN " <>
203− renderTableRef tab
203+ renderJoinExpression tab
204 <> " ON " <>
204 <> " ON " <>
205 renderExpression on
205 renderExpression on
206
206
207−rightOuterJoin
207+rightOuter
208− :: TableRef params schema '[right]
208+ :: JoinExpression params schema '[right]
209 -> Expression params (right ': tables) ('NotNull 'PGBool)
209 -> Expression params (right ': tables) ('NotNull 'PGBool)
210− -> TableRef params schema (left : tables)
210+ -> JoinExpression params schema (left : tables)
211− -> TableRef params schema (right ': NullifyTable left ': tables)
211+ -> JoinExpression params schema (right ': NullifyTable left ': tables)
212−rightOuterJoin tab on tabs = UnsafeTableRef $
212+rightOuter tab on tabs = UnsafeJoinExpression $
213− renderTableRef tabs
213+ renderJoinExpression tabs
214 <> " RIGHT OUTER JOIN " <>
214 <> " RIGHT OUTER JOIN " <>
215− renderTableRef tab
215+ renderJoinExpression tab
216 <> " ON " <>
216 <> " ON " <>
217 renderExpression on
217 renderExpression on
218
218
219−fullOuterJoin
219+fullOuter
220− :: TableRef params schema '[right]
220+ :: JoinExpression params schema '[right]
221− -> Expression params (right ': tables) ('NotNull 'PGBool)
221+ -> Expression params (right ': left ': tables) ('NotNull 'PGBool)
222− -> TableRef params schema (left : tables)
222+ -> JoinExpression params schema (left : tables)
223− -> TableRef params schema
223+ -> JoinExpression params schema
224 (NullifyTable right ': NullifyTable left ': tables)
224 (NullifyTable right ': NullifyTable left ': tables)
225−fullOuterJoin tab on tabs = UnsafeTableRef $
225+fullOuter tab on tabs = UnsafeJoinExpression $
226− renderTableRef tabs
226+ renderJoinExpression tabs
227 <> " FULL OUTER JOIN " <>
227 <> " FULL OUTER JOIN " <>
228− renderTableRef tab
228+ renderJoinExpression tab
229 <> " ON " <>
229 <> " ON " <>
230 renderExpression on
230 renderExpression on
231
231
@@ -255,55 +255,55 @@ instance Monoid (Clauses params tables) where
255 (Just o1,Just o2) -> Just (o1 + o2)
255 (Just o1,Just o2) -> Just (o1 + o2)
256 }
256 }
257
257
258−data TableExpression
258+data FromExpression
259 (params :: [NullityType])
259 (params :: [NullityType])
260 (schema :: [(Symbol,[(Symbol,NullityType)])])
260 (schema :: [(Symbol,[(Symbol,NullityType)])])
261 (tables :: [(Symbol,[(Symbol,NullityType)])])
261 (tables :: [(Symbol,[(Symbol,NullityType)])])
262− = TableExpression
262+ = FromExpression
263− { tableRef :: TableRef params schema tables
263+ { joinExpression :: JoinExpression params schema tables
264 , clauses :: Clauses params tables
264 , clauses :: Clauses params tables
265 }
265 }
266
266
267−tables
267+join
268− :: TableRef params schema tables
268+ :: JoinExpression params schema tables
269− -> TableExpression params schema tables
269+ -> FromExpression params schema tables
270−tables tref = TableExpression tref mempty
270+join tref = FromExpression tref mempty
271
271
272−renderTabulation :: TableExpression params schema tables -> ByteString
272+renderTabulation :: FromExpression params schema tables -> ByteString
273−renderTabulation (TableExpression tref (Clauses wh lim off))= mconcat
273+renderTabulation (FromExpression tref (Clauses wh lim off))= mconcat
274− [ renderTableRef tref
274+ [ renderJoinExpression tref
275 , maybe "" ((" WHERE " <>) . renderExpression) wh
275 , maybe "" ((" WHERE " <>) . renderExpression) wh
276 , maybe "" ((" LIMIT " <>) . renderExpression) lim
276 , maybe "" ((" LIMIT " <>) . renderExpression) lim
277 , maybe "" ((" OFFSET " <>) . renderExpression) off
277 , maybe "" ((" OFFSET " <>) . renderExpression) off
278 ]
278 ]
279
279
280instance (HasTable table schema columns, table ~ table')
280instance (HasTable table schema columns, table ~ table')
281− => IsLabel table (TableRef params schema '[table' ::: columns]) where
281+ => IsLabel table (JoinExpression params schema '[table' ::: columns]) where
282 fromLabel = getTable
282 fromLabel = getTable
283
283
284instance (HasTable table schema columns, table ~ table')
284instance (HasTable table schema columns, table ~ table')
285− => IsLabel table (TableExpression params schema '[table' ::: columns]) where
285+ => IsLabel table (FromExpression params schema '[table' ::: columns]) where
286− fromLabel p = TableExpression (getTable p) mempty
286+ fromLabel p = FromExpression (getTable p) mempty
287
287
288where_
288where_
289 :: Expression params tables ('NotNull 'PGBool)
289 :: Expression params tables ('NotNull 'PGBool)
290− -> TableExpression params schema tables
290+ -> FromExpression params schema tables
291− -> TableExpression params schema tables
291+ -> FromExpression params schema tables
292−where_ wh (TableExpression tabs clauses1) = TableExpression tabs
292+where_ wh (FromExpression tabs clauses1) = FromExpression tabs
293 (clauses1 <> Clauses (Just wh) Nothing Nothing)
293 (clauses1 <> Clauses (Just wh) Nothing Nothing)
294
294
295limit
295limit
296 :: Expression params '[] ('NotNull 'PGInt8)
296 :: Expression params '[] ('NotNull 'PGInt8)
297− -> TableExpression params schema tables
297+ -> FromExpression params schema tables
298− -> TableExpression params schema tables
298+ -> FromExpression params schema tables
299−limit lim (TableExpression tabs clauses1) = TableExpression tabs
299+limit lim (FromExpression tabs clauses1) = FromExpression tabs
300 (clauses1 <> Clauses Nothing (Just lim) Nothing)
300 (clauses1 <> Clauses Nothing (Just lim) Nothing)
301
301
302offset
302offset
303 :: Expression params '[] ('NotNull 'PGInt8)
303 :: Expression params '[] ('NotNull 'PGInt8)
304− -> TableExpression params schema tables
304+ -> FromExpression params schema tables
305− -> TableExpression params schema tables
305+ -> FromExpression params schema tables
306−offset off (TableExpression tabs clauses1) = TableExpression tabs
306+offset off (FromExpression tabs clauses1) = FromExpression tabs
307 (clauses1 <> Clauses Nothing Nothing (Just off))
307 (clauses1 <> Clauses Nothing Nothing (Just off))
308
308
309newtype Selection
309newtype Selection
@@ -315,21 +315,21 @@ newtype Selection
315
315
316starFrom
316starFrom
317 :: tables ~ '[table ::: columns]
317 :: tables ~ '[table ::: columns]
318− => TableExpression params schema tables
318+ => FromExpression params schema tables
319 -> Selection params schema columns
319 -> Selection params schema columns
320starFrom tabs = UnsafeSelection $ "* FROM " <> renderTabulation tabs
320starFrom tabs = UnsafeSelection $ "* FROM " <> renderTabulation tabs
321
321
322dotStarFrom
322dotStarFrom
323 :: HasTable table tables columns
323 :: HasTable table tables columns
324 => Alias table
324 => Alias table
325− -> TableExpression params schema tables
325+ -> FromExpression params schema tables
326 -> Selection params schema columns
326 -> Selection params schema columns
327Alias tab `dotStarFrom` tabs = UnsafeSelection $
327Alias tab `dotStarFrom` tabs = UnsafeSelection $
328 fromString (symbolVal' tab) <> ".* FROM" <> renderTabulation tabs
328 fromString (symbolVal' tab) <> ".* FROM" <> renderTabulation tabs
329
329
330from
330from
331 :: Rec (Aliased (Expression params tables)) columns
331 :: Rec (Aliased (Expression params tables)) columns
332− -> TableExpression params schema tables
332+ -> FromExpression params schema tables
333 -> Selection params schema columns
333 -> Selection params schema columns
334list `from` tabs = UnsafeSelection $
334list `from` tabs = UnsafeSelection $
335 renderList list <> " FROM " <> renderTabulation tabs
335 renderList list <> " FROM " <> renderTabulation tabs
@@ -360,9 +360,9 @@ select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
360
360
361subselect
361subselect
362 :: Aliased (Selection params schema) table
362 :: Aliased (Selection params schema) table
363− -> TableExpression params schema '[table]
363+ -> FromExpression params schema '[table]
364−subselect selection = TableExpression
364+subselect selection = FromExpression
365− { tableRef = UnsafeTableRef . ("SELECT " <>) $
365+ { tableRef = UnsafeJoinExpression . ("SELECT " <>) $
366 renderAliased renderSelection selection
366 renderAliased renderSelection selection
367 , clauses = mempty
367 , clauses = mempty
368 }
368 }
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+5−5
@@ -93,7 +93,7 @@ spec = do
93 let
93 let
94 statement :: Statement '[] JoinTables JoinTables ValueColumns
94 statement :: Statement '[] JoinTables JoinTables ValueColumns
95 statement = select $ vals `from`
95 statement = select $ vals `from`
96− (tables (#orders & crossJoin #customers & crossJoin #shippers))
96+ (join (#orders & cross #customers & cross #shippers))
97 statement `shouldRenderAs`
97 statement `shouldRenderAs`
98 "SELECT\
98 "SELECT\
99 \ orders.orderVal AS orderVal,\
99 \ orders.orderVal AS orderVal,\
@@ -104,12 +104,12 @@ spec = do
104 \ CROSS JOIN shippers;"
104 \ CROSS JOIN shippers;"
105 it "should render INNER JOINs" $ do
105 it "should render INNER JOINs" $ do
106 let
106 let
107− innerJoins :: TableExpression '[] JoinTables JoinTables
107+ innerJoins :: FromExpression '[] JoinTables JoinTables
108− innerJoins = tables $
108+ innerJoins = join $
109 #orders
109 #orders
110− & innerJoin #customers
110+ & inner #customers
111 (#orders .&. #customerID ==* #customers .&. #customerID)
111 (#orders .&. #customerID ==* #customers .&. #customerID)
112− & innerJoin #shippers
112+ & inner #shippers
113 (#orders .&. #shipperID ==* #shippers .&. #shipperID)
113 (#orders .&. #shipperID ==* #shippers .&. #shipperID)
114 selection :: Statement '[] JoinTables JoinTables ValueColumns
114 selection :: Statement '[] JoinTables JoinTables ValueColumns
115 selection = select $ vals `from` innerJoins
115 selection = select $ vals `from` innerJoins