on dev help sign in
arrays
ec51196Eitan Chatav
squeal-postgresql/exe/Example.hs+3−3
@@ -29,7 +29,7 @@ type Schema =
29 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
29 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
30 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
30 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
31 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
31 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
32− , "vec" ::: 'NoDef :=> 'NotNull ('PGarray 'PGint2)
32+ , "vec" ::: 'NoDef :=> 'NotNull ('PGvararray 'PGint2)
33 ]
33 ]
34 , "emails" :::
34 , "emails" :::
35 '[ "pk_emails" ::: 'PrimaryKey '["id"]
35 '[ "pk_emails" ::: 'PrimaryKey '["id"]
@@ -60,7 +60,7 @@ setup =
60teardown :: Definition Schema '[]
60teardown :: Definition Schema '[]
61teardown = dropTable #emails >>> dropTable #users
61teardown = dropTable #emails >>> dropTable #users
62
62
63−insertUser :: Manipulation Schema '[ 'NotNull 'PGtext, 'NotNull ('PGarray 'PGint2)]
63+insertUser :: Manipulation Schema '[ 'NotNull 'PGtext, 'NotNull ('PGvararray 'PGint2)]
64 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
64 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
65insertUser = insertRows #users
65insertUser = insertRows #users
66 (Default `As` #id :* Set (param @1) `As` #name :* Set (param @2) `As` #vec :* Nil) []
66 (Default `As` #id :* Set (param @1) `As` #name :* Set (param @2) `As` #vec :* Nil) []
@@ -76,7 +76,7 @@ insertEmail = insertRows #emails
76getUsers :: Query Schema '[]
76getUsers :: Query Schema '[]
77 '[ "userName" ::: 'NotNull 'PGtext
77 '[ "userName" ::: 'NotNull 'PGtext
78 , "userEmail" ::: 'Null 'PGtext
78 , "userEmail" ::: 'Null 'PGtext
79− , "userVec" ::: 'NotNull ('PGarray 'PGint2)]
79+ , "userVec" ::: 'NotNull ('PGvararray 'PGint2)]
80getUsers = select
80getUsers = select
81 (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* #u ! #vec `As` #userVec :* Nil)
81 (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* #u ! #vec `As` #userVec :* Nil)
82 ( from (table (#users `As` #u)
82 ( 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
116instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
116instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
117instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
117instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
118instance (HasOid pg, ToParam x pg)
118instance (HasOid pg, ToParam x pg)
119− => ToParam (Vector (Maybe x)) ('PGarray pg) where
119+ => ToParam (Vector (Maybe x)) ('PGvararray pg) where
120 toParam = K . Encoding.nullableArray_vector
120 toParam = K . Encoding.nullableArray_vector
121 (oid @pg) (unK . toParam @x @pg)
121 (oid @pg) (unK . toParam @x @pg)
122
122
@@ -193,11 +193,11 @@ instance FromValue 'PGinterval DiffTime where
193 fromValue _ = Decoding.interval_int
193 fromValue _ = Decoding.interval_int
194instance FromValue 'PGjson Value where fromValue _ = Decoding.json_ast
194instance FromValue 'PGjson Value where fromValue _ = Decoding.json_ast
195instance FromValue 'PGjsonb Value where fromValue _ = Decoding.jsonb_ast
195instance 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
197 fromValue _ = Decoding.array
197 fromValue _ = Decoding.array
198 (Decoding.dimensionArray Vector.replicateM
198 (Decoding.dimensionArray Vector.replicateM
199 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
199 (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
201 fromValue _ = Decoding.array
201 fromValue _ = Decoding.array
202 (Decoding.dimensionArray Vector.replicateM
202 (Decoding.dimensionArray Vector.replicateM
203 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
203 (Decoding.nullableValueArray (fromValue (Proxy @pg))))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+7−6
@@ -100,6 +100,7 @@ module Squeal.PostgreSQL.Expression
100 , max_, maxDistinct, min_, minDistinct
100 , max_, maxDistinct, min_, minDistinct
101 -- * Tables
101 -- * Tables
102 , Table (UnsafeTable, renderTable)
102 , Table (UnsafeTable, renderTable)
103+ -- * Types
103 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
104 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
104 , PGTyped (pgtype)
105 , PGTyped (pgtype)
105 , bool
106 , bool
@@ -349,12 +350,12 @@ nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
349array
350array
350 :: [Expression tables grouping params ('Null ty)]
351 :: [Expression tables grouping params ('Null ty)]
351 -- ^ array elements
352 -- ^ array elements
352− -> Expression tables grouping params (nullity ('PGarray ty))
353+ -> Expression tables grouping params (nullity ('PGvararray ty))
353array xs = UnsafeExpression $
354array xs = UnsafeExpression $
354 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
355 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
355
356
356instance Monoid
357instance Monoid
357− (Expression tables grouping params (nullity ('PGarray ty))) where
358+ (Expression tables grouping params (nullity ('PGvararray ty))) where
358 mempty = array []
359 mempty = array []
359 mappend = unsafeBinaryOp "||"
360 mappend = unsafeBinaryOp "||"
360
361
@@ -1165,14 +1166,14 @@ jsonb = UnsafeTypeExpression "jsonb"
1165-- | variable length array
1166-- | variable length array
1166vararray
1167vararray
1167 :: TypeExpression ('NoDef :=> 'Null pg)
1168 :: TypeExpression ('NoDef :=> 'Null pg)
1168− -> TypeExpression ('NoDef :=> 'Null ('PGarray pg))
1169+ -> TypeExpression ('NoDef :=> 'Null ('PGvararray pg))
1169vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1170vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1170-- | fixed length array
1171-- | fixed length array
1171fixarray
1172fixarray
1172 :: KnownNat n
1173 :: KnownNat n
1173 => proxy n
1174 => proxy n
1174 -> TypeExpression ('NoDef :=> 'Null pg)
1175 -> TypeExpression ('NoDef :=> 'Null pg)
1175− -> TypeExpression ('NoDef :=> 'Null ('PGarrayN n pg))
1176+ -> TypeExpression ('NoDef :=> 'Null ('PGfixarray n pg))
1176fixarray p ty = UnsafeTypeExpression $
1177fixarray p ty = UnsafeTypeExpression $
1177 renderTypeExpression ty <> "[" <> renderNat p <> "]"
1178 renderTypeExpression ty <> "[" <> renderNat p <> "]"
1178
1179
@@ -1216,7 +1217,7 @@ instance PGTyped 'PGinterval where pgtype = interval
1216instance PGTyped 'PGuuid where pgtype = uuid
1217instance PGTyped 'PGuuid where pgtype = uuid
1217instance PGTyped 'PGjson where pgtype = json
1218instance PGTyped 'PGjson where pgtype = json
1218instance PGTyped 'PGjsonb where pgtype = jsonb
1219instance PGTyped 'PGjsonb where pgtype = jsonb
1219−instance PGTyped ty => PGTyped ('PGarray ty) where
1220+instance PGTyped ty => PGTyped ('PGvararray ty) where
1220 pgtype = vararray (pgtype @ty)
1221 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
1222 pgtype = fixarray (Proxy @n) (pgtype @ty)
1223 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 =
48 deriving Functor
48 deriving Functor
49
49
50-- | Create a striped pool of connections.
50-- | 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.
52createConnectionPool
52createConnectionPool
53 :: MonadBase IO io
53 :: MonadBase IO io
54 => ByteString
54 => ByteString
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+3−3
@@ -129,8 +129,8 @@ data PGType
129 | PGinet -- ^ IPv4 or IPv6 host address
129 | PGinet -- ^ IPv4 or IPv6 host address
130 | PGjson -- ^ textual JSON data
130 | PGjson -- ^ textual JSON data
131 | PGjsonb -- ^ binary JSON data, decomposed
131 | PGjsonb -- ^ binary JSON data, decomposed
132− | PGarray PGType -- ^ variable length array
132+ | PGvararray PGType -- ^ variable length array
133− | PGarrayN Nat PGType -- ^ fixed length array
133+ | PGfixarray Nat PGType -- ^ fixed length array
134 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
134 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
135
135
136-- | The object identifier of a `PGType`.
136-- | The object identifier of a `PGType`.
@@ -255,7 +255,7 @@ type TableType = ([(Symbol,TableConstraint)],ColumnsType)
255-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
255-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
256-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
256-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
257-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
257-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
258−-- , "vec" ::: 'NoDef :=> 'NotNull ('PGarray 'PGint2)
258+-- , "vec" ::: 'NoDef :=> 'NotNull ('PGvararray 'PGint2)
259-- ]
259-- ]
260-- , "emails" :::
260-- , "emails" :::
261-- '[ "pk_emails" ::: 'PrimaryKey '["id"]
261-- '[ "pk_emails" ::: 'PrimaryKey '["id"]