tedious-web: Easily define multiple interrelated data types

[ bsd3, library, program, web ] [ Propose Tags ] [ Report a vulnerability ]

A user-friendly web development tool that can easily define multiple interrelated data types


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.1.2, 0.2.1.4
Change log CHANGELOG.md
Dependencies aeson (>=2.1.2.1 && <2.2), base (>=4.7 && <5), data-default (>=0.7.1.1 && <0.8), data-default-instances-containers (>=0.0.1 && <0.1), effectful-core (>=2.3.0.1 && <2.4), extra (>=1.7.14 && <1.8), generic-lens (>=2.2.2.0 && <2.3), haskell-src-meta (>=0.8.13 && <0.9), http-types (>=0.12.4 && <0.13), insert-ordered-containers (>=0.2.5.3 && <0.3), lens (>=5.2.3 && <5.3), megaparsec (>=9.5.0 && <9.6), mtl (>=2.3.1 && <2.4), opaleye (>=0.10.3.0 && <0.11), openapi3 (>=3.2.4 && <3.3), persistent (>=2.14.6.1 && <2.15), postgresql-simple (>=0.7.0.0 && <0.8), product-profunctors (>=0.11.1.1 && <0.12), profunctors (>=5.6.2 && <5.7), raw-strings-qq (>=1.1 && <1.2), resource-pool (>=0.4.0.0 && <0.5), tagged (>=0.8.8 && <0.9), tedious-web, template-haskell (>=2.20.0.0 && <2.21), text (>=2.0.2 && <2.1), time (>=1.12.2 && <1.13), tuple (>=0.3.0.2 && <0.4), unordered-containers (>=0.2.20 && <0.3), webgear-core (>=1.3.0 && <1.4) [details]
License BSD-3-Clause
Copyright 2024 WonderBear
Author WonderBear
Maintainer ximengwuheng@163.com
Category Web
Home page https://github.com/xiongxiong/tedious-web#readme
Bug tracker https://github.com/xiongxiong/tedious-web/issues
Source repo head: git clone https://github.com/xiongxiong/tedious-web
Uploaded by WonderBear at 2024-07-23T12:15:54Z
Distributions
Executables tedious-web-exe
Downloads 61 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-23 [all 1 reports]

Readme for tedious-web-0.2.1.4

[back to package description]

tedious-web

A user-friendly web development tool that can easily define multiple interrelated data types, automatically generate common type class instances, provide some convenience for web development.

Pros & Cons

Pros:

  • Can easily define multiple interrelated data types.
  • Instances of Show, Eq, Generic, Default (data-default), ToJSON (aeson), FromJSON (aeson), ToSchema (openapi) are created by default.
  • The table definition of the data type in the style of opaleye will be created easily.
  • Database migration statements based on persistent can also be easily generated.
  • Field types support type variables.

Cons:

  • Do not support sum type.
  • Do not support complex requirements.

Example

[tedious|

Person table t_persion deriving Exception -- optional comment of type
  id `ID` Int64 (Maybe (Field SqlInt8), Field SqlInt8) PersonToUpd
  firstName `first name` Text `John` ("first_name", Field SqlText) !UniquePersonName PersonToAdd PersonToUpd?
  lastName `second name` Text `Smith` ("first_name", Field SqlText) !UniquePersonName PersonToAdd PersonToUpd?
  age Int `10` (Field SqlInt4) PersonToAdd -- optional comment of field A
  address `home address` Text? (Maybe (Field SqlText), Field SqlText) PersonToAdd
  profession Text? `teacher` ("profes", Maybe (Field SqlText), Field SqlText) PersonToAdd
  hobby Text? (Maybe (Field SqlText), Field SqlText) PersonToAdd PersonToUpd?
  score `(English, Mathematic)` ((Int, Int))
  other a

|]

will generate:

data Person
  = Person {  _personId :: Int64,
              _personFirstName :: Text,
              _personLastName :: Text,
              _personAge :: Int,
              _personAddress :: (Maybe Text),
              _personProfession :: (Maybe Text),
              _personHobby :: (Maybe Text),
              _personScore :: (Int, Int)
            }

deriving instance Exception Person
deriving stock instance Show Person
deriving stock instance Eq Person
deriving stock instance Generic Person
deriving instance Default Person
instance ToJSON Person where ...
instance FromJSON Person where ...
instance ToSchema Person where ...

data PersonToAdd
  = PersonToAdd { _personToAddFirstName :: Text,
                  _personToAddLastName :: Text,
                  _personToAddAge :: Int,
                  _personToAddAddress :: (Maybe Text),
                  _personToAddProfession :: (Maybe Text),
                  _personToAddHobby :: (Maybe Text)
                }

deriving instance Exception PersonToAdd
deriving stock instance Show PersonToAdd
deriving stock instance Eq PersonToAdd
deriving stock instance Generic PersonToAdd
deriving instance Default PersonToAdd
instance ToJSON PersonToAdd where ...
instance FromJSON PersonToAdd where ...
instance ToSchema PersonToAdd where ...

data PersonToUpd
  = PersonToUpd { _personToUpdId :: Int64,
                  _personToUpdFirstName :: (Maybe Text),
                  _personToUpdLastName :: (Maybe Text),
                  _personToUpdHobby :: (Maybe Text)
                }

deriving instance Exception PersonToUpd
deriving stock instance Show PersonToUpd
deriving stock instance Eq PersonToUpd
deriving stock instance Generic PersonToUpd
deriving instance Default PersonToUpd
instance ToJSON PersonToUpd where ...
instance FromJSON PersonToUpd where ...
instance ToSchema PersonToUpd where ...

personTable :: Table  ( Maybe (Field SqlInt8), 
                        Field SqlText, 
                        Field SqlText, 
                        Field SqlInt4, 
                        Maybe (Field SqlText), 
                        Maybe (Field SqlText), 
                        Mayb(Field SqlText)
                      ) 
                      ( Field SqlInt8,
                        Field SqlText,
                        Field SqlText,
                        Field SqlInt4,
                        Field SqlText,
                        Field SqlText,
                        Field SqlText
                      )
personTable = ...

tediousPersistString :: String
tediousPersistString = ...

You can use tediousPersistString to do migration in another module like this:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] $(quoteExp persistUpperCase tediousPersistString)