-
Notifications
You must be signed in to change notification settings - Fork 46
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
fieldWIthParser helper #31
Comments
If I understand you right, I think a similar effect can be accomplished by wrapping your type with a newtype and adding a FromField instance for that. Here's a snippet from UserInstances.hs unit test:
I realize though that this does not cover everything. If the above is not what you'd like to do, can you post a comment with an end-to-end example of your suggestion? |
@nurpax That suggestion is basically the same as what I have to do write now, that is, I have to write the full adapter from the |
Sorry, this fell through the cracks. It'd be great to see a complete example of what you had to do without this feature (preferably one that compiles) and an equivalent example using the new entry point you're proposing. |
Current:
New:
|
@singpolyma Sorry for not getting back to this earlier. I quite like the idea. The current FromField instance is kind of ugly as it uses the Ok type for the return value instead of Either. Your suggestion
do you mind if we drop the first String parameter and require 'a' type to be an instance of Typeable? Typeable is already in heavy use in sqlite-simple and helps to construct better error messages automatically. I originally thought perhaps we should generalize this so that non-string types could be used too, but that makes things a bit awkward. I'll post a WIP patch here and will try and if something better comes out. :) |
@lpsmith - any thoughts on generalizing or improving what's being proposed here? This might be useful for postgresql-simple too. Example usage:
If you hit an error in the fieldWithParser parser function, the error will look something like this:
OTOH, if you hit a type error, you'll see something like this:
|
@nurpax I thought you might want to switch to |
Well, very early versions of I guess I don't have a strong opinion on this proposal; it's purely a convenience function which I tend to be wary of adding, but not an immediate disqualification either. |
@singpolyma Right, I guess I agree that requiring users of sqlite-simple to add a Typeable instance to their types just to get error messages right seems a bit harsh. OTOH, I'm not a big fan of adding debug strings into the public API, there aren't any existing entry points which would have them. How about we name this to just "textField"? The type should pretty well show its intended use. I'd like 'text' in the name since this is hardcoded for sqlite string fields. I also noticed that postgresql-simple has a
which sqlite-simple doesn't have. Filed #34 for adding these. |
queryWith_ was contributed recently in #43. |
If I have an existing parser, it would be nice to have an easy way to use that to parse database contents, like maybe:
The text was updated successfully, but these errors were encountered: