on dev help sign in
Merge pull request #25 from echatav/chain
7fe976dEitan Chatav
squeel-postgresql/exe/Example.hs+27−34
@@ -4,12 +4,12 @@
4 , OverloadedLabels
4 , OverloadedLabels
5 , OverloadedStrings
5 , OverloadedStrings
6 , ScopedTypeVariables
6 , ScopedTypeVariables
7+ , TypeApplications
7 , TypeOperators
8 , TypeOperators
8#-}
9#-}
9
10
10module Main (main) where
11module Main (main) where
11
12
12−import Control.Category ((>>>))
13import Control.Monad.Base
13import Control.Monad.Base
14import Control.Monad.Except
14import Control.Monad.Except
15import Control.Monad.Trans.Maybe
15import Control.Monad.Trans.Maybe
@@ -28,45 +28,38 @@ main = do
28 "host=localhost port=5432 dbname=exampledb"
28 "host=localhost port=5432 dbname=exampledb"
29 Char8.putStrLn $ "connecting to " <> connectionString
29 Char8.putStrLn $ "connecting to " <> connectionString
30 connection0 <- connectdb connectionString
30 connection0 <- connectdb connectionString
31− Char8.putStrLn "creating tables"
31+ Char8.putStrLn "setting up database"
32− connection1 <- flip execPQ connection0 $ pqExec $
32+ connection1 <- flip execPQ connection0 $
33− createTable #students
33+ pqExec ( createTable #students
34 ( (text & notNull) `As` #name
34 ( (text & notNull) `As` #name
35− :* Nil )
35+ :* Nil ) )
36− >>>
37− createTable #table1
36+ &>> createTable #table1
38 ( (int4 & notNull) `As` #col1
37 ( (int4 & notNull) `As` #col1
39 :* (int4 & notNull) `As` #col2
38 :* (int4 & notNull) `As` #col2
40 :* Nil )
39 :* Nil )
40+ &>> insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
41+ &>> insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
42+ Char8.putStrLn "querying"
41 connection2 <- flip execPQ connection1 $ do
43 connection2 <- flip execPQ connection1 $ do
42− _insertTable1Result <- pqExec $
43− insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
44− >>>
45− insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
46− Just selectTable1Result <- flip pqExecParams Nil $
47− (select $ starFrom #table1 :: Statement '[] Columns Tables Tables)
44+ Just result <- pqExecNil $ select $ starFrom #table1
48− Just (Right value00) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
45+ runMaybeT . runExceptT . flip runValue result $ do
49− getValue (RowNumber 0) colNum0
46+ value00 <- getValue (RowNumber 0) (columnNumber @0)
50− Just (Right value01) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
51− getValue (RowNumber 0) colNum1
47+ value01 <- getValue (RowNumber 0) (columnNumber @1)
52− Just (Right value10) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
53− getValue (RowNumber 1) colNum0
48+ value10 <- getValue (RowNumber 1) (columnNumber @0)
54− Just (Right value11) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
55− getValue (RowNumber 1) colNum1
49+ value11 <- getValue (RowNumber 1) (columnNumber @1)
56− Just (Right row0) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
57− getRow (RowNumber 0)
50+ row0 <- getRow (RowNumber 0)
58− Just (Right row1) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
59− getRow (RowNumber 1)
51+ row1 <- getRow (RowNumber 1)
60− liftBase $ do
52+ liftBase $ do
61− print (value00 :: Int32)
53+ print (value00 :: Int32)
62− print (value01 :: Int32)
54+ print (value01 :: Int32)
63− print (value10 :: Int32)
55+ print (value10 :: Int32)
64− print (value11 :: Int32)
56+ print (value11 :: Int32)
65− print (row0 :: NP I '[Int32,Int32])
57+ print (row0 :: NP I '[Int32,Int32])
66− print (row1 :: NP I '[Int32,Int32])
58+ print (row1 :: NP I '[Int32,Int32])
59+ Char8.putStrLn "tearing down database"
67− connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec $
60+ connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec
68 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
61 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
69− >>> dropTable #students
62+ &>> dropTable #students
70 finish connection3
63 finish connection3
71
64
72type Columns =
65type Columns =
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+26−21
@@ -73,7 +73,7 @@ class MonadPQ pq where
73 -> pq db0 db1 io (Maybe (Result '[]))
73 -> pq db0 db1 io (Maybe (Result '[]))
74
74
75 pqExecParams
75 pqExecParams
76− :: (MonadBase IO io, ToOids ps, AllZip HasEncoding ps xs, All Top ps)
76+ :: (MonadBase IO io, ToOids ps, AllZip HasEncoding ps xs)
77 => Statement ps ys db0 db1
77 => Statement ps ys db0 db1
78 -> NP I xs
78 -> NP I xs
79 -> pq db0 db1 io (Maybe (Result ys))
79 -> pq db0 db1 io (Maybe (Result ys))
@@ -82,14 +82,27 @@ class MonadPQ pq where
82 :: (MonadBase IO io, ToOids ps)
82 :: (MonadBase IO io, ToOids ps)
83 => ByteString
83 => ByteString
84 -> Statement ps xs db0 db1
84 -> Statement ps xs db0 db1
85− -> pq db0 db1 io (Maybe (Result []), PreparedStatement ps xs db0 db1)
85+ -> pq db0 db1 io (Maybe (Result '[]), PreparedStatement ps xs db0 db1)
86
86
87 pqExecPrepared
87 pqExecPrepared
88− :: (MonadBase IO io, AllZip HasEncoding ps xs, All Top ps)
88+ :: (MonadBase IO io, AllZip HasEncoding ps xs)
89 => PreparedStatement ps ys db0 db1
89 => PreparedStatement ps ys db0 db1
90 -> NP I xs
90 -> NP I xs
91 -> pq db0 db1 io (Maybe (Result ys))
91 -> pq db0 db1 io (Maybe (Result ys))
92
92
93+(&>>)
94+ :: (MonadPQ pq, MonadBase IO io)
95+ => pq db0 db1 io (Maybe (Result '[]))
96+ -> Statement '[] '[] db1 db2
97+ -> pq db0 db2 io (Maybe (Result '[]))
98+pq1 &>> statement2 = pqBind (\ _ -> pqExec statement2) pq1
99+
100+pqExecNil
101+ :: (MonadPQ pq, MonadBase IO io)
102+ => Statement '[] ys db0 db1
103+ -> pq db0 db1 io (Maybe (Result ys))
104+pqExecNil statement = pqExecParams statement Nil
105+
93instance MonadPQ PQ where
106instance MonadPQ PQ where
94
107
95 pqAp (PQ f) (PQ x) = PQ $ \ conn -> do
108 pqAp (PQ f) (PQ x) = PQ $ \ conn -> do
@@ -177,32 +190,24 @@ withConnection
177withConnection connString action =
190withConnection connString action =
178 bracket (connectdb connString) finish action
191 bracket (connectdb connString) finish action
179
192
193+newtype Result (xs :: [(Symbol,ColumnType)])
180−newtype Result xs = Result { unResult :: LibPQ.Result }
194+ = Result { unResult :: LibPQ.Result }
181
195
182newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
196newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
183
197
184−newtype ColumnNumber cs c = ColumnNumber { unColumnNumber :: LibPQ.Column }
198+newtype ColumnNumber n cs c =
199+ UnsafeColumnNumber { getColumnNumber :: LibPQ.Column }
185
200
186−class KnownNat n => HasColumnNumber (n :: Nat) columns column
201+class KnownNat n => HasColumnNumber n columns column
187 | n columns -> column where
202 | n columns -> column where
188− colNum :: Proxy# n -> ColumnNumber columns column
203+ columnNumber :: ColumnNumber n columns column
204+ columnNumber =
189− colNum p = ColumnNumber . fromIntegral $ natVal' p
205+ UnsafeColumnNumber . fromIntegral $ natVal' (proxy# :: Proxy# n)
190instance {-# OVERLAPPING #-} HasColumnNumber 0 (column1:columns) column1
206instance {-# OVERLAPPING #-} HasColumnNumber 0 (column1:columns) column1
191instance {-# OVERLAPPABLE #-}
207instance {-# OVERLAPPABLE #-}
192 (KnownNat n, HasColumnNumber (n-1) columns column)
208 (KnownNat n, HasColumnNumber (n-1) columns column)
193 => HasColumnNumber n (column' : columns) column
209 => HasColumnNumber n (column' : columns) column
194
210
195−colNum0 :: ColumnNumber (c0:cs) c0
196−colNum0 = colNum (proxy# :: Proxy# 0)
197−colNum1 :: ColumnNumber (c0:c1:cs) c1
198−colNum1 = colNum (proxy# :: Proxy# 1)
199−colNum2 :: ColumnNumber (c0:c1:c2:cs) c2
200−colNum2 = colNum (proxy# :: Proxy# 2)
201−colNum3 :: ColumnNumber (c0:c1:c2:c3:cs) c3
202−colNum3 = colNum (proxy# :: Proxy# 3)
203−colNum4 :: ColumnNumber (c0:c1:c2:c3:c4:cs) c4
204−colNum4 = colNum (proxy# :: Proxy# 4)
205−
206newtype Value pgs m x = Value { runValue :: Result pgs -> m x }
211newtype Value pgs m x = Value { runValue :: Result pgs -> m x }
207 deriving (Functor)
212 deriving (Functor)
208instance Applicative m => Applicative (Value pgs m) where
213instance Applicative m => Applicative (Value pgs m) where
@@ -221,9 +226,9 @@ instance MonadBase b m => MonadBase b (Value pgs m) where
221getValue
226getValue
222 :: (HasDecoding pg x, MonadBase IO io)
227 :: (HasDecoding pg x, MonadBase IO io)
223 => RowNumber
228 => RowNumber
224− -> ColumnNumber pgs pg
229+ -> ColumnNumber n pgs pg
225 -> Value pgs (ExceptT Text (MaybeT io)) x
230 -> Value pgs (ExceptT Text (MaybeT io)) x
226−getValue (RowNumber r) (ColumnNumber c :: ColumnNumber pgs pg) =
231+getValue (RowNumber r) (UnsafeColumnNumber c :: ColumnNumber n pgs pg) =
227 Value $ \ (Result result) -> do
232 Value $ \ (Result result) -> do
228 maybeBytestring <- liftBase $ LibPQ.getvalue result r c
233 maybeBytestring <- liftBase $ LibPQ.getvalue result r c
229 case maybeBytestring of
234 case maybeBytestring of
squeel-postgresql/src/Squeel/PostgreSQL/Schema.hs+8−7
@@ -17,7 +17,7 @@ module Squeel.PostgreSQL.Schema
17 ( PGType (..)
17 ( PGType (..)
18 , ToOid (..)
18 , ToOid (..)
19 , ToOids (..)
19 , ToOids (..)
20− , PGNum
20+ , PGNum (..)
21 , PGFractional
21 , PGFractional
22 , PGFloating
22 , PGFloating
23 , (:::)
23 , (:::)
@@ -82,12 +82,13 @@ instance (ToOid pg, ToOids pgs) => ToOids (pg ': pgs) where
82 toOids _ = toOid (proxy# :: Proxy# pg) : toOids (proxy# :: Proxy# pgs)
82 toOids _ = toOid (proxy# :: Proxy# pg) : toOids (proxy# :: Proxy# pgs)
83
83
84class PGNum (ty :: PGType) where
84class PGNum (ty :: PGType) where
85+ decimal :: proxy ty -> Bool
85−instance PGNum 'PGInt2
86+instance PGNum 'PGInt2 where decimal _ = False
86−instance PGNum 'PGInt4
87+instance PGNum 'PGInt4 where decimal _ = False
87−instance PGNum 'PGInt8
88+instance PGNum 'PGInt8 where decimal _ = False
88−instance PGNum 'PGNumeric
89+instance PGNum 'PGNumeric where decimal _ = True
89−instance PGNum 'PGFloat4
90+instance PGNum 'PGFloat4 where decimal _ = True
90−instance PGNum 'PGFloat8
91+instance PGNum 'PGFloat8 where decimal _ = True
91
92
92class PGNum ty => PGFractional (ty :: PGType) where
93class PGNum ty => PGFractional (ty :: PGType) where
93instance PGFractional 'PGNumeric
94instance PGFractional 'PGNumeric
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+41−26
@@ -8,6 +8,7 @@
8 , MagicHash
8 , MagicHash
9 , OverloadedStrings
9 , OverloadedStrings
10 , ScopedTypeVariables
10 , ScopedTypeVariables
11+ , TypeApplications
11 , TypeFamilies
12 , TypeFamilies
12 , TypeOperators
13 , TypeOperators
13 , UndecidableInstances
14 , UndecidableInstances
@@ -15,7 +16,6 @@
15
16
16module Squeel.PostgreSQL.Statement where
17module Squeel.PostgreSQL.Statement where
17
18
18−import Control.Category
19import Data.Boolean
19import Data.Boolean
20import Data.Boolean.Numbers
20import Data.Boolean.Numbers
21import Data.ByteString (ByteString)
21import Data.ByteString (ByteString)
@@ -27,7 +27,7 @@ import Generics.SOP
27import GHC.Exts
27import GHC.Exts
28import GHC.OverloadedLabels
28import GHC.OverloadedLabels
29import GHC.TypeLits
29import GHC.TypeLits
30−import Prelude hiding (id,(.),RealFrac(..))
30+import Prelude hiding (RealFrac(..))
31
31
32import qualified Data.ByteString as ByteString
32import qualified Data.ByteString as ByteString
33
33
@@ -134,7 +134,11 @@ instance PGNum ty
134 (*) = unsafeBinaryOp "*"
134 (*) = unsafeBinaryOp "*"
135 abs = unsafeFunction "abs"
135 abs = unsafeFunction "abs"
136 signum = unsafeFunction "sign"
136 signum = unsafeFunction "sign"
137+ fromInteger
137− fromInteger = UnsafeExpression . (<> ".") . fromString . show
138+ = UnsafeExpression
139+ . (<> if decimal (Proxy :: Proxy ty) then "." else "")
140+ . fromString
141+ . show
138
142
139instance PGFractional ty
143instance PGFractional ty
140 => Fractional (Expression params tables ('Required (nullity ty))) where
144 => Fractional (Expression params tables ('Required (nullity ty))) where
@@ -334,11 +338,6 @@ newtype Statement
334 = UnsafeStatement { renderStatement :: ByteString }
338 = UnsafeStatement { renderStatement :: ByteString }
335 deriving (Show,Eq)
339 deriving (Show,Eq)
336
340
337−instance Category (Statement '[] '[]) where
338− id = UnsafeStatement ";"
339− statement2 . statement1 = UnsafeStatement $
340− renderStatement statement1 <> " " <> renderStatement statement2
341−
342newtype PreparedStatement
341newtype PreparedStatement
343 (params :: [ColumnType])
342 (params :: [ColumnType])
344 (columns :: [(Symbol,ColumnType)])
343 (columns :: [(Symbol,ColumnType)])
@@ -615,53 +614,53 @@ serial8 :: TypeExpression ('Optional ('NotNull 'PGInt8))
615serial8 = UnsafeTypeExpression "serial8"
614serial8 = UnsafeTypeExpression "serial8"
616bigserial :: TypeExpression ('Optional ('NotNull 'PGInt8))
615bigserial :: TypeExpression ('Optional ('NotNull 'PGInt8))
617bigserial = UnsafeTypeExpression "bigserial"
616bigserial = UnsafeTypeExpression "bigserial"
618−money :: TypeExpression ('Optional ('NotNull 'PGMoney))
617+money :: TypeExpression ('Required ('Null 'PGMoney))
619money = UnsafeTypeExpression "money"
618money = UnsafeTypeExpression "money"
620text :: TypeExpression ('Required ('Null 'PGText))
619text :: TypeExpression ('Required ('Null 'PGText))
621text = UnsafeTypeExpression "text"
620text = UnsafeTypeExpression "text"
622char
621char
623 :: KnownNat n
622 :: KnownNat n
624 => proxy n
623 => proxy n
625− -> TypeExpression ('Optional ('NotNull ('PGChar n)))
624+ -> TypeExpression ('Required ('Null ('PGChar n)))
626char (_ :: proxy n) = UnsafeTypeExpression $
625char (_ :: proxy n) = UnsafeTypeExpression $
627 "char(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
626 "char(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
628character
627character
629 :: KnownNat n
628 :: KnownNat n
630 => proxy n
629 => proxy n
631− -> TypeExpression ('Optional ('NotNull ('PGChar n)))
630+ -> TypeExpression ('Required ('Null ('PGChar n)))
632character (_ :: proxy n) = UnsafeTypeExpression $
631character (_ :: proxy n) = UnsafeTypeExpression $
633 "character(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
632 "character(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
634varchar
633varchar
635 :: KnownNat n
634 :: KnownNat n
636 => proxy n
635 => proxy n
637− -> TypeExpression ('Optional ('NotNull ('PGVarChar n)))
636+ -> TypeExpression ('Required ('Null ('PGVarChar n)))
638varchar (_ :: proxy n) = UnsafeTypeExpression $
637varchar (_ :: proxy n) = UnsafeTypeExpression $
639 "varchar(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
638 "varchar(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
640characterVarying
639characterVarying
641 :: KnownNat n
640 :: KnownNat n
642 => proxy n
641 => proxy n
643− -> TypeExpression ('Optional ('NotNull ('PGVarChar n)))
642+ -> TypeExpression ('Required ('Null ('PGVarChar n)))
644characterVarying (_ :: proxy n) = UnsafeTypeExpression $
643characterVarying (_ :: proxy n) = UnsafeTypeExpression $
645 "character varying(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
644 "character varying(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
646−bytea :: TypeExpression ('Optional ('NotNull ('PGBytea)))
645+bytea :: TypeExpression ('Required ('Null ('PGBytea)))
647bytea = UnsafeTypeExpression "bytea"
646bytea = UnsafeTypeExpression "bytea"
648−timestamp :: TypeExpression ('Optional ('NotNull ('PGTimestamp)))
647+timestamp :: TypeExpression ('Required ('Null ('PGTimestamp)))
649timestamp = UnsafeTypeExpression "timestamp"
648timestamp = UnsafeTypeExpression "timestamp"
650−timestampWithTimeZone :: TypeExpression ('Optional ('NotNull ('PGTimestampTZ)))
649+timestampWithTimeZone :: TypeExpression ('Required ('Null ('PGTimestampTZ)))
651timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
650timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
652−date :: TypeExpression ('Optional ('NotNull ('PGDate)))
651+date :: TypeExpression ('Required ('Null ('PGDate)))
653date = UnsafeTypeExpression "date"
652date = UnsafeTypeExpression "date"
654−time :: TypeExpression ('Optional ('NotNull ('PGTime)))
653+time :: TypeExpression ('Required ('Null ('PGTime)))
655time = UnsafeTypeExpression "time"
654time = UnsafeTypeExpression "time"
656−timeWithTimeZone :: TypeExpression ('Optional ('NotNull ('PGTimeTZ)))
655+timeWithTimeZone :: TypeExpression ('Required ('Null ('PGTimeTZ)))
657timeWithTimeZone = UnsafeTypeExpression "time with time zone"
656timeWithTimeZone = UnsafeTypeExpression "time with time zone"
658−interval :: TypeExpression ('Optional ('NotNull ('PGInterval)))
657+interval :: TypeExpression ('Required ('Null ('PGInterval)))
659interval = UnsafeTypeExpression "interval"
658interval = UnsafeTypeExpression "interval"
660−uuid :: TypeExpression ('Optional ('NotNull ('PGUuid)))
659+uuid :: TypeExpression ('Required ('Null ('PGUuid)))
661uuid = UnsafeTypeExpression "uuid"
660uuid = UnsafeTypeExpression "uuid"
662−json :: TypeExpression ('Optional ('NotNull ('PGJson)))
661+json :: TypeExpression ('Required ('Null ('PGJson)))
663json = UnsafeTypeExpression "json"
662json = UnsafeTypeExpression "json"
664−jsonb :: TypeExpression ('Optional ('NotNull ('PGJsonb)))
663+jsonb :: TypeExpression ('Required ('Null ('PGJsonb)))
665jsonb = UnsafeTypeExpression "jsonb"
664jsonb = UnsafeTypeExpression "jsonb"
666
665
667notNull
666notNull
@@ -677,11 +676,27 @@ default_ x ty = UnsafeTypeExpression $
677
676
678class PGTyped (ty :: PGType) where
677class PGTyped (ty :: PGType) where
679 pgtype :: TypeExpression ('Required ('Null ty))
678 pgtype :: TypeExpression ('Required ('Null ty))
679+instance PGTyped 'PGBool where pgtype = bool
680instance PGTyped 'PGInt2 where pgtype = int2
680instance PGTyped 'PGInt2 where pgtype = int2
681instance PGTyped 'PGInt4 where pgtype = int4
681instance PGTyped 'PGInt4 where pgtype = int4
682instance PGTyped 'PGInt8 where pgtype = int8
682instance PGTyped 'PGInt8 where pgtype = int8
683−instance PGTyped 'PGBool where pgtype = bool
683+instance PGTyped 'PGNumeric where pgtype = numeric
684+instance PGTyped 'PGFloat4 where pgtype = float4
685+instance PGTyped 'PGFloat8 where pgtype = float8
686+instance PGTyped 'PGMoney where pgtype = money
684instance PGTyped 'PGText where pgtype = text
687instance PGTyped 'PGText where pgtype = text
688+instance KnownNat n => PGTyped ('PGChar n) where pgtype = char (Proxy @n)
689+instance KnownNat n => PGTyped ('PGVarChar n) where pgtype = varchar (Proxy @n)
690+instance PGTyped 'PGBytea where pgtype = bytea
691+instance PGTyped 'PGTimestamp where pgtype = timestamp
692+instance PGTyped 'PGTimestampTZ where pgtype = timestampWithTimeZone
693+instance PGTyped 'PGDate where pgtype = date
694+instance PGTyped 'PGTime where pgtype = time
695+instance PGTyped 'PGTimeTZ where pgtype = timeWithTimeZone
696+instance PGTyped 'PGInterval where pgtype = interval
697+instance PGTyped 'PGUuid where pgtype = uuid
698+instance PGTyped 'PGJson where pgtype = json
699+instance PGTyped 'PGJsonb where pgtype = jsonb
685
700
686createTable
701createTable
687 :: (KnownSymbol table, SListI columns)
702 :: (KnownSymbol table, SListI columns)
@@ -711,8 +726,8 @@ class KnownSymbol table => DropTable table schema0 schema1
711 dropTable (Alias table) = UnsafeStatement $
726 dropTable (Alias table) = UnsafeStatement $
712 "DROP TABLE " <> fromString (symbolVal' table) <> ";"
727 "DROP TABLE " <> fromString (symbolVal' table) <> ";"
713instance {-# OVERLAPPING #-}
728instance {-# OVERLAPPING #-}
714− (KnownSymbol table, table ~ table')
729+ (KnownSymbol table, table ~ table', schema ~ schema')
715− => DropTable table ((table' ::: columns) ': schema) schema
730+ => DropTable table ((table' ::: columns) ': schema) schema'
716instance {-# OVERLAPPABLE #-}
731instance {-# OVERLAPPABLE #-}
717 DropTable table schema0 schema1
732 DropTable table schema0 schema1
718 => DropTable table (table' ': schema0) (table' ': schema1)
733 => DropTable table (table' ': schema0) (table' ': schema1)
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+6−6
@@ -47,13 +47,13 @@ spec = do
47 let
47 let
48 statement :: Statement '[] Columns Tables Tables
48 statement :: Statement '[] Columns Tables Tables
49 statement = select $ starFrom (#table1 & limit 1)
49 statement = select $ starFrom (#table1 & limit 1)
50− statement `shouldRenderAs` "SELECT * FROM table1 AS table1 LIMIT 1.;"
50+ statement `shouldRenderAs` "SELECT * FROM table1 AS table1 LIMIT 1;"
51 it "should use the minimum of given LIMITs" $ do
51 it "should use the minimum of given LIMITs" $ do
52 let
52 let
53 statement :: Statement '[] Columns Tables Tables
53 statement :: Statement '[] Columns Tables Tables
54 statement = select $ starFrom (#table1 & limit 1 & limit 2)
54 statement = select $ starFrom (#table1 & limit 1 & limit 2)
55 statement `shouldRenderAs`
55 statement `shouldRenderAs`
56− "SELECT * FROM table1 AS table1 LIMIT CASE WHEN (1. <= 2.) THEN 1. ELSE 2. END;"
56+ "SELECT * FROM table1 AS table1 LIMIT CASE WHEN (1 <= 2) THEN 1 ELSE 2 END;"
57 it "should render parameters using $ signs" $ do
57 it "should render parameters using $ signs" $ do
58 let
58 let
59 statement :: Statement '[ 'Required ('NotNull 'PGInt8)] Columns Tables Tables
59 statement :: Statement '[ 'Required ('NotNull 'PGInt8)] Columns Tables Tables
@@ -63,18 +63,18 @@ spec = do
63 let
63 let
64 statement :: Statement '[] Columns Tables Tables
64 statement :: Statement '[] Columns Tables Tables
65 statement = select $ starFrom (#table1 & offset 1)
65 statement = select $ starFrom (#table1 & offset 1)
66− statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET 1.;"
66+ statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET 1;"
67 it "should use the sum of given OFFSETs" $ do
67 it "should use the sum of given OFFSETs" $ do
68 let
68 let
69 statement :: Statement '[] Columns Tables Tables
69 statement :: Statement '[] Columns Tables Tables
70 statement = select $ starFrom (#table1 & offset 1 & offset 2)
70 statement = select $ starFrom (#table1 & offset 1 & offset 2)
71− statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET (1. + 2.);"
71+ statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET (1 + 2);"
72 it "correctly render simple INSERTs" $ do
72 it "correctly render simple INSERTs" $ do
73 let
73 let
74 statement :: Statement '[] '[] Tables Tables
74 statement :: Statement '[] '[] Tables Tables
75 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
75 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
76 statement `shouldRenderAs`
76 statement `shouldRenderAs`
77− "INSERT INTO table1 (col1, col2) VALUES (2., 4.);"
77+ "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
78 it "should be safe against SQL injection in literal text" $ do
78 it "should be safe against SQL injection in literal text" $ do
79 let
79 let
80 statement :: Statement '[] '[] StudentsTable StudentsTable
80 statement :: Statement '[] '[] StudentsTable StudentsTable
@@ -145,7 +145,7 @@ spec = do
145 :* (int8 & notNull & default_ 8) `As` #col3
145 :* (int8 & notNull & default_ 8) `As` #col3
146 :* Nil)
146 :* Nil)
147 `shouldRenderAs`
147 `shouldRenderAs`
148− "CREATE TABLE table2 (col1 serial, col2 text, col3 int8 NOT NULL DEFAULT 8.);"
148+ "CREATE TABLE table2 (col1 serial, col2 text, col3 int8 NOT NULL DEFAULT 8);"
149 it "should render DROP TABLE statements" $ do
149 it "should render DROP TABLE statements" $ do
150 let
150 let
151 statement :: Statement '[] '[] Tables '[]
151 statement :: Statement '[] '[] Tables '[]