on dev help sign in
updates, fix binary issue
commit8571e213a3fa12bcfba5be539d0131d355006441 authorEitan Chatav <eitan.chatav@gmail.com> dateMon 26 Jun 2017, 13:34 (9 years ago) parent1cdb88a
6 files changed+38−55
squeel-postgresql/exe/Example.hs+15−22 squeel-postgresql/src/Squeel/PostgreSQL/Binary.hs+10−12 squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+3−5 squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+4−4 squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+5−5 stack.yaml+1−7
squeel-postgresql/exe/Example.hs+15−22
@@ -27,20 +27,13 @@ main = do
2727 Char8.putStrLn "creating tables"
2828 connection1 <- flip execPQ connection0 $ pqExec $
2929 createTable #table1 (proxy# :: Proxy# Columns)
30− .>>.
31− createTable #students (proxy# :: Proxy# StudentsColumns)
32− .>>.
33− createTable #shippers (proxy# :: Proxy# ShipperColumns)
34− .>>.
35− createTable #customers (proxy# :: Proxy# CustomerColumns)
36− .>>.
37− createTable #orders (proxy# :: Proxy# OrderColumns)
3830 connection2 <- flip execPQ connection1 $ do
3931 _insertTable1Result <- pqExec $
4032 insertInto #table1 ( 1 `As` #col1 :& 2 `As` #col2 :& RNil )
41− .>>.
33+ &>>
4234 insertInto #table1 ( 3 `As` #col1 :& 4 `As` #col2 :& RNil )
43− Just selectTable1Result <- pqExec $ select $ starFrom #table1
35+ Just selectTable1Result <- flip pqExecParams RNil $
36+ (select $ starFrom #table1 :: Statement '[] Tables Tables Columns)
4437 Just (Right value00) <- getvalue selectTable1Result (RowNumber 0) colNum0
4538 Just (Right value01) <- getvalue selectTable1Result (RowNumber 0) colNum1
4639 Just (Right value10) <- getvalue selectTable1Result (RowNumber 1) colNum0
@@ -53,20 +46,20 @@ main = do
5346 finish connection2
5447
5548type Columns = '[ "col1" ::: 'NotNull 'PGInt4, "col2" ::: 'NotNull 'PGInt4]
56−-- type Tables = '[ "table1" ::: Columns ]
49+type Tables = '[ "table1" ::: Columns ]
5750-- type SumAndCol1 = '[ "sum" ::: 'NotNull 'PGInt4, "col1" ::: 'NotNull 'PGInt4]
58−type StudentsColumns = '["name" ::: 'NotNull 'PGText]
51+-- type StudentsColumns = '["name" ::: 'NotNull 'PGText]
5952-- type StudentsTable = '["students" ::: StudentsColumns]
60−type OrderColumns =
61− [ "orderID" ::: 'NotNull 'PGInt4
62− , "orderVal" ::: 'NotNull 'PGText
63− , "customerID" ::: 'NotNull 'PGInt4
64− , "shipperID" ::: 'NotNull 'PGInt4
65− ]
66−type CustomerColumns =
67− [ "customerID" ::: 'NotNull 'PGInt4, "customerVal" ::: 'NotNull 'PGFloat4 ]
68−type ShipperColumns =
69− [ "shipperID" ::: 'NotNull 'PGInt4, "shipperVal" ::: 'NotNull 'PGBool ]
53+-- type OrderColumns =
54+-- [ "orderID" ::: 'NotNull 'PGInt4
55+-- , "orderVal" ::: 'NotNull 'PGText
56+-- , "customerID" ::: 'NotNull 'PGInt4
57+-- , "shipperID" ::: 'NotNull 'PGInt4
58+-- ]
59+-- type CustomerColumns =
60+-- [ "customerID" ::: 'NotNull 'PGInt4, "customerVal" ::: 'NotNull 'PGFloat4 ]
61+-- type ShipperColumns =
62+-- [ "shipperID" ::: 'NotNull 'PGInt4, "shipperVal" ::: 'NotNull 'PGBool ]
7063-- type JoinTables =
7164-- [ "shippers" ::: ShipperColumns
7265-- , "customers" ::: CustomerColumns
squeel-postgresql/src/Squeel/PostgreSQL/Binary.hs+10−12
@@ -11,16 +11,14 @@
1111
1212module Squeel.PostgreSQL.Binary where
1313
14−import Debug.Trace
15−
1614import Control.Arrow (left)
1715import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
1816import Data.ByteString (ByteString)
1917import Data.Int (Int16,Int32,Int64)
2018import Data.Vinyl
2119import Data.Vinyl.Functor
22−import PostgreSQL.Binary.Decoder (Decoder)
23−import PostgreSQL.Binary.Encoder (Encoder)
20+import PostgreSQL.Binary.Decoding (Value)
21+import PostgreSQL.Binary.Encoding (Encoding)
2422import Data.Scientific (Scientific)
2523import Data.Text (Text)
2624import Data.Time (Day, TimeOfDay, TimeZone, LocalTime, UTCTime, DiffTime)
@@ -30,20 +28,20 @@ import GHC.Exts
3028import qualified Data.ByteString.Lazy as Lazy (ByteString, toStrict)
3129import qualified Data.Text as Text (pack)
3230import qualified Data.Text.Lazy as Lazy (Text)
33−import qualified PostgreSQL.Binary.Decoder as Decoder
34−import qualified PostgreSQL.Binary.Encoder as Encoder
31+import qualified PostgreSQL.Binary.Decoding as Decoder
32+import qualified PostgreSQL.Binary.Encoding as Encoder
3533
3634import Squeel.PostgreSQL.Schema
3735
3836decodeValue :: FromValue pg x => Proxy# pg -> ByteString -> Either Text x
39−decodeValue p = Decoder.run $ fromValue p
37+decodeValue p = Decoder.valueParser $ fromValue p
4038
4139class FromValue pg x where
42− fromValue :: Proxy# pg -> Decoder x
40+ fromValue :: Proxy# pg -> Value x
4341instance FromValue 'PGInt2 Int16 where
4442 fromValue _ = Decoder.int
4543instance FromValue 'PGInt4 Int32 where
46− fromValue _ = trace "Decoder.int" Decoder.int
44+ fromValue _ = Decoder.int
4745instance FromValue 'PGInt8 Int64 where
4846 fromValue _ = Decoder.int
4947instance FromValue 'PGFloat4 Float where
@@ -95,7 +93,7 @@ instance (FromValue pg x, FromValues pgs xs)
9593 :& decodeValues (proxy# :: Proxy# pgs) results
9694
9795class ToValue x pg where
98− toValue :: Proxy# pg -> Encoder x
96+ toValue :: Proxy# pg -> x -> Encoding
9997instance ToValue Int16 'PGInt2 where
10098 toValue _ = Encoder.int2_int16
10199instance ToValue Int32 'PGInt4 where
@@ -117,7 +115,7 @@ instance ToValue Text 'PGText where
117115instance ToValue Lazy.Text 'PGText where
118116 toValue _ = Encoder.text_lazy
119117instance ToValue Char ('PGChar 1) where
120− toValue _ = Encoder.char
118+ toValue _ = Encoder.char_utf8
121119instance ToValue Scientific 'PGNumeric where
122120 toValue _ = Encoder.numeric
123121instance ToValue UUID 'PGUuid where
@@ -145,5 +143,5 @@ instance ToValues '[] '[] where toValues _ _ = []
145143instance (ToValue x pg, ToValues xs pgs)
146144 => ToValues (x ': xs) (pg ': pgs) where
147145 toValues _ (Identity x :& xs)
148− = Encoder.run (toValue (proxy# :: Proxy# pg)) x
146+ = Encoder.encodingBytes ((toValue (proxy# :: Proxy# pg)) x)
149147 : toValues (proxy# :: Proxy# pgs) xs
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+3−5
@@ -17,8 +17,6 @@
1717
1818module Squeel.PostgreSQL.PQ where
1919
20−import Debug.Trace
21−
2220import Control.Exception.Lifted
2321import Control.Monad.Base
2422import Control.Monad.Trans
@@ -68,8 +66,8 @@ class MonadPQ pq where
6866
6967 pqExec
7068 :: MonadBase IO io
71− => Statement '[] db0 db1 xs
72− -> pq db0 db1 io (Maybe (Result xs))
69+ => Statement '[] db0 db1 '[]
70+ -> pq db0 db1 io (Maybe (Result '[]))
7371
7472 pqExecParams
7573 :: (MonadBase IO io, ToOids ps, ToValues xs ps)
@@ -213,4 +211,4 @@ getvalue
213211 -> io (Maybe (Either Text y))
214212getvalue (Result result) (RowNumber r) (ColumnNumber c :: ColumnNumber xs x) =
215213 liftBase $ fmap (fmap (decodeValue (proxy# :: Proxy# x)))
216− (traceShowId <$> LibPQ.getvalue' result r c)
214+ (LibPQ.getvalue' result r c)
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+4−4
@@ -66,10 +66,10 @@ instance (HasColumn column columns ty, tables ~ '[table ::: columns])
6666 => IsLabel column (Expression params tables ty) where
6767 fromLabel = getColumn
6868
69−(.&.)
69+(&.)
7070 :: (HasTable table tables columns, HasColumn column columns ty)
7171 => Alias table -> Alias column -> Expression params tables ty
72−Alias table .&. Alias column = UnsafeExpression $
72+Alias table &. Alias column = UnsafeExpression $
7373 fromString (symbolVal' table)
7474 <> "." <>
7575 fromString (symbolVal' column)
@@ -377,11 +377,11 @@ newtype Statement
377377 (columns :: [(Symbol,NullityType)])
378378 = UnsafeStatement { renderStatement :: ByteString }
379379
380−(.>>.)
380+(&>>)
381381 :: Statement '[] schema0 schema1 '[]
382382 -> Statement '[] schema1 schema2 results
383383 -> Statement '[] schema0 schema2 results
384−statement1 .>>. statement2 = UnsafeStatement $
384+statement1 &>> statement2 = UnsafeStatement $
385385 renderStatement statement1 <> " " <> renderStatement statement2
386386
387387newtype PreparedStatement
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+5−5
@@ -86,9 +86,9 @@ spec = do
8686 describe "JOINs" $ do
8787 let
8888 vals =
89− #orders .&. #orderVal `As` #orderVal
90− :& #customers .&. #customerVal `As` #customerVal
91− :& #shippers .&. #shipperVal `As` #shipperVal :& RNil
89+ #orders &. #orderVal `As` #orderVal
90+ :& #customers &. #customerVal `As` #customerVal
91+ :& #shippers &. #shipperVal `As` #shipperVal :& RNil
9292 it "should render CROSS JOINs" $ do
9393 let
9494 statement :: Statement '[] JoinTables JoinTables ValueColumns
@@ -108,9 +108,9 @@ spec = do
108108 innerJoins = join $
109109 #orders
110110 & Inner #customers
111− (#orders .&. #customerID ==* #customers .&. #customerID)
111+ (#orders &. #customerID ==* #customers &. #customerID)
112112 & Inner #shippers
113− (#orders .&. #shipperID ==* #shippers .&. #shipperID)
113+ (#orders &. #shipperID ==* #shippers &. #shipperID)
114114 selection :: Statement '[] JoinTables JoinTables ValueColumns
115115 selection = select $ vals `from` innerJoins
116116 selection `shouldRenderAs`
stack.yaml+1−7
@@ -1,9 +1,3 @@
1−resolver: nightly-2016-12-31
1+resolver: nightly-2017-06-26
22packages:
33- squeel-postgresql
4−extra-deps:
5−- bifunctors-5.3
6−- indexed-0.1.3
7−- indexed-extras-0.2
8−flags: {}
9−extra-package-dbs: []