on dev help sign in
arrays

PGarray ~> PGvararray PGarrayN -> PGfixarray

commitec511968e430bbf5a85b0669ebb1d95f51d137a5 authorEitan Chatav <eitan.chatav@gmail.com> dateTue 20 Mar 2018, 12:27 (9 years ago) parent5471fa1
5 files changed+17−16
squeal-postgresql/exe/Example.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+7−6 squeal-postgresql/src/Squeal/PostgreSQL/Pool.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+3−3
squeal-postgresql/exe/Example.hs+3−3
@@ -29,7 +29,7 @@ type Schema =
2929 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
3030 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
3131 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
32− , "vec" ::: 'NoDef :=> 'NotNull ('PGarray 'PGint2)
32+ , "vec" ::: 'NoDef :=> 'NotNull ('PGvararray 'PGint2)
3333 ]
3434 , "emails" :::
3535 '[ "pk_emails" ::: 'PrimaryKey '["id"]
@@ -60,7 +60,7 @@ setup =
6060teardown :: Definition Schema '[]
6161teardown = dropTable #emails >>> dropTable #users
6262
63−insertUser :: Manipulation Schema '[ 'NotNull 'PGtext, 'NotNull ('PGarray 'PGint2)]
63+insertUser :: Manipulation Schema '[ 'NotNull 'PGtext, 'NotNull ('PGvararray 'PGint2)]
6464 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
6565insertUser = insertRows #users
6666 (Default `As` #id :* Set (param @1) `As` #name :* Set (param @2) `As` #vec :* Nil) []
@@ -76,7 +76,7 @@ insertEmail = insertRows #emails
7676getUsers :: Query Schema '[]
7777 '[ "userName" ::: 'NotNull 'PGtext
7878 , "userEmail" ::: 'Null 'PGtext
79− , "userVec" ::: 'NotNull ('PGarray 'PGint2)]
79+ , "userVec" ::: 'NotNull ('PGvararray 'PGint2)]
8080getUsers = select
8181 (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* #u ! #vec `As` #userVec :* Nil)
8282 ( from (table (#users `As` #u)
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -116,7 +116,7 @@ instance ToParam DiffTime 'PGinterval where toParam = K . Encoding.interval_int
116116instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
117117instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
118118instance (HasOid pg, ToParam x pg)
119− => ToParam (Vector (Maybe x)) ('PGarray pg) where
119+ => ToParam (Vector (Maybe x)) ('PGvararray pg) where
120120 toParam = K . Encoding.nullableArray_vector
121121 (oid @pg) (unK . toParam @x @pg)
122122
@@ -193,11 +193,11 @@ instance FromValue 'PGinterval DiffTime where
193193 fromValue _ = Decoding.interval_int
194194instance FromValue 'PGjson Value where fromValue _ = Decoding.json_ast
195195instance FromValue 'PGjsonb Value where fromValue _ = Decoding.jsonb_ast
196−instance FromValue pg y => FromValue ('PGarray pg) (Vector (Maybe y)) where
196+instance FromValue pg y => FromValue ('PGvararray pg) (Vector (Maybe y)) where
197197 fromValue _ = Decoding.array
198198 (Decoding.dimensionArray Vector.replicateM
199199 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
200−instance FromValue pg y => FromValue ('PGarrayN n pg) (Vector (Maybe y)) where
200+instance FromValue pg y => FromValue ('PGfixarray n pg) (Vector (Maybe y)) where
201201 fromValue _ = Decoding.array
202202 (Decoding.dimensionArray Vector.replicateM
203203 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+7−6
@@ -100,6 +100,7 @@ module Squeal.PostgreSQL.Expression
100100 , max_, maxDistinct, min_, minDistinct
101101 -- * Tables
102102 , Table (UnsafeTable, renderTable)
103+ -- * Types
103104 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
104105 , PGTyped (pgtype)
105106 , bool
@@ -349,12 +350,12 @@ nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
349350array
350351 :: [Expression tables grouping params ('Null ty)]
351352 -- ^ array elements
352− -> Expression tables grouping params (nullity ('PGarray ty))
353+ -> Expression tables grouping params (nullity ('PGvararray ty))
353354array xs = UnsafeExpression $
354355 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
355356
356357instance Monoid
357− (Expression tables grouping params (nullity ('PGarray ty))) where
358+ (Expression tables grouping params (nullity ('PGvararray ty))) where
358359 mempty = array []
359360 mappend = unsafeBinaryOp "||"
360361
@@ -1165,14 +1166,14 @@ jsonb = UnsafeTypeExpression "jsonb"
11651166-- | variable length array
11661167vararray
11671168 :: TypeExpression ('NoDef :=> 'Null pg)
1168− -> TypeExpression ('NoDef :=> 'Null ('PGarray pg))
1169+ -> TypeExpression ('NoDef :=> 'Null ('PGvararray pg))
11691170vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
11701171-- | fixed length array
11711172fixarray
11721173 :: KnownNat n
11731174 => proxy n
11741175 -> TypeExpression ('NoDef :=> 'Null pg)
1175− -> TypeExpression ('NoDef :=> 'Null ('PGarrayN n pg))
1176+ -> TypeExpression ('NoDef :=> 'Null ('PGfixarray n pg))
11761177fixarray p ty = UnsafeTypeExpression $
11771178 renderTypeExpression ty <> "[" <> renderNat p <> "]"
11781179
@@ -1216,7 +1217,7 @@ instance PGTyped 'PGinterval where pgtype = interval
12161217instance PGTyped 'PGuuid where pgtype = uuid
12171218instance PGTyped 'PGjson where pgtype = json
12181219instance PGTyped 'PGjsonb where pgtype = jsonb
1219−instance PGTyped ty => PGTyped ('PGarray ty) where
1220+instance PGTyped ty => PGTyped ('PGvararray ty) where
12201221 pgtype = vararray (pgtype @ty)
1221−instance (KnownNat n, PGTyped ty) => PGTyped ('PGarrayN n ty) where
1222+instance (KnownNat n, PGTyped ty) => PGTyped ('PGfixarray n ty) where
12221223 pgtype = fixarray (Proxy @n) (pgtype @ty)
squeal-postgresql/src/Squeal/PostgreSQL/Pool.hs+1−1
@@ -48,7 +48,7 @@ newtype PoolPQ (schema :: TablesType) m x =
4848 deriving Functor
4949
5050-- | Create a striped pool of connections.
51−-- Although the garbage collector will destroy all idle connections when the pool is garbage collected it's recommended to manually destroyAllResources when you're done with the pool so that the connections are freed up as soon as possible.
51+-- Although the garbage collector will destroy all idle connections when the pool is garbage collected it's recommended to manually `destroyAllResources` when you're done with the pool so that the connections are freed up as soon as possible.
5252createConnectionPool
5353 :: MonadBase IO io
5454 => ByteString
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+3−3
@@ -129,8 +129,8 @@ data PGType
129129 | PGinet -- ^ IPv4 or IPv6 host address
130130 | PGjson -- ^ textual JSON data
131131 | PGjsonb -- ^ binary JSON data, decomposed
132− | PGarray PGType -- ^ variable length array
133− | PGarrayN Nat PGType -- ^ fixed length array
132+ | PGvararray PGType -- ^ variable length array
133+ | PGfixarray Nat PGType -- ^ fixed length array
134134 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
135135
136136-- | The object identifier of a `PGType`.
@@ -255,7 +255,7 @@ type TableType = ([(Symbol,TableConstraint)],ColumnsType)
255255-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
256256-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
257257-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
258−-- , "vec" ::: 'NoDef :=> 'NotNull ('PGarray 'PGint2)
258+-- , "vec" ::: 'NoDef :=> 'NotNull ('PGvararray 'PGint2)
259259-- ]
260260-- , "emails" :::
261261-- '[ "pk_emails" ::: 'PrimaryKey '["id"]