on dev help sign in
some changes
commit872e605887ad89bdcbf1a177eed0235d21af27e9 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 19 Aug 2017, 12:29 (9 years ago) parenta2b5148
5 files changed+51−51
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+31−31 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+10−10 squeal-postgresql/test/Squeal/PostgreSQL/DefinitionSpec.hs+2−2 squeal-postgresql/test/Squeal/PostgreSQL/ManipulationSpec.hs+4−4 squeal-postgresql/test/Squeal/PostgreSQL/QuerySpec.hs+4−4
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+31−31
@@ -61,16 +61,16 @@ module Squeal.PostgreSQL.Expression
6161 , true
6262 , false
6363 , not_
64− , (&&*)
65− , (||*)
64+ , (.&&)
65+ , (.||)
6666 , caseWhenThenElse
6767 , ifThenElse
68− , (==*)
69− , (/=*)
70− , (>=*)
71− , (*<)
72− , (*<=)
73− , (>*)
68+ , (.==)
69+ , (./=)
70+ , (.>=)
71+ , (.<)
72+ , (.<=)
73+ , (.>)
7474 -- ** Time
7575 , currentDate
7676 , currentTime
@@ -362,7 +362,7 @@ matchNull y f x = ifThenElse (isNull x) y
362362--
363363-- >>> :set -XTypeApplications -XDataKinds
364364-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
365−-- "COALESCE(NULL IF (FALSE, FALSE), FALSE)"
365+-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
366366nullIf
367367 :: Expression tables grouping params ('Required ('NotNull ty))
368368 -> Expression tables grouping params ('Required ('NotNull ty))
@@ -526,17 +526,17 @@ not_
526526 -> Condition tables grouping params
527527not_ = unsafeUnaryOp "NOT"
528528
529−(&&*)
529+(.&&)
530530 :: Condition tables grouping params
531531 -> Condition tables grouping params
532532 -> Condition tables grouping params
533−(&&*) = unsafeBinaryOp "AND"
533+(.&&) = unsafeBinaryOp "AND"
534534
535−(||*)
535+(.||)
536536 :: Condition tables grouping params
537537 -> Condition tables grouping params
538538 -> Condition tables grouping params
539−(||*) = unsafeBinaryOp "OR"
539+(.||) = unsafeBinaryOp "OR"
540540
541541caseWhenThenElse
542542 :: [ ( Condition tables grouping params
@@ -564,47 +564,47 @@ ifThenElse
564564 -> Expression tables grouping params ('Required ty)
565565ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
566566
567−(==*)
567+(.==)
568568 :: Expression tables grouping params ('Required (nullity ty))
569569 -> Expression tables grouping params ('Required (nullity ty))
570570 -> Expression tables grouping params ('Required (nullity 'PGbool))
571−(==*) = unsafeBinaryOp "="
572−infix 4 ==*
571+(.==) = unsafeBinaryOp "="
572+infix 4 .==
573573
574−(/=*)
574+(./=)
575575 :: Expression tables grouping params ('Required (nullity ty))
576576 -> Expression tables grouping params ('Required (nullity ty))
577577 -> Expression tables grouping params ('Required (nullity 'PGbool))
578−(/=*) = unsafeBinaryOp "<>"
579−infix 4 /=*
578+(./=) = unsafeBinaryOp "<>"
579+infix 4 ./=
580580
581−(>=*)
581+(.>=)
582582 :: Expression tables grouping params ('Required (nullity ty))
583583 -> Expression tables grouping params ('Required (nullity ty))
584584 -> Expression tables grouping params ('Required (nullity 'PGbool))
585−(>=*) = unsafeBinaryOp ">="
586−infix 4 >=*
585+(.>=) = unsafeBinaryOp ">="
586+infix 4 .>=
587587
588−(*<)
588+(.<)
589589 :: Expression tables grouping params ('Required (nullity ty))
590590 -> Expression tables grouping params ('Required (nullity ty))
591591 -> Expression tables grouping params ('Required (nullity 'PGbool))
592−(*<) = unsafeBinaryOp "<"
593−infix 4 *<
592+(.<) = unsafeBinaryOp "<"
593+infix 4 .<
594594
595−(*<=)
595+(.<=)
596596 :: Expression tables grouping params ('Required (nullity ty))
597597 -> Expression tables grouping params ('Required (nullity ty))
598598 -> Expression tables grouping params ('Required (nullity 'PGbool))
599−(*<=) = unsafeBinaryOp "<="
600−infix 4 *<=
599+(.<=) = unsafeBinaryOp "<="
600+infix 4 .<=
601601
602−(>*)
602+(.>)
603603 :: Expression tables grouping params ('Required (nullity ty))
604604 -> Expression tables grouping params ('Required (nullity ty))
605605 -> Expression tables grouping params ('Required (nullity 'PGbool))
606−(>*) = unsafeBinaryOp ">"
607−infix 4 >*
606+(.>) = unsafeBinaryOp ">"
607+infix 4 .>
608608
609609currentDate
610610 :: Expression tables grouping params ('Required (nullity 'PGdate))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+10−10
@@ -46,9 +46,9 @@ module Squeal.PostgreSQL.Query
4646 , orderBy
4747 , limit
4848 , offset
49+ -- * Grouping
4950 , By (By, By2)
5051 , renderBy
51− -- * Grouping
5252 , GroupByClause (NoGroups, Group)
5353 , renderGroupByClause
5454 , HavingClause (NoHaving, Having)
@@ -218,7 +218,7 @@ data TableExpression
218218 { fromClause :: FromClause schema params tables
219219 , whereClause :: [Condition tables 'Ungrouped params]
220220 , groupByClause :: GroupByClause tables grouping
221− , havingClause :: HavingClause params tables grouping
221+ , havingClause :: HavingClause tables grouping params
222222 , orderByClause :: [SortExpression tables grouping params]
223223 , limitClause :: [Word64]
224224 , offsetClause :: [Word64]
@@ -241,7 +241,7 @@ renderTableExpression
241241 renderWheres = \case
242242 [] -> ""
243243 wh:[] -> " WHERE" <+> renderExpression wh
244− wh:whs -> " WHERE" <+> renderExpression (foldr (&&*) wh whs)
244+ wh:whs -> " WHERE" <+> renderExpression (foldr (.&&) wh whs)
245245 renderSorts = \case
246246 [] -> ""
247247 srts -> " SORT BY"
@@ -341,16 +341,16 @@ renderGroupByClause = \case
341341 Group Nil -> ""
342342 Group bys -> " GROUP BY" <+> renderCommaSeparated renderBy bys
343343
344−data HavingClause params tables grouping where
345− NoHaving :: HavingClause params tables 'Ungrouped
344+data HavingClause tables grouping params where
345+ NoHaving :: HavingClause tables 'Ungrouped params
346346 Having
347347 :: [Condition tables ('Grouped bys) params]
348− -> HavingClause params tables ('Grouped bys)
349−deriving instance Show (HavingClause params tables grouping)
350−deriving instance Eq (HavingClause params tables grouping)
351−deriving instance Ord (HavingClause params tables grouping)
348+ -> HavingClause tables ('Grouped bys) params
349+deriving instance Show (HavingClause tables grouping params)
350+deriving instance Eq (HavingClause tables grouping params)
351+deriving instance Ord (HavingClause tables grouping params)
352352
353−renderHavingClause :: HavingClause params tables grouping -> ByteString
353+renderHavingClause :: HavingClause tables grouping params -> ByteString
354354renderHavingClause = \case
355355 NoHaving -> ""
356356 Having [] -> ""
squeal-postgresql/test/Squeal/PostgreSQL/DefinitionSpec.hs+2−2
@@ -33,7 +33,7 @@ spec = do
3333 ( serial `As` #col1 :*
3434 text `As` #col2 :*
3535 (int8 & notNull & default_ 8) `As` #col3 :* Nil )
36− [check (#col3 >* 0)]
36+ [check (#col3 .> 0)]
3737 `definitionRenders`
3838 "CREATE TABLE table2\
3939 \ (col1 serial,\
@@ -65,7 +65,7 @@ spec = do
6565 , foreignKey (Column #userid :* Nil) #users (Column #id :* Nil)
6666 OnDeleteCascade OnUpdateRestrict
6767 , unique (Column #email :* Nil)
68− , check (#email /=* "")
68+ , check (#email ./= "")
6969 ]
7070 statement `definitionRenders`
7171 "CREATE TABLE users\
squeal-postgresql/test/Squeal/PostgreSQL/ManipulationSpec.hs+4−4
@@ -34,7 +34,7 @@ spec = do
3434 statement :: Manipulation Tables '[] '[]
3535 statement =
3636 update #table1 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
37− (#col1 /=* #col2) (Returning Nil)
37+ (#col1 ./= #col2) (Returning Nil)
3838 statement `manipulationRenders`
3939 "UPDATE table1 SET col1 = 2\
4040 \ WHERE (col1 <> col2);"
@@ -43,7 +43,7 @@ spec = do
4343 statement :: Manipulation Tables '[] SumAndCol1
4444 statement =
4545 update #table1 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
46− (#col1 /=* #col2)
46+ (#col1 ./= #col2)
4747 (Returning $ (#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
4848 statement `manipulationRenders`
4949 "UPDATE table1 SET col1 = 2\
@@ -68,7 +68,7 @@ spec = do
6868 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
6969 (OnConflictDoUpdate
7070 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
71− (Just (#col1 /=* #col2)))
71+ (Just (#col1 ./= #col2)))
7272 (Returning $ (#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
7373 statement `manipulationRenders`
7474 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\
@@ -79,7 +79,7 @@ spec = do
7979 it "correctly renders DELETEs" $ do
8080 let
8181 statement :: Manipulation Tables '[] '[]
82− statement = deleteFrom #table1 (#col1 ==* #col2)
82+ statement = deleteFrom #table1 (#col1 .== #col2)
8383 statement `manipulationRenders`
8484 "DELETE FROM table1 WHERE (col1 = col2);"
8585 it "should be safe against SQL injection in literal text" $ do
squeal-postgresql/test/Squeal/PostgreSQL/QuerySpec.hs+4−4
@@ -25,7 +25,7 @@ spec = do
2525 statement :: Query Tables '[] SumAndCol1
2626 statement =
2727 select ((#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
28− (from (Table (#table1 `As` #table1)) & where_ (#col1 >* #col2))
28+ (from (Table (#table1 `As` #table1)) & where_ (#col1 .> #col2))
2929 statement `queryRenders`
3030 "SELECT (col1 + col2) AS sum, col1 AS col1\
3131 \ FROM table1 AS table1 WHERE (col1 > col2);"
@@ -86,7 +86,7 @@ spec = do
8686 select (sum_ #col2 `As` #sum :* #col1 `As` #col1 :* Nil)
8787 ( from (Table (#table1 `As` #table1))
8888 & group (By #col1 :* Nil)
89− & having (#col1 + sum_ #col2 >* 1) )
89+ & having (#col1 + sum_ #col2 .> 1) )
9090 statement `queryRenders`
9191 "SELECT sum(col2) AS sum, col1 AS col1\
9292 \ FROM table1 AS table1\
@@ -120,9 +120,9 @@ spec = do
120120 :* (#shippers ! #shipperVal) `As` #shipperVal :* Nil)
121121 ( from (Table (#orders `As` #orders)
122122 & InnerJoin (Table (#customers `As` #customers))
123− ((#orders ! #customerID) ==* (#customers ! #customerID))
123+ ((#orders ! #customerID) .== (#customers ! #customerID))
124124 & InnerJoin (Table (#shippers `As` #shippers))
125− ((#orders ! #shipperID) ==* (#shippers ! #shipperID))))
125+ ((#orders ! #shipperID) .== (#shippers ! #shipperID))))
126126 statement `queryRenders`
127127 "SELECT\
128128 \ orders.orderVal AS orderVal,\