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.
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 writelength <$> 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, iflength
is applied to the return value offetchComments
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, sincelength <$> fetchComments
is translated into a different SQL query than justfetchComments
alone.