on master help sign in
Remove `out` from `TypeInformation`
0857ffbOllie Charles
src/Rel8/Expr/Serialize.hs+3−3
@@ -44,6 +44,6 @@ slitExpr nullability info@TypeInformation {encode} =
44
44
45
45
46sparseValue :: Nullability a -> TypeInformation (Unnullify a) -> Hasql.Row a
46sparseValue :: Nullability a -> TypeInformation (Unnullify a) -> Hasql.Row a
47−sparseValue nullability TypeInformation {decode, out} = case nullability of
47+sparseValue nullability TypeInformation {decode} = case nullability of
48− Nullable -> Hasql.column $ Hasql.nullable $ out <$> decode
48+ Nullable -> Hasql.column $ Hasql.nullable decode
49− NonNullable -> Hasql.column $ Hasql.nonNullable $ out <$> decode
49+ NonNullable -> Hasql.column $ Hasql.nonNullable decode
src/Rel8/Type.hs−17
@@ -102,7 +102,6 @@ instance DBType Bool where
102 { encode = Opaleye.ConstExpr . Opaleye.BoolLit
102 { encode = Opaleye.ConstExpr . Opaleye.BoolLit
103 , decode = Hasql.bool
103 , decode = Hasql.bool
104 , typeName = "bool"
104 , typeName = "bool"
105− , out = id
106 }
105 }
107
106
108
107
@@ -112,7 +111,6 @@ instance DBType Char where
112 { encode = Opaleye.ConstExpr . Opaleye.StringLit . pure
111 { encode = Opaleye.ConstExpr . Opaleye.StringLit . pure
113 , decode = Hasql.char
112 , decode = Hasql.char
114 , typeName = "char"
113 , typeName = "char"
115− , out = id
116 }
114 }
117
115
118
116
@@ -122,7 +120,6 @@ instance DBType Int16 where
122 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
120 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
123 , decode = Hasql.int2
121 , decode = Hasql.int2
124 , typeName = "int2"
122 , typeName = "int2"
125− , out = id
126 }
123 }
127
124
128
125
@@ -132,7 +129,6 @@ instance DBType Int32 where
132 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
129 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
133 , decode = Hasql.int4
130 , decode = Hasql.int4
134 , typeName = "int4"
131 , typeName = "int4"
135− , out = id
136 }
132 }
137
133
138
134
@@ -142,7 +138,6 @@ instance DBType Int64 where
142 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
138 { encode = Opaleye.ConstExpr . Opaleye.IntegerLit . toInteger
143 , decode = Hasql.int8
139 , decode = Hasql.int8
144 , typeName = "int8"
140 , typeName = "int8"
145− , out = id
146 }
141 }
147
142
148
143
@@ -152,7 +147,6 @@ instance DBType Float where
152 { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
147 { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
153 , decode = Hasql.float4
148 , decode = Hasql.float4
154 , typeName = "float4"
149 , typeName = "float4"
155− , out = id
156 }
150 }
157
151
158
152
@@ -162,7 +156,6 @@ instance DBType Double where
162 { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
156 { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
163 , decode = Hasql.float8
157 , decode = Hasql.float8
164 , typeName = "float8"
158 , typeName = "float8"
165− , out = id
166 }
159 }
167
160
168
161
@@ -172,7 +165,6 @@ instance DBType Scientific where
172 { encode = Opaleye.ConstExpr . Opaleye.NumericLit
165 { encode = Opaleye.ConstExpr . Opaleye.NumericLit
173 , decode = Hasql.numeric
166 , decode = Hasql.numeric
174 , typeName = "numeric"
167 , typeName = "numeric"
175− , out = id
176 }
168 }
177
169
178
170
@@ -184,7 +176,6 @@ instance DBType UTCTime where
184 formatTime defaultTimeLocale "'%FT%T%QZ'"
176 formatTime defaultTimeLocale "'%FT%T%QZ'"
185 , decode = Hasql.timestamptz
177 , decode = Hasql.timestamptz
186 , typeName = "timestamptz"
178 , typeName = "timestamptz"
187− , out = id
188 }
179 }
189
180
190
181
@@ -196,7 +187,6 @@ instance DBType Day where
196 formatTime defaultTimeLocale "'%F'"
187 formatTime defaultTimeLocale "'%F'"
197 , decode = Hasql.date
188 , decode = Hasql.date
198 , typeName = "date"
189 , typeName = "date"
199− , out = id
200 }
190 }
201
191
202
192
@@ -208,7 +198,6 @@ instance DBType LocalTime where
208 formatTime defaultTimeLocale "'%FT%T%Q'"
198 formatTime defaultTimeLocale "'%FT%T%Q'"
209 , decode = Hasql.timestamp
199 , decode = Hasql.timestamp
210 , typeName = "timestamp"
200 , typeName = "timestamp"
211− , out = id
212 }
201 }
213
202
214
203
@@ -220,7 +209,6 @@ instance DBType TimeOfDay where
220 formatTime defaultTimeLocale "'%T%Q'"
209 formatTime defaultTimeLocale "'%T%Q'"
221 , decode = Hasql.time
210 , decode = Hasql.time
222 , typeName = "time"
211 , typeName = "time"
223− , out = id
224 }
212 }
225
213
226
214
@@ -232,7 +220,6 @@ instance DBType CalendarDiffTime where
232 formatTime defaultTimeLocale "'%bmon %0Es'"
220 formatTime defaultTimeLocale "'%bmon %0Es'"
233 , decode = CalendarDiffTime 0 . realToFrac <$> Hasql.interval
221 , decode = CalendarDiffTime 0 . realToFrac <$> Hasql.interval
234 , typeName = "interval"
222 , typeName = "interval"
235− , out = id
236 }
223 }
237
224
238
225
@@ -242,7 +229,6 @@ instance DBType Text where
242 { encode = Opaleye.ConstExpr . Opaleye.StringLit . Text.unpack
229 { encode = Opaleye.ConstExpr . Opaleye.StringLit . Text.unpack
243 , decode = Hasql.text
230 , decode = Hasql.text
244 , typeName = "text"
231 , typeName = "text"
245− , out = id
246 }
232 }
247
233
248
234
@@ -272,7 +258,6 @@ instance DBType ByteString where
272 { encode = Opaleye.ConstExpr . Opaleye.ByteStringLit
258 { encode = Opaleye.ConstExpr . Opaleye.ByteStringLit
273 , decode = Hasql.bytea
259 , decode = Hasql.bytea
274 , typeName = "bytea"
260 , typeName = "bytea"
275− , out = id
276 }
261 }
277
262
278
263
@@ -289,7 +274,6 @@ instance DBType UUID where
289 { encode = Opaleye.ConstExpr . Opaleye.StringLit . UUID.toString
274 { encode = Opaleye.ConstExpr . Opaleye.StringLit . UUID.toString
290 , decode = Hasql.uuid
275 , decode = Hasql.uuid
291 , typeName = "uuid"
276 , typeName = "uuid"
292− , out = id
293 }
277 }
294
278
295
279
@@ -302,7 +286,6 @@ instance DBType Value where
302 Lazy.unpack . Lazy.decodeUtf8 . Aeson.encode
286 Lazy.unpack . Lazy.decodeUtf8 . Aeson.encode
303 , decode = Hasql.jsonb
287 , decode = Hasql.jsonb
304 , typeName = "jsonb"
288 , typeName = "jsonb"
305− , out = id
306 }
289 }
307
290
308
291
src/Rel8/Type/Array.hs+3−4
@@ -40,15 +40,14 @@ listTypeInformation :: ()
40 -> TypeInformation [a]
40 -> TypeInformation [a]
41listTypeInformation nullability info =
41listTypeInformation nullability info =
42 case info of
42 case info of
43− TypeInformation{ encode, decode, out } -> TypeInformation
43+ TypeInformation{ encode, decode } -> TypeInformation
44 { decode = row $ case nullability of
44 { decode = row $ case nullability of
45− Nullable -> Hasql.listArray (Hasql.nullable (out <$> decode))
45+ Nullable -> Hasql.listArray (Hasql.nullable decode)
46− NonNullable -> Hasql.listArray (Hasql.nonNullable (out <$> decode))
46+ NonNullable -> Hasql.listArray (Hasql.nonNullable decode)
47 , encode = case nullability of
47 , encode = case nullability of
48 Nullable -> array info . fmap (maybe null encode)
48 Nullable -> array info . fmap (maybe null encode)
49 NonNullable -> array info . fmap encode
49 NonNullable -> array info . fmap encode
50 , typeName = "record"
50 , typeName = "record"
51− , out = id
52 }
51 }
53 where
52 where
54 row = Hasql.composite . Hasql.field . Hasql.nonNullable
53 row = Hasql.composite . Hasql.field . Hasql.nonNullable
src/Rel8/Type/Array1D.hs+3−4
@@ -98,15 +98,14 @@ array1DTypeInformation :: IsArray1D (Unnullify a) ~ 'False
98 -> TypeInformation (Array1D a)
98 -> TypeInformation (Array1D a)
99array1DTypeInformation nullability info =
99array1DTypeInformation nullability info =
100 case info of
100 case info of
101− TypeInformation{ encode, decode, typeName, out } -> TypeInformation
101+ TypeInformation{ encode, decode, typeName } -> TypeInformation
102 { decode = case nullability of
102 { decode = case nullability of
103− Nullable -> Array1D <$> Hasql.listArray (Hasql.nullable (out <$> decode))
103+ Nullable -> Array1D <$> Hasql.listArray (Hasql.nullable decode)
104− NonNullable -> Array1D <$> Hasql.listArray (Hasql.nonNullable (out <$> decode))
104+ NonNullable -> Array1D <$> Hasql.listArray (Hasql.nonNullable decode)
105 , encode = case nullability of
105 , encode = case nullability of
106 Nullable -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
106 Nullable -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
107 NonNullable -> Opaleye.ArrayExpr . fmap encode . getArray1D
107 NonNullable -> Opaleye.ArrayExpr . fmap encode . getArray1D
108 , typeName = typeName <> "[]"
108 , typeName = typeName <> "[]"
109− , out = id
110 }
109 }
111 where
110 where
112 null = Opaleye.ConstExpr Opaleye.NullLit
111 null = Opaleye.ConstExpr Opaleye.NullLit
src/Rel8/Type/Information.hs+10−15
@@ -28,18 +28,14 @@ import qualified Data.Text as Text
28-- from database queries. The @typeName@ is the name of the type in the
28-- from database queries. The @typeName@ is the name of the type in the
29-- database, which is used to accurately type literals.
29-- database, which is used to accurately type literals.
30type TypeInformation :: Type -> Type
30type TypeInformation :: Type -> Type
31−data TypeInformation a where
31+data TypeInformation a = TypeInformation
32− TypeInformation ::
33− { encode :: a -> Opaleye.PrimExpr
32+ { encode :: a -> Opaleye.PrimExpr
34− -- ^ How to encode a single Haskell value as a SQL expression.
33+ -- ^ How to encode a single Haskell value as a SQL expression.
35− , decode :: Hasql.Value x
34+ , decode :: Hasql.Value a
36− -- ^ How to deserialize a single result back to Haskell.
35+ -- ^ How to deserialize a single result back to Haskell.
37− , typeName :: String
36+ , typeName :: String
38− -- ^ The name of the SQL type.
37+ -- ^ The name of the SQL type.
39− , out :: x -> a
38+ }
40− -- ^ A final output function - usually this will just be 'id'. This is
41− -- needed to allow @TypeInformation@s to be coerced.
42− } -> TypeInformation a
43
39
44
40
45-- | Simultaneously map over how a type is both encoded and decoded, while
41-- | Simultaneously map over how a type is both encoded and decoded, while
@@ -81,10 +77,9 @@ mapTypeInformation = parseTypeInformation . fmap pure
81parseTypeInformation :: ()
77parseTypeInformation :: ()
82 => (a -> Either String b) -> (b -> a)
78 => (a -> Either String b) -> (b -> a)
83 -> TypeInformation a -> TypeInformation b
79 -> TypeInformation a -> TypeInformation b
84−parseTypeInformation to from TypeInformation {encode, decode, typeName, out} =
80+parseTypeInformation to from TypeInformation {encode, decode, typeName} =
85 TypeInformation
81 TypeInformation
86 { encode = encode . from
82 { encode = encode . from
87− , decode = Hasql.refine (first Text.pack . to) (out <$> decode)
83+ , decode = Hasql.refine (first Text.pack . to) decode
88 , typeName
84 , typeName
89− , out = id
90 }
85 }
src/Rel8/Type/JSONBEncoded.hs−1
@@ -28,5 +28,4 @@ instance (FromJSON a, ToJSON a) => DBType (JSONBEncoded a) where
28 { encode = encode typeInformation . toJSON . fromJSONBEncoded
28 { encode = encode typeInformation . toJSON . fromJSONBEncoded
29 , decode = Hasql.refine (first pack . fmap JSONBEncoded . parseEither parseJSON) Hasql.jsonb
29 , decode = Hasql.refine (first pack . fmap JSONBEncoded . parseEither parseJSON) Hasql.jsonb
30 , typeName = "jsonb"
30 , typeName = "jsonb"
31− , out = id
32 }
31 }