Skip to content

Commit 9c12203

Browse files
author
Johannes
committed
Make stream more general
1 parent 38e0434 commit 9c12203

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

app/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repl c = do
3939
hSetBuffering stdout LineBuffering
4040
catch
4141
(catch
42-
(do (_, count) <- ODBC.stream c input output (False, 0 :: Int)
42+
(do (_, count) <- ODBC.stream c input output (\_ -> pure (False, 0 :: Int))
4343
putStrLn ("Rows: " ++ show count))
4444
(\case
4545
UserInterrupt -> pure ()
@@ -54,7 +54,7 @@ piped c = do
5454
hSetBuffering stdout LineBuffering
5555
catch
5656
(catch
57-
(do (_, count) <- ODBC.stream c input output (False, 0 :: Int)
57+
(do (_, count) <- ODBC.stream c input output (\_ -> pure (False, 0 :: Int))
5858
putStrLn ("Rows: " ++ show count))
5959
(\case
6060
UserInterrupt -> pure ()

src/Database/ODBC/Internal.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ stream ::
334334
-> (state -> [(Column, Value)] -> m (Step state))
335335
-- ^ A stepping function that gets as input the current @state@ and
336336
-- a row, returning either a new @state@ or a final @result@.
337-
-> state
337+
-> ([Column] -> m state)
338338
-- ^ A state that you can use for the computation. Strictly
339339
-- evaluated each iteration.
340340
-> m state
@@ -352,7 +352,7 @@ streamWithParams ::
352352
-> (state -> [(Column, Value)] -> m (Step state))
353353
-- ^ A stepping function that gets as input the current @state@ and
354354
-- a row, returning either a new @state@ or a final @result@.
355-
-> state
355+
-> ([Column] -> m state)
356356
-- ^ A state that you can use for the computation. Strictly
357357
-- evaluated each iteration.
358358
-> m state
@@ -496,7 +496,7 @@ fetchIterator ::
496496
Ptr EnvAndDbc
497497
-> UnliftIO m
498498
-> (state -> [(Column, Value)] -> m (Step state))
499-
-> state
499+
-> ([Column] -> m state)
500500
-> SQLHSTMT s
501501
-> IO state
502502
fetchIterator dbc (UnliftIO runInIO) step state0 stmt = do
@@ -533,9 +533,8 @@ fetchIterator dbc (UnliftIO runInIO) step state0 stmt = do
533533
(coerce retcode0)
534534
"Unexpected return code"
535535
sqlState)
536-
if cols > 0
537-
then loop state0
538-
else pure state0
536+
537+
(if cols > 0 then loop else pure) =<< runInIO (state0 types)
539538

540539
-- | Fetch all results from possible multiple statements.
541540
fetchAllResults :: Ptr EnvAndDbc -> SQLHSTMT s -> IO ()

src/Database/ODBC/SQLServer.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ stream ::
455455
-> (state -> row -> m (Internal.Step state))
456456
-- ^ A stepping function that gets as input the current @state@ and
457457
-- a row, returning either a new @state@ or a final @result@.
458-
-> state
458+
-> ([Internal.Column] -> m state)
459459
-- ^ A state that you can use for the computation. Strictly
460460
-- evaluated each iteration.
461461
-> m state

test/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ dataRetrieval = do
231231
c
232232
"DROP TABLE IF EXISTS no_such_table"
233233
(\s _ -> pure (Stop s))
234-
[]
234+
(\_ -> pure [])
235235
shouldBe (map (map snd) (rows1 ++ rows2)) [])
236236
quickCheckInternalRoundtrip
237237
"Int"

0 commit comments

Comments
 (0)