Skip to content

Commit

Permalink
Remove Default type
Browse files Browse the repository at this point in the history
  • Loading branch information
ocharles committed Mar 31, 2021
1 parent 7881170 commit db1ddf6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Rel8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module Rel8
, select

-- ** @INSERT@
, Default(..), Insert
, Insert
, insert {- , insertReturning -}

-- ** @UPDATE@
Expand Down
12 changes: 6 additions & 6 deletions Rel8/Internal/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,17 @@ instance GTabular SchemaInfo (K1 i (SchemaInfo '( (a :: Symbol), (b :: HasDefaul
(\(SchemaInfo a) -> Identity (Colimit (SchemaInfo a)))
(\(Identity (Colimit (SchemaInfo a))) -> SchemaInfo a)

-- This is only proper if OverrideDefault DefaultInsertExpr can't occur.
instance GTabular Insert (K1 i (Default (Expr a))) Identity where
-- This is only proper if Just DefaultInsertExpr can't occur.
instance GTabular Insert (K1 i (Maybe (Expr a))) Identity where
gtabular _ = _K1 . iso forward backward
where
forward (OverrideDefault a) = Identity (Colimit (InsertExpr a))
forward InsertDefault =
forward (Just a) = Identity (Colimit (InsertExpr a))
forward Nothing =
Identity (Colimit (InsertExpr (Expr O.DefaultInsertExpr)))
backward (Identity (Colimit (InsertExpr (Expr O.DefaultInsertExpr)))) =
InsertDefault
Nothing
backward (Identity (Colimit (InsertExpr (Expr prim)))) =
OverrideDefault (Expr prim)
Just (Expr prim)

instance GTabular Insert (K1 i (Expr a)) Identity where
gtabular _ = _K1 . iso forward backward
Expand Down
15 changes: 1 addition & 14 deletions Rel8/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ data SchemaInfo a =
newtype Name a = Name String
deriving (IsString, Show)


--------------------------------------------------------------------------------
-- | When inserting into tables, some columns may be marked as allowing
-- defaults (indicated by the argument @'HasDefault@ to 'C'). If this is the
-- case, you will need to supply @Default Expr@s as column values. 'Default'
-- indicates that you are either supplying a value explictly
-- (with 'OverrideDefault'), or you wish the databse to provide a value (with
-- 'InsertDefault'). The latter is useful for automatically generated primary
-- keys, or timestamps.
data Default a
= OverrideDefault a
| InsertDefault

--------------------------------------------------------------------------------
{-| All metadata about a column in a table.
Expand All @@ -67,7 +54,7 @@ type family C f columnName hasDefault columnType :: * where
C Expr _name _def t = Expr t
C QueryResult _name _def t = t
C SchemaInfo name hasDefault t = SchemaInfo '(name, hasDefault, t)
C Insert name 'HasDefault t = Default (Expr t)
C Insert name 'HasDefault t = Maybe (Expr t)
C Insert name 'NoDefault t = Expr t
C Aggregate name _ t = Aggregate t
C Name _ _ t = Name t
Expand Down

0 comments on commit db1ddf6

Please sign in to comment.