|
1 | 1 | {- AUTOCOLLECT.TEST -}
|
| 2 | +{-# LANGUAGE LambdaCase #-} |
2 | 3 | {-# LANGUAGE NamedFieldPuns #-}
|
3 | 4 | {-# LANGUAGE OverloadedStrings #-}
|
4 | 5 | {-# LANGUAGE ScopedTypeVariables #-}
|
@@ -698,20 +699,20 @@ testPersistentAPI backendType =
|
698 | 699 | result <- runTestApp backendType $ do
|
699 | 700 | insertMany_ [person "Alice", person "Bob"]
|
700 | 701 | withRawQuery "SELECT name FROM person" [] $
|
701 |
| - Conduit.mapC (fromPersistValue' @Text . head) .| Conduit.sinkList |
| 702 | + Conduit.mapC (getFirstPersistValue @Text) .| Conduit.sinkList |
702 | 703 |
|
703 | 704 | result @?= ["Alice", "Bob"]
|
704 | 705 | , testCase "rawQueryRes" $ do
|
705 | 706 | result <- runTestApp backendType $ do
|
706 | 707 | insertMany_ [person "Alice", person "Bob"]
|
707 | 708 | acquire <- rawQueryRes "SELECT name FROM person" []
|
708 | 709 | Acquire.with acquire $ \conduit ->
|
709 |
| - runConduit $ conduit .| Conduit.mapC (fromPersistValue' @Text . head) .| Conduit.sinkList |
| 710 | + runConduit $ conduit .| Conduit.mapC (getFirstPersistValue @Text) .| Conduit.sinkList |
710 | 711 | result @?= ["Alice", "Bob"]
|
711 | 712 | , testCase "rawQuery" $ do
|
712 | 713 | result <- runTestApp backendType $ do
|
713 | 714 | insertMany_ [person "Alice", person "Bob"]
|
714 |
| - runConduit $ rawQuery "SELECT name FROM person" [] .| Conduit.mapC (fromPersistValue' @Text . head) .| Conduit.sinkList |
| 715 | + runConduit $ rawQuery "SELECT name FROM person" [] .| Conduit.mapC (getFirstPersistValue @Text) .| Conduit.sinkList |
715 | 716 | result @?= ["Alice", "Bob"]
|
716 | 717 | , testCase "rawExecute" $ do
|
717 | 718 | result <- runTestApp backendType $ do
|
@@ -792,8 +793,13 @@ testInterop backendType =
|
792 | 793 |
|
793 | 794 | {- Persistent helpers -}
|
794 | 795 |
|
795 |
| -fromPersistValue' :: (PersistField a) => PersistValue -> a |
796 |
| -fromPersistValue' = either (error . Text.unpack) id . fromPersistValue |
| 796 | +getFirstPersistValue :: (PersistField a) => [PersistValue] -> a |
| 797 | +getFirstPersistValue = \case |
| 798 | + [] -> error "Unexpectedly got no values" |
| 799 | + v : _ -> fromPersistValueOrFail v |
| 800 | + |
| 801 | +fromPersistValueOrFail :: (PersistField a) => PersistValue -> a |
| 802 | +fromPersistValueOrFail = either (error . Text.unpack) id . fromPersistValue |
797 | 803 |
|
798 | 804 | {- Meta SQL helpers -}
|
799 | 805 |
|
|
0 commit comments