Something went wrong. Try again.
Compile-time SQL datatype generation from PostgreSQL for Haskell
Something went wrong. Try again.
2.1 kB · 53 lines
Haskell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354module 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 = [] }