Skip to content

Add foldCopyData helper function - #56

Merged
phadej merged 1 commit into
haskellari:masterfrom
stackbuilders:all_copy_data
Nov 25, 2020
Merged

phadej merged 1 commit into
haskellari:masterfrom
stackbuilders:all_copy_data

Conversation

@sestrella

@sestrella sestrella commented Nov 23, 2020 •

Copy link
Copy Markdown
Contributor

This PR introduces a new function called foldCopyData which folds over COPY TO STDOUT query.

@phadej phadej left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The withCopyData and getAllCopyData are too specific functions.

I'd rather write something like

-- | Fold over @COPY TO STDOUT@ query. ... same notes as for 'getCopyData'.
foldCopyData
    :: (a -> ByteString -> IO a)  -- ^ Accumulate one row of the result
    -> (a -> Int64 -> IO b)       -- ^ Post-process accumulator with a count of rows
    -> a                          -- ^ Initial accumulator
    -> IO b                       -- ^ Result

and let people specialise.

Your getAllCopyData has performance issue, ++ is quadratic when used like that.
Check difference lists (i.e. composing [a] -> [a] functions).
It would be a simple instantiation of foldCopyData

@sestrella

sestrella commented Nov 24, 2020 •

Copy link
Copy Markdown
Contributor Author

@phadej thank you for the feedback! I completely agree with you, I think both functions could be replaced by a more general function. I'll work on it.

@sestrella sestrella changed the title Add getCopyData helper functions to consume all rows Add foldCopyData helper function Nov 25, 2020

@phadej phadej left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better!

Comment thread src/Database/PostgreSQL/Simple/Copy.hs Outdated
Comment thread src/Database/PostgreSQL/Simple/Copy.hs Outdated
@phadej
phadej merged commit 227fcb3 into haskellari:master Nov 25, 2020
@phadej

phadej commented Nov 25, 2020

Copy link
Copy Markdown
Collaborator

Good, thanks!

@sestrella
sestrella deleted the all_copy_data branch November 25, 2020 15:59
@phadej

phadej commented Jan 6, 2021

Copy link
Copy Markdown
Collaborator

Released in postgresql-0.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants