Skip to content

Commit

Permalink
Add omitOnWriteTableField
Browse files Browse the repository at this point in the history
Part of #606
  • Loading branch information
tomjaguarpaw committed Oct 4, 2024
1 parent 5806b81 commit 541d3a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Opaleye/Internal/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ newtype Writer columns dummy =
Writer (forall f. Functor f =>
PM.PackMap (f HPQ.PrimExpr, String) () (f columns) ())

coerceWriterOutput :: Writer columns dummy -> Writer columns dummy'
coerceWriterOutput (Writer w) = Writer w

-- | 'requiredTableField' is for fields which are not optional. You
-- must provide them on writes.
requiredTableField :: String -> TableFields (Field_ n a) (Field_ n a)
Expand All @@ -109,6 +112,11 @@ optionalTableField columnName = TableFields
readOnlyTableField :: String -> TableFields () (Field_ n a)
readOnlyTableField = lmap (const Nothing) . optionalTableField

omitOnWriteTableField :: String -> TableFields () (Field_ n a)
omitOnWriteTableField columnName = TableFields
(coerceWriterOutput (pure ()))
(View (Column (HPQ.BaseTableAttrExpr columnName)))

-- | You should not define your own instances of
-- 'InferrableTableField'.
class InferrableTableField w n r
Expand Down
1 change: 1 addition & 0 deletions src/Opaleye/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module Opaleye.Table (-- * Defining tables
T.tableField,
T.optionalTableField,
T.requiredTableField,
T.omitOnWriteTableField,
T.InferrableTableField,
-- * Selecting from tables
selectTable,
Expand Down

0 comments on commit 541d3a4

Please sign in to comment.