| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hasql.Generate
Synopsis
- data Config = Config {}
- data ConnectionInfo
- = PgSimpleInfo { }
- | PgConnectionString String
- data GenerateConfig
- class HasDelete (a :: k) where
- class HasEnum a where
- class HasInsert a where
- insert :: a -> Session a
- insertMany :: [a] -> Session [a]
- class HasPrimaryKey a where
- class HasSelect a where
- class HasUpdate a where
- update :: a -> Session (Maybe a)
- updateMany :: [a] -> Session [a]
- class HasView a where
- selectView :: Session [a]
- class PgCodec a where
- class PgCodec a => PgColumn (pgSchema :: Symbol) (pgName :: Symbol) a | pgSchema pgName -> a
- fromTable :: String -> String -> GenerateConfig
- fromType :: String -> String -> GenerateConfig
- fromView :: String -> String -> GenerateConfig
- generate :: Config -> GenerateConfig -> Q [Dec]
- libpqDefaults :: ConnectionInfo
- withDefaultedCols :: [String] -> GenerateConfig -> GenerateConfig
- withDerivations :: [Name] -> GenerateConfig -> GenerateConfig
- withOverrides :: [(String, Name)] -> GenerateConfig -> GenerateConfig
Documentation
Constructors
| Config | |
Fields | |
data ConnectionInfo Source #
Constructors
| PgSimpleInfo | |
| PgConnectionString String | |
Instances
| Default ConnectionInfo Source # | |
Defined in Hasql.Generate.Connection Methods def :: ConnectionInfo # | |
data GenerateConfig Source #
Configuration for a table, view, or type code-generation request.
Use fromTable, fromView, or fromType to create a default config,
then chain modifier functions with (&) to customise it:
fromTable "public" "users"
& withDerivations [''Show, ''Eq, ''Generic]
& withOverrides [("timestamptz", ''UTCTime)]
& withDefaultedCols ["id"]
class HasPrimaryKey a where Source #
class HasView a where Source #
Typeclass for views — read-only relations with no primary key.
Methods
selectView :: Session [a] Source #
class PgCodec a where Source #
Instances
class PgCodec a => PgColumn (pgSchema :: Symbol) (pgName :: Symbol) a | pgSchema pgName -> a Source #
Instances
fromTable :: String -> String -> GenerateConfig Source #
Create a GenerateConfig for the given schema and table with no derivations
and no type overrides. Generates full CRUD code.
fromType :: String -> String -> GenerateConfig Source #
Create a GenerateConfig for the given schema and enum type with no
derivations. Generates a Haskell sum type, a PgCodec instance,
and a PgColumn instance. Overrides are ignored for types.
The splice must appear before any fromTable whose table has a column of
this enum type, since TH processes splices top to bottom.
Orphan instance warning: The generated PgColumn instance will trigger
GHC's -Worphans warning because the functional dependency's determining
types are Symbol literals, which GHC never considers local to any user
module. This is expected and harmless. Add the following pragma to any
module that uses fromType:
{-# OPTIONS_GHC -Wno-orphans #-}
fromView :: String -> String -> GenerateConfig Source #
Create a GenerateConfig for the given schema and view with no derivations
and no type overrides. Generates read-only code: a record type, a decoder,
a SELECT statement, and a HasView instance.
generate :: Config -> GenerateConfig -> Q [Dec] Source #
Terminal step that introspects a PostgreSQL database at compile time and generates the provided data construct:
Usage:
$(generate def (fromTable "public" "users" & withDerivations [''Show, ''Eq]))
withDefaultedCols :: [String] -> GenerateConfig -> GenerateConfig Source #
Exclude the named columns from INSERT statements. Each column must exist
in the table and have a database default (atthasdef = true in
pg_catalog); a compile-time error is raised otherwise.
fromTable "public" "users" & withDefaultedCols ["id", "created_at"]
withDerivations :: [Name] -> GenerateConfig -> GenerateConfig Source #
Append derivation class Names to the config.
withOverrides :: [(String, Name)] -> GenerateConfig -> GenerateConfig Source #
Append per-table PG type overrides. Each pair maps a PostgreSQL type name
(e.g. "timestamptz") to a Haskell type Name (e.g. ''UTCTime).
The override type must still have a PgCodec instance.