-
Notifications
You must be signed in to change notification settings - Fork 115
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
Working read/write-only fields by truly unhooking them #591
Comments
Just to check I understand, do the writing parts of these behave as indicated in the following?
|
Correct! |
Great, in that case maybe we can do them all as versions of a single "write type" that is something like WriteField a = Omitted | SetToDefault | SetToValue a |
I just noticed a related issue on rel8: circuithub/rel8#193 |
Yeah I think many Haskell db libraries handle this type of stuff poorly. I don't think |
For updates, Opaleye generates a syntactically valid query that will actually "typecheck" against the schema, so to speak, but unless the
The query updates the field by recomputing the (Which is just to say that the "nothing generated, not even |
Ah, I see this was mentioned in #590 (comment) and you were talking about generated columns, not the… |
Yes just |
Just came up with another use-case for First you convert the column to Without it it's still possible, but easier to mess up, instead of using |
I've added your suggested |
As mentioned in the documentation the current
readOnlyTableField
doesn't work in typical cases due to it feedingDEFAULT
into updates. This makes sense as there is no single value/expression/keyword you can feed into both inserts and updates that correctly models the concept of being "read only", the correct way to do it is to omit any mention of the field entirely.As a side note
readOnlyTableField
does actually work correctly for generated columns due to them allowing the keywordDEFAULT
for inserts and updates even though all other values are rejected due to their read-only nature.Given the above, we should have
tableField
functions for all possible combinations. For reads the choices are simply hooked up vs not hooked up. For writes the choices are hooked up with no default, hooked up with default, and not hooked up. You could technically include "optionally not hooked up" type of stuff, but it's not strictly needed as you can always feed inNothing
for inserts and the existing value for updates to get the same behavior.This gives us the following 6 combinations:
readOnlyTableField
andmissingTableField
should emit zero code when writing, so noDEFAULT
or anything like that, they should just be omitted entirely. Likewise the bottom three should all emit zero code when reading. I skipped the inferabletableField
but it would have a second equivalentwriteOnlyTableField
.For my use cases I see the most benefit from
readOnlyTableField
for generated columns and one-time-default-write columns likecreated
andid
, and frommissingTableField
for reserving space on core fully-polymorphic types for data that can't be obtained in a single query, be it due to a one-to-many or data from an external system.Example read-only column code:
Example missing column code:
For additional context see #447 and #590
The text was updated successfully, but these errors were encountered: