hasql-generate-1.0.0: src/Hasql/Generate/Config.hs
module Hasql.Generate.Config
( Config (..)
) where
----------------------------------------------------------------------------------------------------
import Data.Bool ( Bool (..) )
import Data.Default.Class ( Default (..) )
import Data.String ( String )
import Hasql.Generate.Connection ( ConnectionInfo, libpqDefaults )
import Language.Haskell.TH ( Name )
----------------------------------------------------------------------------------------------------
{- Top-level configuration for compile-time code generation.
Embeds the database connection parameters ('ConnectionInfo') together with
behavioral flags that control the shape of the generated code.
Use @def@ for the default configuration, which reads connection details
from standard PostgreSQL environment variables, sets False to allowDuplicateRecordFields
and newtypePrimaryKeys, and has an emply override list.
-}
data Config
= Config
{ connection :: ConnectionInfo
, allowDuplicateRecordFields :: Bool
, newtypePrimaryKeys :: Bool
, globalOverrides :: [(String, Name)]
}
{- Default configuration:
* Connection via libpq environment variables (@PGHOST@, @PGPORT@, etc.)
* @allowDuplicateRecordFields = False@ — field names are prefixed with the
type name so the generated code compiles without @DuplicateRecordFields@
* @newtypePrimaryKeys = False@ — when @True@, generates newtype (single PK)
or data record (composite PK) wrappers for primary keys, plus @HasPrimaryKey@
instances for all tables with PKs
* @globalOverrides = []@ — PG type overrides applied to all tables. Per-table
'withOverrides' take precedence over global ones.
-}
instance Default Config where
def :: Config
def =
Config
{ connection = libpqDefaults
, allowDuplicateRecordFields = False
, newtypePrimaryKeys = False
, globalOverrides = []
}