Skip to content

updates for 0.12, remove foreign-generics #21

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

Merged
merged 1 commit into from
Jun 9, 2018
Merged

Conversation

justinwoo
Copy link
Contributor

Foreign-Generics won't be updated for a while, but the usages here seem to be leftover from pre-11.6 days. I updated this to have the user supply their own decoding function, and updated the tests to use Simple-JSON.

@anttih
Copy link
Collaborator

anttih commented Jun 6, 2018

Thanks! I really would like to use foreign-generics, was the hold-up just with some record stuff? Do you think we should make an interim release with this change and then update to foreign-generics later?

@justinwoo
Copy link
Contributor Author

I would like to use this library without foreign-generics at all though. Those who want to use foreign-generics could later opt in when it gets updated.

@anttih
Copy link
Collaborator

anttih commented Jun 6, 2018

How would they opt in later if this library doesn't use foreign-generic anymore?

I'm skeptical of removing the Decode constraint which would completely change the way this library works. Are you using simple-json instead of foreign-generic? Couldn't you write a Decode instance that uses simple-json or not decode at all but decode manually the Foreign value you get? Is there no type class that we could use that would serve everyone?

@justinwoo
Copy link
Contributor Author

justinwoo commented Jun 6, 2018

They can always recover the constraint version by binding show and ForeignGeneric.decode.

I would never want to use Decode in my code base which purposefully doesn't use Decode for anything. Decoding the Foreign value I get back is exactly what this PR does, where no assumptions are made but for the user to provide a function to Either.

I think there is absolutely no type class that would serve everyone, and nobody really should expect one to work. This library should not force a specific decoding solution to its users.

Libraries forcing very specific unrelated typeclasses is what makes them impossible to actually use with any of my other tools, and, for example, is why I don't use the purescript-express package.

I wouldn't be that opposed to having a fork of this library called "node-postgres-core" and having this one maintain some Foreign-Generics constraints if the README at least pointed people at not using Decode for everything.

@anttih
Copy link
Collaborator

anttih commented Jun 7, 2018

One option that converges with the node-postgres-core package you suggested, would be to only decode as much as node-pg does. That is, we would provide a custom FromSql class that would provide an instance basically only for strings, Foreign and records using RowToList. That way you would get at least something out from the result rows, and the API would be much cleaner.

@justinwoo
Copy link
Contributor Author

I really don't want this library to do any actual decoding on my behalf, I want to pass in all the decoding I do with concrete functions.

@anttih
Copy link
Collaborator

anttih commented Jun 8, 2018

Could we get rid of the print argument by fixing the error type to Error, which can be used with Aff?

rows <- fromEffFnAff $ runQuery_ sql client
either liftError pure (runExcept (sequence $ decode <$> rows))
query_ :: forall b a
. (b -> String) -> (Foreign -> Either b a) -> Query a -> Client -> Aff (Array a)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is an extra space before the Query a here and also in the next few type defs.

@justinwoo
Copy link
Contributor Author

All right, updated to use Error

@anttih
Copy link
Collaborator

anttih commented Jun 9, 2018

One final nitpick, the commit still says Either b a. Could you fix that?

removes dependency on foreign-generics and allows the user to supply
their own Foreign -> Either Error a function, e.g. Simple-JSON for record
alias decoding.
@justinwoo
Copy link
Contributor Author

okay, i updated it

@anttih anttih merged commit c71db7e into epost:master Jun 9, 2018
@anttih
Copy link
Collaborator

anttih commented Jun 9, 2018

Thanks!

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