Skip to content

Commit aec8c0a

Browse files
Kushagra GuptaKushagra Gupta
authored andcommitted
all tests should pass now
1 parent 2eb1b2c commit aec8c0a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

beam-postgres/Database/Beam/Postgres/PgSpecific.hs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -530,35 +530,30 @@ arraySample_ (QExpr arr) (QExpr n) =
530530
-- | Postgres array_to_string(array, delimiter) function.
531531
-- Converts each element to text and joins with the delimiter. NULLs are omitted.
532532
arrayToString_
533-
:: BeamSqlBackendIsString Postgres text
534-
=> QGenExpr ctxt Postgres s (V.Vector a)
533+
:: QGenExpr ctxt Postgres s (V.Vector a)
535534
-> QGenExpr ctxt Postgres s text
536535
-> QGenExpr ctxt Postgres s text
537536
arrayToString_ (QExpr arr) (QExpr delim) =
538-
QExpr (PgExpressionSyntax . mappend (emit "array_to_string") . pgParens . mconcat <$> sequenceA
539-
[ fromPgExpression <$> arr
540-
, pure (emit ", ")
541-
, fromPgExpression <$> delim
542-
])
537+
QExpr (PgExpressionSyntax <$> do
538+
arrExpr <- fromPgExpression <$> arr
539+
delimExpr <- fromPgExpression <$> delim
540+
pure $ emit "array_to_string" <> pgParens (arrExpr <> emit ", " <> delimExpr))
543541

544542
-- | Postgres array_to_string(array, delimiter, null_string) function.
545543
-- Converts each element to text and joins with the delimiter. NULLs are
546544
-- represented by the provided @null_string@.
547545
arrayToStringWithNull_
548-
:: BeamSqlBackendIsString Postgres text
549-
=> QGenExpr ctxt Postgres s (V.Vector a)
546+
:: QGenExpr ctxt Postgres s (V.Vector a)
550547
-> QGenExpr ctxt Postgres s text
551548
-> QGenExpr ctxt Postgres s text
552549
-> QGenExpr ctxt Postgres s text
553550
arrayToStringWithNull_ (QExpr arr) (QExpr delim) (QExpr nullStr) =
554-
QExpr (PgExpressionSyntax . mappend (emit "array_to_string") . pgParens . mconcat <$> sequenceA
555-
[ fromPgExpression <$> arr
556-
, pure (emit ", ")
557-
, fromPgExpression <$> delim
558-
, pure (emit ", ")
559-
, fromPgExpression <$> nullStr
560-
])
561-
551+
QExpr (PgExpressionSyntax <$> do
552+
arrExpr <- fromPgExpression <$> arr
553+
delimExpr <- fromPgExpression <$> delim
554+
nullStrExpr <- fromPgExpression <$> nullStr
555+
pure $ emit "array_to_string" <>
556+
pgParens (mconcat [arrExpr, emit ", ", delimExpr, emit ", ", nullStrExpr]))
562557
-- ** Array expressions
563558

564559
-- | An expression context that determines which types of expressions can be put

beam-postgres/test/Database/Beam/Postgres/Test/Select.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ testArraySample getConn = testFunction getConn "array_sample" $ \conn -> do
100100
_ -> assertFailure "unexpected result"
101101

102102
testArrayToStringBasic :: IO ByteString -> TestTree
103-
testArrayToStringBasic getConn = testFunction getConn "array_to_string basic" $ \conn -> do
103+
testArrayToStringBasic getConn = testFunction getConn "array_to_string_basic" $ \conn -> do
104104
let arr = V.fromList [1::Int32,2,3]
105105
res <- runBeamPostgres conn $ runSelectReturningList $ select $ do
106-
pure $ arrayToString_ (val_ arr) (val_ ("," :: T.Text))
106+
pure $ arrayToString_ (val_ arr) (val_ ",")
107107
assertEqual "join" ["1,2,3" :: T.Text] res
108108

109109
testArrayToStringWithNull :: IO ByteString -> TestTree
110-
testArrayToStringWithNull getConn = testFunction getConn "array_to_string with null" $ \conn -> do
110+
testArrayToStringWithNull getConn = testFunction getConn "array_to_string_with_null" $ \conn -> do
111111
let arr :: V.Vector (Maybe T.Text)
112112
arr = V.fromList [Just "a", Nothing, Just "b"]
113113
res <- runBeamPostgres conn $ runSelectReturningList $ select $ do
114-
pure $ arrayToStringWithNull_ (val_ arr) (val_ ("-" :: T.Text)) (val_ ("*" :: T.Text))
114+
pure $ arrayToStringWithNull_ (val_ arr) (val_ "-") (val_ "*")
115115
assertEqual "join with null" ["a-*-b" :: T.Text] res
116116

117117
testArrayAppend :: IO ByteString -> TestTree

0 commit comments

Comments
 (0)