digitallyinduced/ihp

Auto derive the ToJSON instance of database types

オープン

#407 opened on 2020/09/20

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)Haskell (221 件のフォーク)batch import
enhancementhacktoberfest

Repository metrics

Stars
 (5,285 個のスター)
PR merge metrics
 (平均マージ 11h 20m) (30d で 21 merged PRs)

説明

I am not terribly familiar with how this works but I've seen another haskell webserver project (Scotty) that was able to derive the ToJSON typeclass by using the type class Generic

The following changes in Generated.Types should allow for this:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics

data Model = Model {..} deriving(Eq, Show, Generic)

instance ToJSON Model

However, these changes are not sufficient as every model also contains a MetaBag property which has no ToJSON instance. I am not IHP literate enough to know what it does and if it makes sense to create some sort of empty ToJSON implementation for it. However, that would be the last roadblock to automatically derive ToJSON for all models by default.

Even if that wouldn't work, we could consider making a checkbox when generating controllers to add a default implementation of ToJSON

コントリビューターガイド