k0001/tisch

Documentation for mkHsI out of date

Opened this issue · 0 comments

Example of use still refers to the old type class method:

Helper function to safely build an HsI t.

The type of this function isn't easy to understand, but an example should clarify its usage. We will asume we have a TPerson which is an instance of Table, and Person datatype as follows:

data TPerson

instance Table TPerson where
data T TPerson = TPerson
type Database TPerson = ... not important ...
type SchemaName TPerson = ... not important ...
type TableName TPerson = ... not important ...
type Columns TPerson
= '[ 'Col "name" W R PGText Text
, 'Col "age" W R PGInt4 Int32
]

data Person = Person
{ _personName :: Text
, _personAge :: Int
}
With that in place, and with the OverloadedLabels GHC extension enabled, we can use mkHsI as follows:

personToHsI :: Person -> HsI TPerson
personToHsI person =
mkHsI TPerson
(hsi #name (_personName person))
(hsi #age (_personAge age))