on dev help sign in
remove Proxy from param
21b9167Eitan Chatav
squeal-postgresql/exe/Example.hs+11−15
@@ -1,4 +1,4 @@
1−{-# OPTIONS_GHC -fno-warn-unused-imports #-}
1+{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}
2{-# LANGUAGE
2{-# LANGUAGE
3 DataKinds
3 DataKinds
4 , DeriveGeneric
4 , DeriveGeneric
@@ -6,6 +6,7 @@
6 , MultiParamTypeClasses
6 , MultiParamTypeClasses
7 , OverloadedLabels
7 , OverloadedLabels
8 , OverloadedStrings
8 , OverloadedStrings
9+ , PartialTypeSignatures
9 , TypeApplications
10 , TypeApplications
10 , TypeOperators
11 , TypeOperators
11 , TypeSynonymInstances
12 , TypeSynonymInstances
@@ -32,10 +33,10 @@ type Schema =
32 ]
33 ]
33 ]
34 ]
34
35
35−data Table1Row = Table1Row { col1 :: Int32, col2 :: Int32 }
36+data Row = Row { col1 :: Int32, col2 :: Int32 }
36 deriving (Show, GHC.Generic)
37 deriving (Show, GHC.Generic)
37−instance Generic Table1Row
38+instance Generic Row
38−instance HasDatatypeInfo Table1Row
39+instance HasDatatypeInfo Row
39
40
40main :: IO ()
41main :: IO ()
41main = do
42main = do
@@ -52,17 +53,12 @@ main = do
52 ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
53 ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
53 connection2 <- flip execPQ (connection1 :: Connection Schema) $ do
54 connection2 <- flip execPQ (connection1 :: Connection Schema) $ do
54 let
55 let
55− insert :: Manipulation Schema
56+ insert :: Manipulation Schema '[_,_,_,_] '[]
56− '[ 'Required ('NotNull 'PGint4)
57− , 'Required ('NotNull 'PGint4)
58− , 'Required ('NotNull 'PGint4)
59− , 'Required ('NotNull 'PGint4)
60− ] '[]
61 insert =
57 insert =
62 insertInto #table1
58 insertInto #table1
63 ( Values
59 ( Values
64− (param (Proxy @1) `As` #col1 :* param (Proxy @2) `As` #col2 :* Nil)
60+ (param @1 `As` #col1 :* param @2 `As` #col2 :* Nil)
65− [param (Proxy @3) `As` #col1 :* param (Proxy @4) `As` #col2 :* Nil]
61+ [param @3 `As` #col1 :* param @4 `As` #col2 :* Nil]
66 ) Conflict (Returning Nil)
62 ) Conflict (Returning Nil)
67 liftBase $ Char8.putStrLn "manipulating"
63 liftBase $ Char8.putStrLn "manipulating"
68 _insertResult <- manipulateParams insert
64 _insertResult <- manipulateParams insert
@@ -82,9 +78,9 @@ main = do
82 print (value01 :: Int32)
78 print (value01 :: Int32)
83 print (value10 :: Int32)
79 print (value10 :: Int32)
84 print (value11 :: Int32)
80 print (value11 :: Int32)
85− print (row0 :: Table1Row)
81+ print (row0 :: Row)
86− print (row1 :: Table1Row)
82+ print (row1 :: Row)
87− print (rows :: [Table1Row])
83+ print (rows :: [Row])
88 Char8.putStrLn "tearing down schema"
84 Char8.putStrLn "tearing down schema"
89 connection3 <- flip execPQ (connection2 :: Connection Schema) $ define $
85 connection3 <- flip execPQ (connection2 :: Connection Schema) $ define $
90 dropTable #table1 >>> dropTable #students
86 dropTable #table1 >>> dropTable #students
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
@@ -115,8 +115,8 @@ data NullityType
115
115
116-- | `ColumnType` encodes the allowance of @DEFAULT@ and the only way
116-- | `ColumnType` encodes the allowance of @DEFAULT@ and the only way
117-- to generate an `Optional` `Squeel.PostgreSQL.Statement.Expression`
117-- to generate an `Optional` `Squeel.PostgreSQL.Statement.Expression`
118−-- is to use `Squeel.PostgreSQL.Statement.def`
118+-- is to use `Squeel.PostgreSQL.Statement.def`,
119−-- or `Squeel.PostgreSQL.Statement.unDef`.
119+-- `Squeel.PostgreSQL.Statement.unDef` or `Squeel.PostgreSQL.Statement.param`.
120data ColumnType
120data ColumnType
121 = Optional NullityType
121 = Optional NullityType
122 -- ^ @DEFAULT@ is an allowed `Squeel.PostgreSQL.Statement.Expression`
122 -- ^ @DEFAULT@ is an allowed `Squeel.PostgreSQL.Statement.Expression`
squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+12−9
@@ -1,6 +1,7 @@
1{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
1{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
2{-# LANGUAGE
2{-# LANGUAGE
3+ AllowAmbiguousTypes
3− DataKinds
4+ , DataKinds
4 , DeriveGeneric
5 , DeriveGeneric
5 , DeriveDataTypeable
6 , DeriveDataTypeable
6 , FlexibleContexts
7 , FlexibleContexts
@@ -269,8 +270,8 @@ refer to the out-of-line data values.
269-}
270-}
270class (PGTyped (BaseType ty), KnownNat n)
271class (PGTyped (BaseType ty), KnownNat n)
271 => HasParameter (n :: Nat) params ty | n params -> ty where
272 => HasParameter (n :: Nat) params ty | n params -> ty where
272− param :: proxy n -> Expression params tables grouping ty
273+ param :: Expression params tables grouping ty
273− param _ = UnsafeExpression $ parenthesized $
274+ param = UnsafeExpression $ parenthesized $
274 "$" <> renderNat (Proxy @n) <+> "::"
275 "$" <> renderNat (Proxy @n) <+> "::"
275 <+> renderTypeExpression (pgtype @(BaseType ty))
276 <+> renderTypeExpression (pgtype @(BaseType ty))
276instance {-# OVERLAPPING #-} PGTyped (BaseType ty1)
277instance {-# OVERLAPPING #-} PGTyped (BaseType ty1)
@@ -1099,22 +1100,22 @@ bigserial = UnsafeTypeExpression "bigserial"
1099text :: TypeExpression ('Required ('Null 'PGtext))
1100text :: TypeExpression ('Required ('Null 'PGtext))
1100text = UnsafeTypeExpression "text"
1101text = UnsafeTypeExpression "text"
1101char
1102char
1102− :: KnownNat n
1103+ :: (KnownNat n, 1 <= n)
1103 => proxy n
1104 => proxy n
1104 -> TypeExpression ('Required ('Null ('PGchar n)))
1105 -> TypeExpression ('Required ('Null ('PGchar n)))
1105char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1106char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1106character
1107character
1107− :: KnownNat n
1108+ :: (KnownNat n, 1 <= n)
1108 => proxy n
1109 => proxy n
1109 -> TypeExpression ('Required ('Null ('PGchar n)))
1110 -> TypeExpression ('Required ('Null ('PGchar n)))
1110character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1111character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1111varchar
1112varchar
1112− :: KnownNat n
1113+ :: (KnownNat n, 1 <= n)
1113 => proxy n
1114 => proxy n
1114 -> TypeExpression ('Required ('Null ('PGvarchar n)))
1115 -> TypeExpression ('Required ('Null ('PGvarchar n)))
1115varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1116varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1116characterVarying
1117characterVarying
1117− :: KnownNat n
1118+ :: (KnownNat n, 1 <= n)
1118 => proxy n
1119 => proxy n
1119 -> TypeExpression ('Required ('Null ('PGvarchar n)))
1120 -> TypeExpression ('Required ('Null ('PGvarchar n)))
1120characterVarying p = UnsafeTypeExpression $
1121characterVarying p = UnsafeTypeExpression $
@@ -1161,8 +1162,10 @@ instance PGTyped 'PGnumeric where pgtype = numeric
1161instance PGTyped 'PGfloat4 where pgtype = float4
1162instance PGTyped 'PGfloat4 where pgtype = float4
1162instance PGTyped 'PGfloat8 where pgtype = float8
1163instance PGTyped 'PGfloat8 where pgtype = float8
1163instance PGTyped 'PGtext where pgtype = text
1164instance PGTyped 'PGtext where pgtype = text
1165+instance (KnownNat n, 1 <= n)
1164−instance KnownNat n => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
1166+ => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
1167+instance (KnownNat n, 1 <= n)
1165−instance KnownNat n => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
1168+ => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
1166instance PGTyped 'PGbytea where pgtype = bytea
1169instance PGTyped 'PGbytea where pgtype = bytea
1167instance PGTyped 'PGtimestamp where pgtype = timestamp
1170instance PGTyped 'PGtimestamp where pgtype = timestamp
1168instance PGTyped 'PGtimestamptz where pgtype = timestampWithTimeZone
1171instance PGTyped 'PGtimestamptz where pgtype = timestampWithTimeZone
squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+1−1
@@ -69,7 +69,7 @@ spec = do
69 let
69 let
70 statement :: Query Tables '[ 'Required ('NotNull 'PGbool)] Columns
70 statement :: Query Tables '[ 'Required ('NotNull 'PGbool)] Columns
71 statement = selectStar
71 statement = selectStar
72− (from (Table (#table1 `As` #table1)) & where_ (param (Proxy @1)))
72+ (from (Table (#table1 `As` #table1)) & where_ (param @1))
73 statement `queryRenders`
73 statement `queryRenders`
74 "SELECT * FROM table1 AS table1 WHERE ($1 :: bool);"
74 "SELECT * FROM table1 AS table1 WHERE ($1 :: bool);"
75 it "does OFFSET clauses" $ do
75 it "does OFFSET clauses" $ do