@@ -252,11 +252,11 @@ pgInsertManyEntitiesId ents' =
252
252
-- 'pgInsertManyEntitiesId' does
253
253
pgInsertManyEntities :: forall a m . (Entity a , HasPostgres m , MonadLogger m , ToRow a )
254
254
=> [a ]
255
- -> m ()
256
- pgInsertManyEntities [] = return ()
255
+ -> m Int64
256
+ pgInsertManyEntities [] = return 0
257
257
pgInsertManyEntities ents' =
258
258
let ents = NL. fromList ents'
259
- in void $ pgExecute $ insertManyEntities ents
259
+ in pgExecute $ insertManyEntities ents
260
260
261
261
262
262
{- | Delete entity.
@@ -267,19 +267,21 @@ rmUser uid = do
267
267
pgDeleteEntity uid
268
268
@
269
269
270
+ Return 'True' if row was actually deleted.
270
271
-}
271
272
272
273
pgDeleteEntity :: forall a m . (Entity a , HasPostgres m , MonadLogger m , ToField (EntityId a ), Functor m )
273
274
=> EntityId a
274
- -> m ()
275
+ -> m Bool
275
276
pgDeleteEntity eid =
276
277
let p = Proxy :: Proxy a
277
- in (const () ) <$> pgExecute [sqlExp |DELETE FROM ^{mkIdent $ tableName p}
278
- WHERE id = #{eid}|]
278
+ in fmap (1 == )
279
+ $ pgExecute [sqlExp |DELETE FROM ^{mkIdent $ tableName p}
280
+ WHERE id = #{eid}|]
279
281
280
282
281
- {- | Update entity using 'ToMarkedRow' instanced value. Requires 'Proxy' while
282
- 'EntityId' is not a data type.
283
+ {- | Update entity using 'ToMarkedRow' instanced value. Requires 'Proxy'
284
+ while 'EntityId' is not a data type.
283
285
284
286
@
285
287
fixUser :: Text -> EntityId User -> Handler ()
@@ -293,19 +295,21 @@ fixUser username uid = do
293
295
("name", mkValue username)]
294
296
@
295
297
298
+ Returns 'True' if record was actually updated and 'False' if there was
299
+ not row with such id (or was more than 1, in fact)
296
300
-}
297
301
298
302
pgUpdateEntity :: forall a b m . (ToMarkedRow b , Entity a , HasPostgres m , MonadLogger m ,
299
303
ToField (EntityId a ), Functor m , Typeable a , Typeable b )
300
304
=> EntityId a
301
305
-> b
302
- -> m ()
306
+ -> m Bool
303
307
pgUpdateEntity eid b =
304
308
let p = Proxy :: Proxy a
305
309
mr = toMarkedRow b
306
310
in if L. null $ unMR mr
307
- then return ()
308
- else fmap (const () )
311
+ then return False
312
+ else fmap (1 == )
309
313
$ pgExecute [sqlExp |UPDATE ^{mkIdent $ tableName p}
310
314
SET ^{mrToBuilder ", " mr}
311
315
WHERE id = #{eid}|]
0 commit comments