Replies: 1 comment
-
Personally I'm tempted to take this approach: type role Entity nominal
-- | The constructor is not exported
data Entity (a :: Type) = Entity
{ _tableName :: String
, _primaryKey :: String
, _schema :: Maybe String
, _fields :: [String]
}
deriving stock (Eq, Show)
entity :: String
-> String
-> Maybe String
-> [String]
-> Entity a
entity = Entity
instance HasField "tableName" (Entity r) String where
getField e = e._tableName
instance HasField "primaryKey" (Entity r) String where
getField e = e._primaryKey
instance HasField "schema" (Entity r) (Maybe String) where
getField e = e._schema
instance HasField "fields" (Entity r) [String] where
getField e = e._fields |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
At present time,
Entity
is a typeclass and we pass the dictionary implicitly to the functions.It is suggested by @dminuoso that it could be a record with a phantom type:
Question coming from a remark of @kozross:
Can we do more to avoid sneaky/accidental retagging?
Like
Entity User -> Entity Group
for instance?The constructor should not be exposed otherwise this is going to end badly.
Discussion is open.
Beta Was this translation helpful? Give feedback.
All reactions