on dev help sign in
lts
e1c115eEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+1
@@ -1,5 +1,6 @@
1{-# LANGUAGE
1{-# LANGUAGE
2 TypeFamilies
2 TypeFamilies
3+ , UndecidableSuperClasses
3#-}
4#-}
4
5
5{-|
6{-|
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+2−3
@@ -206,9 +206,8 @@ instance RenderSQL (Manipulation commons schemas params columns) where
206 renderSQL = renderManipulation
206 renderSQL = renderManipulation
207instance With Manipulation where
207instance With Manipulation where
208 with Done manip = manip
208 with Done manip = manip
209− with (cte :>> ctes) manip = UnsafeManipulation $
209+ with ctes manip = UnsafeManipulation $
210− "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
211− <+> renderSQL manip
210+ "WITH" <+> renderSQL ctes <+> renderSQL manip
212
211
213type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
212type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
214 Manipulation_ schemas params row = Manipulation '[] schemas (TuplePG params) (RowPG row)
213 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
83import Generics.SOP
83import Generics.SOP
84import PostgreSQL.Binary.Encoding (encodingBytes)
84import PostgreSQL.Binary.Encoding (encodingBytes)
85
85
86+import qualified Control.Monad.Fail as Fail
86import qualified Database.PostgreSQL.LibPQ as LibPQ
87import qualified Database.PostgreSQL.LibPQ as LibPQ
87
88
88import Squeal.PostgreSQL.Binary
89import Squeal.PostgreSQL.Binary
@@ -488,6 +489,10 @@ instance (Monad m, schemas0 ~ schemas1)
488 return = pure
489 return = pure
489 (>>=) = flip pqBind
490 (>>=) = flip pqBind
490
491
492+instance (Monad m, schemas0 ~ schemas1)
493+ => Fail.MonadFail (PQ schemas0 schemas1 m) where
494+ fail = Fail.fail
495+
491instance schemas0 ~ schemas1 => MFunctor (PQ schemas0 schemas1) where
496instance schemas0 ~ schemas1 => MFunctor (PQ schemas0 schemas1) where
492 hoist f (PQ pq) = PQ (f . pq)
497 hoist f (PQ pq) = PQ (f . pq)
493
498
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+7−24
@@ -18,6 +18,7 @@ Squeal queries.
18 , LambdaCase
18 , LambdaCase
19 , MultiParamTypeClasses
19 , MultiParamTypeClasses
20 , OverloadedStrings
20 , OverloadedStrings
21+ , QuantifiedConstraints
21 , ScopedTypeVariables
22 , ScopedTypeVariables
22 , StandaloneDeriving
23 , StandaloneDeriving
23 , TypeApplications
24 , TypeApplications
@@ -51,8 +52,6 @@ module Squeal.PostgreSQL.Query
51 -- ** With
52 -- ** With
52 , With (..)
53 , With (..)
53 , CommonTableExpression (..)
54 , CommonTableExpression (..)
54− , renderCommonTableExpression
55− , renderCommonTableExpressions
56 -- ** Json
55 -- ** Json
57 , jsonEach
56 , jsonEach
58 , jsonbEach
57 , jsonbEach
@@ -1346,25 +1345,10 @@ instance
1346 (AlignedList (CommonTableExpression statement schemas params) commons commons1) where
1345 (AlignedList (CommonTableExpression statement schemas params) commons commons1) where
1347 statement `as` cte = single (statement `as` cte)
1346 statement `as` cte = single (statement `as` cte)
1348
1347
1349−-- | render a `CommonTableExpression`.
1348+instance (forall c s p r. RenderSQL (statement c s p r)) => RenderSQL
1350−renderCommonTableExpression
1351− :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1352− -> CommonTableExpression statement schemas params commons0 commons1 -> ByteString
1349+ (CommonTableExpression statement schemas params commons0 commons1) where
1353−renderCommonTableExpression renderStatement
1354− (CommonTableExpression (statement `As` alias)) =
1350+ renderSQL (CommonTableExpression (statement `As` cte)) =
1355− renderSQL alias <+> "AS" <+> parenthesized (renderStatement statement)
1351+ renderSQL cte <+> "AS" <+> parenthesized (renderSQL 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'
1368
1352
1369-- | `with` provides a way to write auxiliary statements for use in a larger query.
1353-- | `with` provides a way to write auxiliary statements for use in a larger query.
1370-- These statements, referred to as `CommonTableExpression`s, can be thought of as
1354-- These statements, referred to as `CommonTableExpression`s, can be thought of as
@@ -1378,6 +1362,5 @@ class With statement where
1378 -> statement commons0 schemas params row
1362 -> statement commons0 schemas params row
1379instance With Query where
1363instance With Query where
1380 with Done query = query
1364 with Done query = query
1381− with (cte :>> ctes) query = UnsafeQuery $
1365+ with ctes query = UnsafeQuery $
1382− "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
1383− <+> renderSQL query
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.
22 , GADTs
22 , GADTs
23 , LambdaCase
23 , LambdaCase
24 , OverloadedStrings
24 , OverloadedStrings
25+ , QuantifiedConstraints
25 , RankNTypes
26 , RankNTypes
26 , ScopedTypeVariables
27 , ScopedTypeVariables
27 , StandaloneDeriving
28 , StandaloneDeriving
@@ -775,6 +776,7 @@ RowPG Person :: [(Symbol, NullityType)]
775= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
776= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
776-}
777-}
777type family RowPG (hask :: Type) :: RowType where
778type family RowPG (hask :: Type) :: RowType where
779+ RowPG (P (col ::: head), tail) = col ::: NullPG head ': RowPG tail
778 RowPG hask = RowOf (RecordCodeOf hask)
780 RowPG hask = RowOf (RecordCodeOf hask)
779
781
780type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
782type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
@@ -802,7 +804,7 @@ the corresponding list of `NullityType`s.
802
804
803>>> :kind! TuplePG (Double, Maybe Char)
805>>> :kind! TuplePG (Double, Maybe Char)
804TuplePG (Double, Maybe Char) :: [NullityType]
806TuplePG (Double, Maybe Char) :: [NullityType]
805−= '['NotNull 'PGfloat8, 'Null ('PGchar 1)]
807+= '[ 'NotNull 'PGfloat8, 'Null ('PGchar 1)]
806-}
808-}
807type family TuplePG (hask :: Type) :: [NullityType] where
809type family TuplePG (hask :: Type) :: [NullityType] where
808 TuplePG hask = TupleOf (TupleCodeOf hask (Code hask))
810 TuplePG hask = TupleOf (TupleCodeOf hask (Code hask))
@@ -867,6 +869,12 @@ instance Category (AlignedList p) where
867 (.) list = \case
869 (.) list = \case
868 Done -> list
870 Done -> list
869 step :>> steps -> step :>> (steps >>> list)
871 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
870
878
871-- | A `single` step.
879-- | A `single` step.
872single :: p x0 x1 -> AlignedList p x0 x1
880single :: 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
2packages:
2packages:
3- squeal-postgresql
3- squeal-postgresql