Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New application: Haskell to SQL (f="SELECT * FROM table;" length<$>f="SELECT COUNT(*) FROM table;") #21

Open
runeksvendsen opened this issue Dec 12, 2017 · 0 comments

Comments

@runeksvendsen
Copy link

runeksvendsen commented Dec 12, 2017

Let's say we have an SQL database containing a comments table.

In our Haskell code, we have a DB function fetchComments :: m [Comment] which, behind the scenes, runs an SQL query and returns a list of comments. In the code that consumes this DB function, sometimes we would like to just get the number of comments, so we would write length <$> fetchComments.

So, I've been thinking: is it possible to use the library in this repo to have fetchComments generate, by default, an SQL string that looks something like "SELECT * FROM comments;", whereas, if length is applied to the return value of fetchComments in the code, the resulting SQL string would be "SELECT COUNT(*) FROM comments;"?

So, in other words, rather than having the SQL server send all the comments (possibly thousands, or millions) over the write, the length transformation -- that would otherwise be applied in application code -- is applied by the SQL server, since length <$> fetchComments is translated into a different SQL query than just fetchComments alone.

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

No branches or pull requests

1 participant