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

Expose SqlSelect so it can be used in type signatures #160

Open
googleson78 opened this issue Apr 6, 2020 · 1 comment
Open

Expose SqlSelect so it can be used in type signatures #160

googleson78 opened this issue Apr 6, 2020 · 1 comment

Comments

@googleson78
Copy link

googleson78 commented Apr 6, 2020

I currently have two very similar sql queries, different in only their return type. (one returns a tuple and has a limit, while the other returns count(*) with no limit)

I would like to create a function

f ::
  SqlSelect a r =>
  (... -> SqlQuery a) ->
  ReaderT SqlBackend IO [r]

to factour out the similarities by passing in an f :: ... -> SqlQuery a function which determines the return type of the query. However to give a type to this I have to use SqlSelect, which is in an internal module.

Would it be possible to somehow expose it for this purpose, or should I just use the Internal module in this case? (or is there some other solution that I just missed)

@googleson78
Copy link
Author

(for anyone wondering the same thing)

There is also another idea that works:
In my original post I was trying to use a select directly to implement f.

Instead of trying to generalise the select statement, I generalised the from part only, which worked out fine.

The new type of my f is

f ::
  (... -> SqlQuery b) ->
  SqlQuery b

and I later use it with

select $
  f <provide functions here that have access to the from statement in f>

The only duplicated part is now the select, which is a very minor annoyance.

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