hasql-generate
Safe HaskellNone
LanguageGHC2021

Hasql.Generate

Synopsis

Documentation

data Config Source #

Instances

Instances details
Default Config Source # 
Instance details

Defined in Hasql.Generate.Config

Methods

def :: Config #

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 HasDelete (a :: k) where Source #

Associated Types

type DeleteKey (a :: k) Source #

class HasEnum a where Source #

Methods

allValues :: [a] Source #

toText :: a -> Text Source #

fromText :: Text -> Maybe a Source #

class HasInsert a where Source #

Methods

insert :: a -> Session a Source #

insertMany :: [a] -> Session [a] Source #

class HasPrimaryKey a where Source #

Associated Types

type PkOf a Source #

type RawPkOf a Source #

Methods

toPk :: a -> PkOf a Source #

wrapPk :: RawPkOf a -> PkOf a Source #

unwrapPk :: PkOf a -> RawPkOf a Source #

rawPk :: a -> RawPkOf a Source #

class HasSelect a where Source #

Associated Types

type SelectKey a Source #

class HasUpdate a where Source #

Methods

update :: a -> Session (Maybe a) Source #

updateMany :: [a] -> Session [a] 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

Instances details
PgCodec Value Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec ByteString Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Int16 Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Int32 Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Int64 Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Scientific Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Text Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Day Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec DiffTime Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec UTCTime Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec LocalTime Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec TimeOfDay Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec UUID Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec String Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Bool Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Char Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Double Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec Float Source # 
Instance details

Defined in Hasql.Generate.Codec

PgCodec (TimeOfDay, TimeZone) Source # 
Instance details

Defined in Hasql.Generate.Codec

class PgCodec a => PgColumn (pgSchema :: Symbol) (pgName :: Symbol) a | pgSchema pgName -> a Source #

Instances

Instances details
PgColumn "pg_catalog" "bool" Bool Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "bpchar" Text Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "bytea" ByteString Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "char" Char Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "date" Day Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "float4" Float Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "float8" Double Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "int2" Int16 Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "int4" Int32 Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "int8" Int64 Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "interval" DiffTime Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "json" Value Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "jsonb" Value Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "name" Text Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "numeric" Scientific Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "text" Text Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "time" TimeOfDay Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "timestamp" LocalTime Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "timestamptz" UTCTime Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "uuid" UUID Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "varchar" Text Source # 
Instance details

Defined in Hasql.Generate.Column

PgColumn "pg_catalog" "timetz" (TimeOfDay, TimeZone) Source # 
Instance details

Defined in Hasql.Generate.Column

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.