on dev help sign in
remove Proxy from param
commit21b9167675e141be163c7deb2e9583fffcfe8514 authorEitan Chatav <eitan.chatav@gmail.com> dateFri 18 Aug 2017, 09:07 (9 years ago) parent5f924c9
4 files changed+26−27
squeal-postgresql/exe/Example.hs+11−15 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+12−9 squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+1−1
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 #-}
22{-# LANGUAGE
33 DataKinds
44 , DeriveGeneric
@@ -6,6 +6,7 @@
66 , MultiParamTypeClasses
77 , OverloadedLabels
88 , OverloadedStrings
9+ , PartialTypeSignatures
910 , TypeApplications
1011 , TypeOperators
1112 , TypeSynonymInstances
@@ -32,10 +33,10 @@ type Schema =
3233 ]
3334 ]
3435
35−data Table1Row = Table1Row { col1 :: Int32, col2 :: Int32 }
36+data Row = Row { col1 :: Int32, col2 :: Int32 }
3637 deriving (Show, GHC.Generic)
37−instance Generic Table1Row
38−instance HasDatatypeInfo Table1Row
38+instance Generic Row
39+instance HasDatatypeInfo Row
3940
4041main :: IO ()
4142main = do
@@ -52,17 +53,12 @@ main = do
5253 ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
5354 connection2 <- flip execPQ (connection1 :: Connection Schema) $ do
5455 let
55− insert :: Manipulation Schema
56− '[ 'Required ('NotNull 'PGint4)
57− , 'Required ('NotNull 'PGint4)
58− , 'Required ('NotNull 'PGint4)
59− , 'Required ('NotNull 'PGint4)
60− ] '[]
56+ insert :: Manipulation Schema '[_,_,_,_] '[]
6157 insert =
6258 insertInto #table1
6359 ( Values
64− (param (Proxy @1) `As` #col1 :* param (Proxy @2) `As` #col2 :* Nil)
65− [param (Proxy @3) `As` #col1 :* param (Proxy @4) `As` #col2 :* Nil]
60+ (param @1 `As` #col1 :* param @2 `As` #col2 :* Nil)
61+ [param @3 `As` #col1 :* param @4 `As` #col2 :* Nil]
6662 ) Conflict (Returning Nil)
6763 liftBase $ Char8.putStrLn "manipulating"
6864 _insertResult <- manipulateParams insert
@@ -82,9 +78,9 @@ main = do
8278 print (value01 :: Int32)
8379 print (value10 :: Int32)
8480 print (value11 :: Int32)
85− print (row0 :: Table1Row)
86− print (row1 :: Table1Row)
87− print (rows :: [Table1Row])
81+ print (row0 :: Row)
82+ print (row1 :: Row)
83+ print (rows :: [Row])
8884 Char8.putStrLn "tearing down schema"
8985 connection3 <- flip execPQ (connection2 :: Connection Schema) $ define $
9086 dropTable #table1 >>> dropTable #students
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
@@ -115,8 +115,8 @@ data NullityType
115115
116116-- | `ColumnType` encodes the allowance of @DEFAULT@ and the only way
117117-- to generate an `Optional` `Squeel.PostgreSQL.Statement.Expression`
118−-- is to use `Squeel.PostgreSQL.Statement.def`
119−-- or `Squeel.PostgreSQL.Statement.unDef`.
118+-- is to use `Squeel.PostgreSQL.Statement.def`,
119+-- `Squeel.PostgreSQL.Statement.unDef` or `Squeel.PostgreSQL.Statement.param`.
120120data ColumnType
121121 = Optional NullityType
122122 -- ^ @DEFAULT@ is an allowed `Squeel.PostgreSQL.Statement.Expression`
squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+12−9
@@ -1,6 +1,7 @@
11{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
22{-# LANGUAGE
3− DataKinds
3+ AllowAmbiguousTypes
4+ , DataKinds
45 , DeriveGeneric
56 , DeriveDataTypeable
67 , FlexibleContexts
@@ -269,8 +270,8 @@ refer to the out-of-line data values.
269270-}
270271class (PGTyped (BaseType ty), KnownNat n)
271272 => HasParameter (n :: Nat) params ty | n params -> ty where
272− param :: proxy n -> Expression params tables grouping ty
273− param _ = UnsafeExpression $ parenthesized $
273+ param :: Expression params tables grouping ty
274+ param = UnsafeExpression $ parenthesized $
274275 "$" <> renderNat (Proxy @n) <+> "::"
275276 <+> renderTypeExpression (pgtype @(BaseType ty))
276277instance {-# OVERLAPPING #-} PGTyped (BaseType ty1)
@@ -1099,22 +1100,22 @@ bigserial = UnsafeTypeExpression "bigserial"
10991100text :: TypeExpression ('Required ('Null 'PGtext))
11001101text = UnsafeTypeExpression "text"
11011102char
1102− :: KnownNat n
1103+ :: (KnownNat n, 1 <= n)
11031104 => proxy n
11041105 -> TypeExpression ('Required ('Null ('PGchar n)))
11051106char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
11061107character
1107− :: KnownNat n
1108+ :: (KnownNat n, 1 <= n)
11081109 => proxy n
11091110 -> TypeExpression ('Required ('Null ('PGchar n)))
11101111character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
11111112varchar
1112− :: KnownNat n
1113+ :: (KnownNat n, 1 <= n)
11131114 => proxy n
11141115 -> TypeExpression ('Required ('Null ('PGvarchar n)))
11151116varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
11161117characterVarying
1117− :: KnownNat n
1118+ :: (KnownNat n, 1 <= n)
11181119 => proxy n
11191120 -> TypeExpression ('Required ('Null ('PGvarchar n)))
11201121characterVarying p = UnsafeTypeExpression $
@@ -1161,8 +1162,10 @@ instance PGTyped 'PGnumeric where pgtype = numeric
11611162instance PGTyped 'PGfloat4 where pgtype = float4
11621163instance PGTyped 'PGfloat8 where pgtype = float8
11631164instance PGTyped 'PGtext where pgtype = text
1164−instance KnownNat n => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
1165−instance KnownNat n => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
1165+instance (KnownNat n, 1 <= n)
1166+ => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
1167+instance (KnownNat n, 1 <= n)
1168+ => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
11661169instance PGTyped 'PGbytea where pgtype = bytea
11671170instance PGTyped 'PGtimestamp where pgtype = timestamp
11681171instance PGTyped 'PGtimestamptz where pgtype = timestampWithTimeZone
squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+1−1
@@ -69,7 +69,7 @@ spec = do
6969 let
7070 statement :: Query Tables '[ 'Required ('NotNull 'PGbool)] Columns
7171 statement = selectStar
72− (from (Table (#table1 `As` #table1)) & where_ (param (Proxy @1)))
72+ (from (Table (#table1 `As` #table1)) & where_ (param @1))
7373 statement `queryRenders`
7474 "SELECT * FROM table1 AS table1 WHERE ($1 :: bool);"
7575 it "does OFFSET clauses" $ do