on dev help sign in
execParams & prepare
commit8424e0cba0a17ac118890e9f6a18821e4a9fbe61 authorEitan Chatav <eitan.chatav@gmail.com> dateThu 16 Mar 2017, 09:22 (10 years ago) parent97f7108
3 files changed+50−25
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+19 squeel-postgresql/src/Squeel/PostgreSQL/Query.hs+2 squeel-postgresql/src/Squeel/PostgreSQL/Value.hs+29−25
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+19
@@ -40,6 +40,25 @@ newtype Result xs = Result { unResult :: LibPQ.Result }
4040exec :: MonadIO io => Query db0 db1 '[] xs -> PQ io db0 db1 (Result xs)
4141exec = undefined
4242
43+type family To xs y where
44+ To '[] y = y
45+ To (x ': xs) y = To x (To xs y)
46+
47+execParams
48+ :: (MonadIO io, ToParameters xs ps)
49+ => Connection db0
50+ -> Query db0 db1 ps ys
51+ -> xs `To` PQ io db0 db1 (Result ys)
52+execParams = undefined
53+
54+prepare
55+ :: MonadIO io
56+ => Connection db0
57+ -> ByteString
58+ -> Query db0 db1 ps xs
59+ -> io (PreparedQuery db0 db1 ps xs)
60+prepare = undefined
61+
4362newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
4463
4564newtype ColumnNumber cs c = ColumnNumber { unColumnNumber :: LibPQ.Column }
squeel-postgresql/src/Squeel/PostgreSQL/Query.hs+2
@@ -7,3 +7,5 @@ module Squeel.PostgreSQL.Query where
77import Data.ByteString (ByteString)
88
99newtype Query db0 db1 ps xs = Query { unQuery :: ByteString }
10+newtype PreparedQuery db0 db1 ps xs
11+ = PreparedQuery { unPreparedQuery :: ByteString }
squeel-postgresql/src/Squeel/PostgreSQL/Value.hs+29−25
@@ -72,53 +72,57 @@ instance FromValue ('PGType "timestamptz") UTCTime where
7272instance FromValue ('PGType "interval") DiffTime where
7373 fromValue _ = Decoder.interval_int
7474
75−class ToValue (pg :: PGType) x where
75+class ToValue x (pg :: PGType) where
7676 toValue :: Proxy pg -> Encoder x
77−instance ToValue ('PGType "int2") Int16 where
77+instance ToValue Int16 ('PGType "int2") where
7878 toValue _ = Encoder.int2_int16
79−instance ToValue ('PGType "int4") Int32 where
79+instance ToValue Int32 ('PGType "int4") where
8080 toValue _ = Encoder.int4_int32
81−instance ToValue ('PGType "int8") Int64 where
81+instance ToValue Int64 ('PGType "int8") where
8282 toValue _ = Encoder.int8_int64
83−instance ToValue ('PGType "word2") Word16 where
83+instance ToValue Word16 ('PGType "word2") where
8484 toValue _ = Encoder.int2_word16
85−instance ToValue ('PGType "word4") Word32 where
85+instance ToValue Word32 ('PGType "word4") where
8686 toValue _ = Encoder.int4_word32
87−instance ToValue ('PGType "word8") Word64 where
87+instance ToValue Word64 ('PGType "word8") where
8888 toValue _ = Encoder.int8_word64
89−instance ToValue ('PGType "float4") Float where
89+instance ToValue Float ('PGType "float4") where
9090 toValue _ = Encoder.float4
91−instance ToValue ('PGType "float8") Double where
91+instance ToValue Double ('PGType "float8") where
9292 toValue _ = Encoder.float8
93−instance ToValue ('PGType "bool") Bool where
93+instance ToValue Bool ('PGType "bool") where
9494 toValue _ = Encoder.bool
95−instance ToValue ('PGType "bytea") ByteString where
95+instance ToValue ByteString ('PGType "bytea") where
9696 toValue _ = Encoder.bytea_strict
97−instance ToValue ('PGType "bytea") Lazy.ByteString where
97+instance ToValue Lazy.ByteString ('PGType "bytea") where
9898 toValue _ = Encoder.bytea_lazy
99−instance ToValue ('PGType "text") Text where
99+instance ToValue Text ('PGType "text") where
100100 toValue _ = Encoder.text_strict
101−instance ToValue ('PGType "text") Lazy.Text where
101+instance ToValue Lazy.Text ('PGType "text") where
102102 toValue _ = Encoder.text_lazy
103−instance ToValue ('PGType "char") Char where
103+instance ToValue Char ('PGType "char") where
104104 toValue _ = Encoder.char
105−instance ToValue ('PGType "numeric") Scientific where
105+instance ToValue Scientific ('PGType "numeric") where
106106 toValue _ = Encoder.numeric
107−instance ToValue ('PGType "uuid") UUID where
107+instance ToValue UUID ('PGType "uuid") where
108108 toValue _ = Encoder.uuid
109−instance ToJSON x => ToValue ('PGType "json") x where
109+instance ToJSON x => ToValue x ('PGType "json") where
110110 toValue _ = Encoder.json_bytes . Lazy.toStrict . encode
111−instance ToJSON x => ToValue ('PGType "jsonb") x where
111+instance ToJSON x => ToValue x ('PGType "jsonb") where
112112 toValue _ = Encoder.jsonb_bytes . Lazy.toStrict . encode
113−instance ToValue ('PGType "date") Day where
113+instance ToValue Day ('PGType "date") where
114114 toValue _ = Encoder.date
115−instance ToValue ('PGType "time") TimeOfDay where
115+instance ToValue TimeOfDay ('PGType "time") where
116116 toValue _ = Encoder.time_int
117−instance ToValue ('PGType "timetz") (TimeOfDay, TimeZone) where
117+instance ToValue (TimeOfDay, TimeZone) ('PGType "timetz") where
118118 toValue _ = Encoder.timetz_int
119−instance ToValue ('PGType "timestamp") LocalTime where
119+instance ToValue LocalTime ('PGType "timestamp") where
120120 toValue _ = Encoder.timestamp_int
121−instance ToValue ('PGType "timestamptz") UTCTime where
121+instance ToValue UTCTime ('PGType "timestamptz") where
122122 toValue _ = Encoder.timestamptz_int
123−instance ToValue ('PGType "interval") DiffTime where
123+instance ToValue DiffTime ('PGType "interval") where
124124 toValue _ = Encoder.interval_int
125+
126+type family ToParameters ps xs where
127+ ToParameters '[] '[] = ()
128+ ToParameters (x ': xs) (p ': ps) = (ToValue x p, ToParameters xs ps)