You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a code which I'd like to keep compatible if key type changes. For example the primary key of a table can be changed from integer to text without any code changes and I can use the value to insert rows to another table which references that column by doing only database schema changes without affecting the code.
I made a small module to demonstrate the usage. If you'd like to include it to the library, I can make a PR for it.
--|Implements type which is unparsed. The Any type is intentionally-- opaque to prevent SQL injections. It's primary purpose is to get a-- value which is used for future inserts without knowing anything-- about its type.moduleAny (Any) whereimportData.ByteString (ByteString)
importDatabase.PostgreSQL.SimpleimportDatabase.PostgreSQL.Simple.FromFieldimportDatabase.PostgreSQL.Simple.ToFieldimportData.ByteString.Builder (byteString)
newtypeAny=AnyByteStringinstanceFromFieldAnywhere
fromField f Nothing= returnError ConversionFailed f ""
fromField _ (Just bs) =pure$Any bs
instanceToFieldAnywhere
toField (Any bs) =Plain (byteString bs)
The text was updated successfully, but these errors were encountered:
I have a code which I'd like to keep compatible if key type changes. For example the primary key of a table can be changed from integer to text without any code changes and I can use the value to insert rows to another table which references that column by doing only database schema changes without affecting the code.
I made a small module to demonstrate the usage. If you'd like to include it to the library, I can make a PR for it.
The text was updated successfully, but these errors were encountered: