on dev help sign in
lts
commite1c115e68cd009e8818d11353696c834456ac1cb authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateTue 19 Feb 2019, 10:55 (8 years ago) parent64539b9
6 files changed+25−29
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+1 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+2−3 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+5 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7−24 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+9−1 stack.yaml+1−1
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+1
@@ -1,5 +1,6 @@
11{-# LANGUAGE
22 TypeFamilies
3+ , UndecidableSuperClasses
34#-}
45
56{-|
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+2−3
@@ -206,9 +206,8 @@ instance RenderSQL (Manipulation commons schemas params columns) where
206206 renderSQL = renderManipulation
207207instance With Manipulation where
208208 with Done manip = manip
209− with (cte :>> ctes) manip = UnsafeManipulation $
210− "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
211− <+> renderSQL manip
209+ with ctes manip = UnsafeManipulation $
210+ "WITH" <+> renderSQL ctes <+> renderSQL manip
212211
213212type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
214213 Manipulation_ schemas params row = Manipulation '[] schemas (TuplePG params) (RowPG row)
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+5
@@ -83,6 +83,7 @@ import Data.Traversable
8383import Generics.SOP
8484import PostgreSQL.Binary.Encoding (encodingBytes)
8585
86+import qualified Control.Monad.Fail as Fail
8687import qualified Database.PostgreSQL.LibPQ as LibPQ
8788
8889import Squeal.PostgreSQL.Binary
@@ -488,6 +489,10 @@ instance (Monad m, schemas0 ~ schemas1)
488489 return = pure
489490 (>>=) = flip pqBind
490491
492+instance (Monad m, schemas0 ~ schemas1)
493+ => Fail.MonadFail (PQ schemas0 schemas1 m) where
494+ fail = Fail.fail
495+
491496instance schemas0 ~ schemas1 => MFunctor (PQ schemas0 schemas1) where
492497 hoist f (PQ pq) = PQ (f . pq)
493498
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7−24
@@ -18,6 +18,7 @@ Squeal queries.
1818 , LambdaCase
1919 , MultiParamTypeClasses
2020 , OverloadedStrings
21+ , QuantifiedConstraints
2122 , ScopedTypeVariables
2223 , StandaloneDeriving
2324 , TypeApplications
@@ -51,8 +52,6 @@ module Squeal.PostgreSQL.Query
5152 -- ** With
5253 , With (..)
5354 , CommonTableExpression (..)
54− , renderCommonTableExpression
55− , renderCommonTableExpressions
5655 -- ** Json
5756 , jsonEach
5857 , jsonbEach
@@ -1346,25 +1345,10 @@ instance
13461345 (AlignedList (CommonTableExpression statement schemas params) commons commons1) where
13471346 statement `as` cte = single (statement `as` cte)
13481347
1349−-- | render a `CommonTableExpression`.
1350−renderCommonTableExpression
1351− :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1352− -> CommonTableExpression statement schemas params commons0 commons1 -> ByteString
1353−renderCommonTableExpression renderStatement
1354− (CommonTableExpression (statement `As` alias)) =
1355− renderSQL alias <+> "AS" <+> parenthesized (renderStatement statement)
1356−
1357−-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1358−renderCommonTableExpressions
1359− :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1360− -> CommonTableExpression statement schemas params commons0 commons1
1361− -> AlignedList (CommonTableExpression statement schemas params) commons1 commons2
1362− -> ByteString
1363−renderCommonTableExpressions renderStatement cte ctes =
1364− renderCommonTableExpression renderStatement cte <> case ctes of
1365− Done -> ""
1366− cte' :>> ctes' -> "," <+>
1367− renderCommonTableExpressions renderStatement cte' ctes'
1348+instance (forall c s p r. RenderSQL (statement c s p r)) => RenderSQL
1349+ (CommonTableExpression statement schemas params commons0 commons1) where
1350+ renderSQL (CommonTableExpression (statement `As` cte)) =
1351+ renderSQL cte <+> "AS" <+> parenthesized (renderSQL statement)
13681352
13691353-- | `with` provides a way to write auxiliary statements for use in a larger query.
13701354-- These statements, referred to as `CommonTableExpression`s, can be thought of as
@@ -1378,6 +1362,5 @@ class With statement where
13781362 -> statement commons0 schemas params row
13791363instance With Query where
13801364 with Done query = query
1381− with (cte :>> ctes) query = UnsafeQuery $
1382− "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
1383− <+> renderSQL query
1365+ with ctes query = UnsafeQuery $
1366+ "WITH" <+> renderSQL ctes <+> renderSQL query
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+9−1
@@ -22,6 +22,7 @@ it defines an embedding of Haskell types into Postgres types.
2222 , GADTs
2323 , LambdaCase
2424 , OverloadedStrings
25+ , QuantifiedConstraints
2526 , RankNTypes
2627 , ScopedTypeVariables
2728 , StandaloneDeriving
@@ -775,6 +776,7 @@ RowPG Person :: [(Symbol, NullityType)]
775776= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
776777-}
777778type family RowPG (hask :: Type) :: RowType where
779+ RowPG (P (col ::: head), tail) = col ::: NullPG head ': RowPG tail
778780 RowPG hask = RowOf (RecordCodeOf hask)
779781
780782type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
@@ -802,7 +804,7 @@ the corresponding list of `NullityType`s.
802804
803805>>> :kind! TuplePG (Double, Maybe Char)
804806TuplePG (Double, Maybe Char) :: [NullityType]
805−= '['NotNull 'PGfloat8, 'Null ('PGchar 1)]
807+= '[ 'NotNull 'PGfloat8, 'Null ('PGchar 1)]
806808-}
807809type family TuplePG (hask :: Type) :: [NullityType] where
808810 TuplePG hask = TupleOf (TupleCodeOf hask (Code hask))
@@ -867,6 +869,12 @@ instance Category (AlignedList p) where
867869 (.) list = \case
868870 Done -> list
869871 step :>> steps -> step :>> (steps >>> list)
872+instance (forall t0 t1. RenderSQL (p t0 t1))
873+ => RenderSQL (AlignedList p x0 x1) where
874+ renderSQL = \case
875+ Done -> ""
876+ step :>> Done -> renderSQL step
877+ step :>> steps -> renderSQL step <> ", " <> renderSQL steps
870878
871879-- | A `single` step.
872880single :: p x0 x1 -> AlignedList p x0 x1
stack.yaml+1−1
@@ -1,3 +1,3 @@
1−resolver: nightly-2018-09-03
1+resolver: lts-13.8
22packages:
33- squeal-postgresql