-
Notifications
You must be signed in to change notification settings - Fork 12
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
Associating Haskell fields with table columns #3
Comments
I'll think more about this, but a couple quick thoughts: For query result values, postgres does provide column names (the same ones you see is psql headers -- they don't have table names and can be changed by Another approach could be to do the equivalent of creating newtypes for columns you want to distinguish in the database itself using The more traditional way to go with this, of course, is an ORM layer that constructs queries for you and makes sure your column references match. This is certainly something that could be built on top of this library, but feels a bit antithetical to the goal of typechecking arbitrary queries. |
Oh, one more option along the lines of an ORM: I've been playing with this new |
Thanks for the quick reply! I didn't know you could define additional types in sql. That might be the most straight forward way. I'll do some reading. Thanks for the hint! |
First, this is an amazing project! Thanks so much for maintaining it.
Something I get nervous about is accidentally putting the right type of Haskell data into the wrong column in the database, or getting the right type of data from the wrong column in the database. For instance, assuming a table like:
And some Haskell definitions:
There's nothing that really stops me from writing a query where the fields are mixed up, like:
Everything type checks on the Haskell side, and it's a valid SQL expression. But, I've asked for the values from
foo.bar
andfoo.baz
–in that order–in SQL. Since both are varchars, the instances can be found in either order on the Haskell side. And a small typo has led to the data being wrong.Do you have any thoughts on how to mitigate the chance for mistakes here? My first thought was to somehow associate the types in
Foo
with the column names in the tablefoo
. Is that feasible? I would imagine that you'd need an additional type class and a different quasi quoter in order to handle that. But I haven't actually looked at anything yet. That might also be more complex than need be.The text was updated successfully, but these errors were encountered: