pg-schema
Copyright(c) Dmitry Olshansky
LicenseBSD-3-Clause
Maintainerolshanskydr@gmail.com, dima@typeable.io
Stabilityexperimental
Safe HaskellNone
LanguageGHC2021

PgSchema.DML

Description

A module to generate and safely execute SQL statements.

Among pg-schema’s library modules, this is the one meant for ordinary application imports for database access (alongside your generated schema module).

TLDR; Example:

data Order = Order { num :: Text, createdAt :: Day, items :: [OrdPos] } deriving Generic
data OrdPos = OrdPos { id :: Int32, num :: Int32, article :: Article, price :: Double } deriving Generic
data Article = Article { id :: Int32, name :: Text } deriving Generic
type MyAnn tabName = 'Ann 5 CamelToSnake MySch ("dbSchema" ->> tabName)
    ...
do
  void $ insertJSON_ (MyAnn "orders") conn
    [ "num" =: "num1" :. "ord__ord_pos" =:
      [ "num" =: 1 :. "articleId" =: 42 :. "price" =: 10
      , "num" =: 2 :. "articleId" =: 41 :. "price" =: 15 ] ]

  (xs :: [Order]) <- selectSch (MyAnn "orders") conn $ qRoot do
    qWhere $ "created_at" >? someDay
      &&& pchild "ord__ord_pos" defTabParam
        (pparent "ord_pos__article" $ "name" ~~? "%pencil%")
    qOrderBy [descf "created_at", descf "num"]
    qPath "ord__ord_pos" do
      qWhere $ pparent "ord_pos__article" $ "name" ~~? "%pencil%"
      qOrderBy [ascf "num"]
    qLimit 20

Here we get all orders created after someDay that have positions with articles like "%pencil%", and return only those order items that relate to "pencil", with article info.

The preceding insertJSON_ call inserts one root row (here an order) and nested child rows (here order positions) in a single database operation, again using JSON internally. Child data is carried in list fields: the field’s name (after Renamer) names the FK constraint in the database and thus selects the child table and link; each list element supplies one child row’s columns, with nested lists for further children in the same way. For strict inserts, insertJSON and insertJSON_ require every mandatory column at each node; upsertJSON / upsertJSON_ relax that so each row can be resolved by keys and optional columns (see their Haddock). Plain insertSch / insertSch_ follow the same safety story for flat (non-tree) rows.

selectSch decodes each row into a Haskell type r whose fields describe the root table columns and nested data for relations (multiple list-shaped children and nested parents/Maybe as appropriate). The type drives the generated SQL shape; monadic QueryParam only adds what this call needs—filters, ordering on a branch, limits, and so on.

We can use both Generic-based and PgTag-based ((=:)) interfaces and mix them in any way.

All string literals at the type level are Symbol thanks to RequiredTypeArguments. Operations are safe when the live database schema matches the generated schema types.

The INSERT and SELECT shown here each run as a single, fast database round-trip (JSON inside PostgreSQL).

We use a Renamer (e.g. CamelToSnake) to map Haskell field names to snake_case in the database. In conditions and QueryParams, column names are the original database names. It can be changed in the future.

Synopsis

DML

Select

Execute SQL

selectSch :: forall (ren :: Renamer) sch (d :: Nat) (tab :: NameNSK). forall (ann :: Ann) -> forall r. (Selectable ann r, ann ~ 'Ann ren sch d tab) => Connection -> QueryParam sch tab -> IO ([r], (Text, [SomeToField])) Source #

Run a single SELECT for root table tab (see annotation ann with schema sch and Renamer ren) and decode rows into [r], also returning the SQL text and bind parameters (for tracing or debugging).

The desired result type r fixes the shape of each row: typically a record with columns of the root table and nested Haskell values for relations along the schema graph. There may be several child-side fields (often lists of nested records) and several parent-side fields (nested records; wrapped in Maybe when the foreign-key side you join from allows NULL).

What actually appears in the generated SQL beyond that shape is controlled by the QueryParam: filters, which paths are traversed, ordering on a branch (e.g. child rows sorted by their position number), limits, and similar options. You only configure in QueryParam what you need for this query—not every possible relation field in r.

Build QueryParam with the MonadQP API.

selectText :: forall (ren :: Renamer) sch (d :: Nat) (tab :: NameNSK). forall (ann :: Ann) -> forall r. (CRecInfo ann r, ann ~ 'Ann ren sch d tab) => QueryParam sch tab -> (Text, [SomeToField]) Source #

Return the generated SELECT SQL text (and bind parameters), e.g. for debugging.

type Selectable (ann :: Ann) r = (CRecInfo ann r, FromRow (PgTag ann r)) Source #

Monad to set Query Params

type MonadQP sch (t :: NameNSK) (path :: [Symbol]) = (TabPath sch t path, ToStar path) => RWS (Proxy path) () (QueryParam sch t) () Source #

qpEmpty :: forall sch (t :: NameNSK). QueryParam sch t Source #

Empty QueryParam.

It means that SELECT is defined only by structure of output type

qRoot :: forall {a} sch (t :: NameNSK). RWS (Proxy ('[] :: [a])) () (QueryParam sch t) () -> QueryParam sch t Source #

Execute MonadQP and get QueryParam.

The table t defines a context and becomes the "current" table

qPath :: forall sch (t :: NameNSK) (path :: [Symbol]) (path' :: [Symbol]). forall (p :: Symbol) -> (TabPath sch t path', ToStar path', path' ~ (path ++ '[p])) => MonadQP sch t path' -> MonadQP sch t path Source #

Change context (current table) to parent or child table.

The Symbol must name the foreign-key constraint (edge to the parent or from the child) for the step away from the current table.

qWhere :: forall sch (t :: NameNSK) (path :: [Symbol]). Cond sch (TabOnPath sch t path) -> MonadQP sch t path Source #

Add WHERE condition for the current table.

If several qWhere exist they are composed according to the Monoid instance for Cond, i.e. with (&&&)

qOrderBy :: forall sch (t :: NameNSK) (path :: [Symbol]). [OrdFld sch (TabOnPath sch t path)] -> MonadQP sch t path Source #

Add ORDER BY condition for the current table

Several qOrderBy are possible and they are composed together.

Ordering can span the current table and joined parents. For example:

qOrderBy [ascf "f1"]
qPath "ref-to-parent" do
  qOrderBy [descf "f2"]
qOrderBy [ascf "f3"]

we get ORDER BY t1.f1, t2.f2 DESC, t1.f3

qDistinct :: forall sch (t :: NameNSK) (path :: [Symbol]) (t' :: NameNSK). TabOnPath2 sch t path ~ '(t', 'RelMany) => MonadQP sch t path Source #

Add DISTINCT condition for the current table. It is applied only to "root" or "children" tables.

qDistinctOn :: forall sch (t :: NameNSK) (path :: [Symbol]). [OrdFld sch (TabOnPath sch t path)] -> MonadQP sch t path Source #

Add DISTINCT ON condition for the current table.

It can also be applied on a parent table because that parent is joined to the current table.

qDistinctOn automatically adds fields to the ORDER BY clause (as PostgreSQL requires). (That's why OrdDirection is needed) So having

qOrderBy [descf "f0"]
qDistinctOn [ascf "f1"]
qPath "ref-to-parent" do
  qDistinctOn [descf "f2"]
qDistinctOn [ascf "f3"]

we get DISTINCT ON (t1.f1, t2.f2, t1.f3) ... ORDER BY t1.f1, t2.f2 DESC, t1.f3, t1.f0 DESC

qLimit :: forall sch (t :: NameNSK) (path :: [Symbol]). Snd (TabOnPath2 sch t path) ~ 'RelMany => Natural -> MonadQP sch t path Source #

Add LIMIT condition for the current table. It is applied only to "root" or "children" tables.

If qLimit is applied several times on the same path, only the last one is used

qOffset :: forall sch (t :: NameNSK) (path :: [Symbol]). Snd (TabOnPath2 sch t path) ~ 'RelMany => Natural -> MonadQP sch t path Source #

Add OFFSET condition for the current table. It is applied only to "root" or "children" tables.

If qOffset is applied several times on the same path, only the last one is used

Internals

data QueryParam sch (t :: NameNSK) Source #

Parameters that are used to describe SELECT.

You don't need to make it directly. Use MonadQP to define QueryParam instead.

Constructors

QueryParam 

Fields

data CondWithPath sch (t :: NameNSK) where Source #

GADT to safely set `where` condition

Constructors

CondWithPath :: forall (path :: [Symbol]) sch (t :: NameNSK). ToStar path => Cond sch (TabOnPath sch t path) -> CondWithPath sch t 

data OrdWithPath (sch :: k) (t :: NameNSK) where Source #

GADT to safely set `order by` clauses

Constructors

OrdWithPath :: forall {k} (path :: [Symbol]) (sch :: k) (t :: NameNSK). ToStar path => [OrdFld sch (TabOnPath sch t path)] -> OrdWithPath sch t 

data LimOffWithPath (sch :: k) (t :: NameNSK) where Source #

GADT to safely set `limit/offset` clauses

Constructors

LimOffWithPath :: forall {k} (path :: [Symbol]) (sch :: k) (t :: NameNSK). (TabPath sch t path, ToStar path, Snd (TabOnPath2 sch t path) ~ 'RelMany) => LO -> LimOffWithPath sch t 

data DistWithPath (sch :: k) (t :: NameNSK) where Source #

GADT to safely set `distinct/distinct on` clauses

Constructors

DistWithPath :: forall {k} (path :: [Symbol]) (sch :: k) (t :: NameNSK). ToStar path => Dist sch (TabOnPath sch t path) -> DistWithPath sch t 

Conditions

Example: "name" =? John

(<?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(>?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(<=?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(>=?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(=?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

Example: "name" ~~? "%joh%"

(~=?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(~~?) :: forall (fld :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab fld fd v => v -> Cond sch tab infix 4 Source #

(|||) :: forall sch (tab :: NameNSK). Cond sch tab -> Cond sch tab -> Cond sch tab infixl 2 Source #

Disjunction

(&&&) :: forall sch (tab :: NameNSK). Cond sch tab -> Cond sch tab -> Cond sch tab infixl 3 Source #

Conjunction

pnot :: forall sch (tab :: NameNSK). Cond sch tab -> Cond sch tab Source #

Boolean NOT

pnull :: forall sch (tab :: NameNSK) (fd :: FldDef' Symbol). forall (name :: Symbol) -> CDBFieldNullable sch tab name fd => Cond sch tab Source #

Check that field value is NULL

pin :: forall (name :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab name fd v => NonEmpty v -> Cond sch tab Source #

Check that field value belongs to non-empty list of values

pinArr :: forall (name :: Symbol) -> forall sch (tab :: NameNSK) (fd :: FldDef' Symbol) v. CDBValue sch tab name fd v => [v] -> Cond sch tab Source #

Check that field value belongs to the list of values. If the list is empty, the condition evaluates to false.

pparent :: forall (ref :: NameNSK) -> CRelDef sch ref => Cond sch (RdTo (TRelDef sch ref)) -> Cond sch (RdFrom (TRelDef sch ref)) Source #

Check that condition is satisfied in parent table

pchild :: forall (ref :: NameNSK) -> CRelDef sch ref => TabParam sch (RdFrom (TRelDef sch ref)) -> Cond sch (RdFrom (TRelDef sch ref)) -> Cond sch (RdTo (TRelDef sch ref)) Source #

True when related rows exist in the child table and satisfy the nested condition there

TabParam is used to limit child dataset (usually with ORDER BY and LIMIT) before applying condition on child table

data TabParam sch (tab :: NameNSK) Source #

Parameters for child table.

It is used to limit child dataset (usually with ORDER BY and LIMIT) before applying condition on child table

Constructors

TabParam 

Fields

defTabParam :: forall sch (tab :: NameNSK). TabParam sch tab Source #

Default empty TabParam.

pUnsafeCond :: forall sch (tab :: NameNSK). CondMonad Text -> Cond sch tab Source #

data Cond sch (tab :: NameNSK) where Source #

GADT to safely set `where` condition for table tab based on definition of schema sch

Cond is Monoid with conjunction ((&&&)) as mappend

Constructors

EmptyCond 

Fields

  • :: forall sch (tab :: NameNSK). Cond sch tab

    Empty Condition. Neutral for conjunction (&&&) and disjunction (|||).

Cmp 

Fields

In 

Fields

InArr 

Fields

  • :: forall (fld :: Symbol) v sch (tab :: NameNSK) (fd :: FldDef' Symbol). CDBValue sch tab fld fd v
     
  • => [v]
     
  • -> Cond sch tab

    Check that field value belongs to the list of values. If the list is empty, the condition evaluates to false.

Null 

Fields

Not 

Fields

BoolOp 

Fields

Child 

Fields

Parent 

Fields

UnsafeCond 

Fields

Instances

Instances details
Monoid (Cond sch tab) Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

mempty :: Cond sch tab #

mappend :: Cond sch tab -> Cond sch tab -> Cond sch tab #

mconcat :: [Cond sch tab] -> Cond sch tab #

Semigroup (Cond sch tab) Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

(<>) :: Cond sch tab -> Cond sch tab -> Cond sch tab #

sconcat :: NonEmpty (Cond sch tab) -> Cond sch tab #

stimes :: Integral b => b -> Cond sch tab -> Cond sch tab #

data Cmp Source #

Comparison constructors; each is paired with its corresponding operator (e.g. (:=) with (=?)).

Constructors

(:=) 
(:<=) 
(:>=) 
(:>) 
(:<) 
Like 
ILike 

Instances

Instances details
Generic Cmp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Associated Types

type Rep Cmp 
Instance details

Defined in PgSchema.DML.Select.Types

type Rep Cmp = D1 ('MetaData "Cmp" "PgSchema.DML.Select.Types" "pg-schema-0.5.0.0-inplace" 'False) ((C1 ('MetaCons ":=" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons ":<=" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons ":>=" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons ":>" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons ":<" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Like" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ILike" 'PrefixI 'False) (U1 :: Type -> Type))))

Methods

from :: Cmp -> Rep Cmp x #

to :: Rep Cmp x -> Cmp #

Show Cmp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

showsPrec :: Int -> Cmp -> ShowS #

show :: Cmp -> String #

showList :: [Cmp] -> ShowS #

Eq Cmp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

(==) :: Cmp -> Cmp -> Bool #

(/=) :: Cmp -> Cmp -> Bool #

type Rep Cmp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

type Rep Cmp = D1 ('MetaData "Cmp" "PgSchema.DML.Select.Types" "pg-schema-0.5.0.0-inplace" 'False) ((C1 ('MetaCons ":=" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons ":<=" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons ":>=" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons ":>" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons ":<" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Like" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ILike" 'PrefixI 'False) (U1 :: Type -> Type))))

data BoolOp Source #

Just boolean operations

Constructors

And 
Or 

Instances

Instances details
Generic BoolOp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Associated Types

type Rep BoolOp 
Instance details

Defined in PgSchema.DML.Select.Types

type Rep BoolOp = D1 ('MetaData "BoolOp" "PgSchema.DML.Select.Types" "pg-schema-0.5.0.0-inplace" 'False) (C1 ('MetaCons "And" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Or" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: BoolOp -> Rep BoolOp x #

to :: Rep BoolOp x -> BoolOp #

Show BoolOp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Eq BoolOp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

(==) :: BoolOp -> BoolOp -> Bool #

(/=) :: BoolOp -> BoolOp -> Bool #

type Rep BoolOp Source # 
Instance details

Defined in PgSchema.DML.Select.Types

type Rep BoolOp = D1 ('MetaData "BoolOp" "PgSchema.DML.Select.Types" "pg-schema-0.5.0.0-inplace" 'False) (C1 ('MetaCons "And" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Or" 'PrefixI 'False) (U1 :: Type -> Type))

type CondMonad = RWS (Text, NonEmpty Int) [SomeToField] Int Source #

RWS-Monad to generate condition. * Read: Stack of numbers of parent tables. The top is "current table" * Write: List of placeholder-values.

Note: SQL is generated top-down so placeholder values appear in the correct order.

  • State: Last number of table "in use"

data SomeToField where Source #

Constructors

SomeToField :: forall a. (ToField a, Show a) => a -> SomeToField 

Instances

Instances details
Show SomeToField Source # 
Instance details

Defined in PgSchema.DML.Select.Types

ToField SomeToField Source # 
Instance details

Defined in PgSchema.DML.Select.Types

showCmp :: IsString s => Cmp -> s Source #

qual :: forall (fld :: Symbol). ToStar fld => CondMonad Text Source #

type CDBField (sch :: k) (tab :: NameNSK) (fld :: Symbol) (fd :: FldDef' Symbol) = (CDBFieldInfo sch tab fld, TDBFieldInfo sch tab fld ~ ('RFPlain fd :: RecField' Symbol NameNSK)) Source #

type CDBValue sch (tab :: NameNSK) (fld :: Symbol) (fd :: FldDef' Symbol) v = (CDBField sch tab fld fd, ToField v, Show v, CanConvert sch tab fld fd v) Source #

type CDBFieldNullable (sch :: k) (tab :: NameNSK) (fld :: Symbol) (fd :: FldDef' Symbol) = (CDBField sch tab fld fd, FdNullable fd ~ 'True) Source #

class (ToStar (TRelDef sch ref), CTabDef sch (RdFrom (TRelDef sch ref)), CTabDef sch (RdTo (TRelDef sch ref))) => CRelDef (sch :: k) (ref :: NameNSK) Source #

Relation definition for relation name ref.

Instances

Instances details
CRelDef PgCatalog (PGC "attribute__class") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "attribute__class") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "attribute__class") = 'RelDef (PGC "pg_attribute") (PGC "pg_class") '['("attrelid", "oid")]
CRelDef PgCatalog (PGC "attribute__type") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "attribute__type") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "attribute__type") = 'RelDef (PGC "pg_attribute") (PGC "pg_type") '['("atttypid", "oid")]
CRelDef PgCatalog (PGC "class__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "class__namespace") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "class__namespace") = 'RelDef (PGC "pg_class") (PGC "pg_namespace") '['("relnamespace", "oid")]
CRelDef PgCatalog (PGC "constraint__class") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "constraint__class") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__class") = 'RelDef (PGC "pg_constraint") (PGC "pg_class") '['("conrelid", "oid")]
CRelDef PgCatalog (PGC "constraint__fclass") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "constraint__fclass") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__fclass") = 'RelDef (PGC "pg_constraint") (PGC "pg_class") '['("confrelid", "oid")]
CRelDef PgCatalog (PGC "constraint__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "constraint__namespace") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__namespace") = 'RelDef (PGC "pg_constraint") (PGC "pg_namespace") '['("connamespace", "oid")]
CRelDef PgCatalog (PGC "enum__type") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "enum__type") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "enum__type") = 'RelDef (PGC "pg_enum") (PGC "pg_type") '['("enumtypid", "oid")]
CRelDef PgCatalog (PGC "type__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TRelDef PgCatalog (PGC "type__namespace") 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "type__namespace") = 'RelDef (PGC "pg_type") (PGC "pg_namespace") '['("typnamespace", "oid")]

Order By and others

ordf :: forall (fld :: Symbol) -> forall (sch :: k) (tab :: NameNSK) (fd :: FldDef' Symbol). CDBField sch tab fld fd => OrdDirection -> OrdFld sch tab Source #

ascf :: forall (fld :: Symbol) -> forall (sch :: k) (tab :: NameNSK) (fd :: FldDef' Symbol). CDBField sch tab fld fd => OrdFld sch tab Source #

descf :: forall (fld :: Symbol) -> forall (sch :: k) (tab :: NameNSK) (fd :: FldDef' Symbol). CDBField sch tab fld fd => OrdFld sch tab Source #

data OrdDirection Source #

Constructors

Asc 
Desc 

Instances

Instances details
Show OrdDirection Source # 
Instance details

Defined in PgSchema.DML.Select.Types

data OrdFld (sch :: k) (tab :: NameNSK) where Source #

Constructors

OrdFld :: forall {k} (fld :: Symbol) (sch :: k) (tab :: NameNSK) (fd :: FldDef' Symbol). CDBField sch tab fld fd => OrdDirection -> OrdFld sch tab 
UnsafeOrd :: forall {k} (sch :: k) (tab :: NameNSK). CondMonad (Text, OrdDirection) -> OrdFld sch tab 

data Dist (sch :: k) (tab :: NameNSK) where Source #

Constructors

Distinct :: forall {k} (sch :: k) (tab :: NameNSK). Dist sch tab 
DistinctOn :: forall {k} (sch :: k) (tab :: NameNSK). [OrdFld sch tab] -> Dist sch tab

Having DistinctOn we automatically add fields from DistinctOn into the begining of ORDER BY. (It is "good enough" and more simple than check it on type level).

That's why we use OrdFld who include OrdDirection. Naturally OrdDirection is not used in DISTINCT ON part itself.

Beside that DISTINCT ON part can include expressions like ORDER BY. We can also use UnsafeOrd here

data LO Source #

Constructors

LO 

Instances

Instances details
Show LO Source # 
Instance details

Defined in PgSchema.DML.Select.Types

Methods

showsPrec :: Int -> LO -> ShowS #

show :: LO -> String #

showList :: [LO] -> ShowS #

Plain Insert

insertSch :: forall (ann :: Ann) -> forall r r'. InsertReturning ann r r' => Connection -> [r] -> IO ([r'], Text) Source #

Insert records into a table. You can request any subset of columns from the inserted row via the result type.

All mandatory fields having no defaults should be present.

insertSch_ :: forall (ann :: Ann) -> forall r. InsertNonReturning ann r => Connection -> [r] -> IO (Int64, Text) Source #

Insert records into a table without RETURNING.

insertText :: forall (ann :: Ann) -> forall r r' s. (CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s) => s Source #

Construct SQL text for inserting records into a table and returning some fields.

insertText_ :: forall (ann :: Ann) -> forall r s. (IsString s, Monoid s, CRecInfo ann r) => s Source #

Construct SQL text for inserting records into a table without RETURNING.

type family AllPlain (ann :: Ann) r where ... Source #

All fields are plain (no RFToHere/RFFromHere)

Equations

AllPlain ann r = Assert (AllPlainCols (Cols ann r)) (TypeError ((('Text "Not all fields in record are 'plain' (no relations allowed)." ':$$: ('Text "Ann: " ':<>: 'ShowType ann)) ':$$: ('Text "Type: " ':<>: 'ShowType r)) ':$$: ('Text "Cols: " ':<>: 'ShowType (Cols ann r))) :: Constraint) 

type InsertNonReturning (ann :: Ann) r = (PlainIn ann r, CheckAllMandatory ann (ColsDbNames (Cols ann r))) Source #

Plain insert without RETURNING. Check that all fields belong to the root table and all mandatory fields are present.

type InsertReturning (ann :: Ann) r r' = (InsertNonReturning ann r, PlainOut ann r') Source #

Plain insert with RETURNING. Check that all inserted and returned fields belong to the root table and all mandatory fields are present.

Update

updateByCond :: forall (ren :: Renamer) sch (d :: Nat) (t :: NameNSK). forall (ann :: Ann) -> forall r r'. (ann ~ 'Ann ren sch d t, UpdateReturning ann r r') => Connection -> r -> Cond sch t -> IO [r'] Source #

Update rows matching a condition; the result type selects which columns are returned.

updateByCond_ :: forall (ren :: Renamer) sch (d :: Nat) (t :: NameNSK). forall (ann :: Ann) -> forall r. (ann ~ 'Ann ren sch d t, UpdateNonReturning ann r) => Connection -> r -> Cond sch t -> IO Int64 Source #

Update records by condition without RETURNING.

updateText :: forall (ren :: Renamer) sch (d :: Nat) (t :: NameNSK). forall (ann :: Ann) -> forall r r' s. (CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s, ann ~ 'Ann ren sch d t) => Cond sch t -> (s, [SomeToField]) Source #

Construct SQL text for updating records by condition and returning some fields.

updateText_ :: forall sch (t :: NameNSK). forall (ann :: Ann) -> forall r s. (IsString s, Monoid s, CRecInfo ann r) => Cond sch t -> (s, [SomeToField]) Source #

Construct SQL text for updating records by condition without RETURNING.

type UpdateReturning (ann :: Ann) r r' = (UpdateNonReturning ann r, PlainOut ann r') Source #

Plain update with RETURNING. Check that all updated and returned fields belong to the root table.

type UpdateNonReturning (ann :: Ann) r = PlainIn ann r Source #

Plain update without RETURNING. Check that all updated fields belong to the root table.

class CRecInfo (ann :: Ann) r where Source #

Methods

getRecordInfo :: RecordInfo Text Source #

Instances

Instances details
(ann ~ 'Ann ren sch d tab, SingI tab, cols ~ Cols ann r, CRecInfoCols ann cols) => CRecInfo ann r Source # 
Instance details

Defined in PgSchema.Ann

Methods

getRecordInfo :: RecordInfo Text Source #

Tree-base Insert/Upsert

insertJSON :: forall (ann :: Ann) -> forall r r'. InsertTreeReturning ann r r' => Connection -> [r] -> IO ([r'], Text) Source #

Insert records into a table and its children using JSON data internally.

Like upsertJSON, but requires all mandatory columns at every node (insert-only constraint).

insertJSON_ :: forall (ann :: Ann) -> forall r. InsertTreeNonReturning ann r => Connection -> [r] -> IO Text Source #

Like insertJSON, but does not return rows.

upsertJSON :: forall (ann :: Ann) -> forall r r'. UpsertTreeReturning ann r r' => Connection -> [r] -> IO ([r'], Text) Source #

Upsert a forest of rows into the root table and its child tables in one round-trip, using JSON inside PostgreSQL (same pipeline as insertJSON).

Input shape (r): a record tree that may contain the root table’s columns and nested child branches (one-to-many from the root downward). There are no nested parent branches: parent keys are implied by the tree you send, not by embedding parent rows inside children.

Output shape (r'): a record tree whose graph of nested tables is a subgraph of the input: the same tables can appear, but you choose which columns (and which levels) appear in the result—whatever is available through the generated RETURNING/result projection. Field sets may differ from r; relation structure cannot grow beyond what you sent in.

What to supply at each node: at every level, each row must either include all mandatory columns (for columns that are mandatory in the schema /sense of this API/) or, alternatively, enough primary-key columns to identify an existing row. Foreign-key columns that are filled in by the parent level (for example after an auto-generated id on insert) do not need to be present on the child payload.

Insert vs update vs upsert per row: the engine picks one of INSERT, UPDATE, or UPSERT from the keys and mandatory fields you provide:

  • all mandatory fields present and no primary key → INSERT
  • primary key present, not all mandatory fields → UPDATE
  • primary key present and all mandatory fields → UPSERT

insertJSON is the same execution path but adds a stricter type-level constraint: every mandatory field must be present (pure inserts). upsertJSON relaxes that so updates and upserts are expressible as in the rules above.

upsertJSON_ :: forall (ann :: Ann) -> forall r. UpsertTreeNonReturning ann r => Connection -> [r] -> IO Text Source #

Like upsertJSON, but does not return rows.

insertJSONText :: forall (ann :: Ann) -> forall r r'. (TreeSch ann, CRecInfo ann r, CRecInfo ann r', IsString s, Monoid s, Ord s) => s Source #

insertJSONText_ :: forall (ann :: Ann) -> forall r s. (IsString s, Monoid s, Ord s, TreeSch ann, CRecInfo ann r) => s Source #

type TreeIn (ann :: Ann) r = (CRecInfo ann r, ToJSON (PgTag ann r)) Source #

type TreeOut (ann :: Ann) r' = (CRecInfo ann r', FromJSON (PgTag ann r'), Typeable ann, Typeable r') Source #

type family AllMandatoryTree (ann :: Ann) r (rFlds :: [Symbol]) where ... Source #

Equations

AllMandatoryTree ann [r] rFlds = AllMandatoryTree ann r rFlds 
AllMandatoryTree ann r rFlds = WalkLevelAnn CheckAllMandatorySym0 ann (TRecordInfo ann r) rFlds 

type family AllMandatoryOrHasPKTree (ann :: Ann) r (rFlds :: [Symbol]) where ... Source #

Equations

AllMandatoryOrHasPKTree ann [r] rFlds = AllMandatoryOrHasPKTree ann r rFlds 
AllMandatoryOrHasPKTree ann r rFlds = WalkLevelAnn CheckAllMandatoryOrHasPKSym0 ann (TRecordInfo ann r) rFlds 

type TreeSch (ann :: Ann) = CSchema (AnnSch ann) Source #

type InsertTreeNonReturning (ann :: Ann) r = (TreeSch ann, TreeIn ann r, AllMandatoryTree ann r ('[] :: [Symbol])) Source #

Insert tree without RETURNING.

Check that all mandatory fields are present in all tables in tree. Reference fields in the child tables are not checked - they are inserted automatically.

type InsertTreeReturning (ann :: Ann) r r' = (InsertTreeNonReturning ann r, TreeOut ann r', ReturningIsSubtree ann r r') Source #

Insert tree with RETURNING.

Check that all mandatory fields are present in all tables in tree. Reference fields in the child tables are not checked - they are inserted automatically.

It also checks that we get returnings only from the tables we inserted into.

type UpsertTreeNonReturning (ann :: Ann) r = (TreeSch ann, TreeIn ann r, AllMandatoryOrHasPKTree ann r ('[] :: [Symbol])) Source #

Upsert tree without RETURNING.

Check that all mandatory fields or primary keys are present in all tables in tree. Reference fields in the child tables are not checked - they are inserted automatically.

type UpsertTreeReturning (ann :: Ann) r r' = (UpsertTreeNonReturning ann r, TreeOut ann r', ReturningIsSubtree ann r r') Source #

Upsert tree with RETURNING.

Check that all mandatory fields or primary keys are present in all tables in tree. Reference fields in the child tables are not checked - they are inserted automatically.

It also checks that we get returnings only from the tables we upserted into.

type family TRecordInfo (ann :: Ann) r :: [FieldInfo Symbol] where ... Source #

Equations

TRecordInfo ann r = TRecordInfoCols ann (Cols ann r) 

Delete

deleteByCond :: forall sch (t :: NameNSK) -> SingI t => Connection -> Cond sch t -> IO (Int64, (Text, [SomeToField])) Source #

Delete records in table by condition.

deleteText :: forall sch (t :: NameNSK) s. (IsString s, Monoid s, SingI t) => Cond sch t -> (s, [SomeToField]) Source #

Construct SQL text for deleting records by condition.

Types

data Ann Source #

Type-level annotation: enforce constraints at compile time and drive demoted types used to generate correct SQL. annRen and annSch are fixed for the whole DML-operation. annDepth and annTab are changed while traversing the structure of the ADT.

Constructors

Ann 

Fields

  • annRen :: Renamer

    Renamer to convert Haskell names to database names.

  • annSch :: Type

    Schema with tables, relations and types.

  • annDepth :: Nat

    Depth of the nested relations. It is mostly used to prevent cycles in types.

  • annTab :: NameNSK

    Name of the root table.

Instances

Instances details
(FromJSON (PgTag ann r), Typeable ann, Typeable r) => FromField [PgTag ann r] Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromField :: FieldParser [PgTag ann r] #

ToJSON (PgTag ann r) => ToField [PgTag ann r] Source # 
Instance details

Defined in PgSchema.Ann

Methods

toField :: [PgTag ann r] -> Action #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, FromJSONCols ann colsCase cols r) => FromJSON (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

parseJSON :: Value -> Parser (PgTag ann r) #

parseJSONList :: Value -> Parser [PgTag ann r] #

omittedField :: Maybe (PgTag ann r) #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, ToJSONCols ann colsCase cols r) => ToJSON (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toJSON :: PgTag ann r -> Value #

toEncoding :: PgTag ann r -> Encoding #

toJSONList :: [PgTag ann r] -> Value #

toEncodingList :: [PgTag ann r] -> Encoding #

omitField :: PgTag ann r -> Bool #

(FromJSON (PgTag ann r), Typeable ann, Typeable r) => FromField (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromField :: FieldParser (PgTag ann r) #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, FromRowCols ann colsCase cols r) => FromRow (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromRow :: RowParser (PgTag ann r) #

ToJSON (PgTag ann r) => ToField (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toField :: PgTag ann r -> Action #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, ToRowCols ann colsCase cols r) => ToRow (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toRow :: PgTag ann r -> [Action] #

type ToStar (a :: k) = (SingKind (KindOf a), SingI a) Source #

Renamers

data RenamerId (a :: TyFun Symbol Symbol) Source #

Renamer that does not change the symbol.

Instances

Instances details
type ApplyRenamer RenamerId s Source # 
Instance details

Defined in PgSchema.Ann

type CamelToSnake (s :: Symbol) = CamelToSnakeInternal (UnconsSymbol s) Source #

Closed type family to convert CamelCase to snake_case that can be used in Renamer.

>>> import Data.Proxy
>>> symbolVal (Proxy @(CamelToSnake TESTCamelTo_snake_Case))
"t_e_s_t_camel_to_snake__case"

type Renamer = Symbol ~> Symbol Source #

Renamer is a type-level function from Symbol to Symbol.

type family ApplyRenamer (renamer :: Renamer) (s :: Symbol) :: Symbol Source #

Apply renamer to symbol.

Like Apply but specialized for Symbol.

To make your own Renamer, typically you make

  • data MyRenamer :: Renamer
  • closed type family: `type family MyRenamerImpl (s :: Symbol) :: Symbol where ... `
  • type instance ApplyRenamer MyRenamer s = MyRenamerImpl s

Instances

Instances details
type ApplyRenamer RenamerId s Source # 
Instance details

Defined in PgSchema.Ann

PgTag types

type (:=) (s :: k) t = PgTag s t infixr 5 Source #

(=:) :: forall (a :: k) -> b -> a := b infixr 5 Source #

newtype PgTag (s :: k) t Source #

Annotates a value with schema/type information for DML codecs.

You can describe rows in two ways:

  1. Ordinary Haskell records with a Generic instance.
  2. Symbol-labelled rows built from (=:) and chained with (:.) from postgresql-simple (re-exported from PgSchema.DML).

PgTag is analogous to Tagged from the tagged package, but carries JSON (and related) instances suited to pg-schema.

Both representations can be mixed in one row.

Two pieces of syntax cooperate with PgTag:

  • (=:) builds a PgTag value (field name + payload). RequiredTypeArguments lets you avoid noisy explicit type application on the field name: you write "name" =: John instead of @"name" =: John.
  • (:=) is the type-level spelling of the same idea (see the (:=) type synonym below).

Constructors

PgTag 

Fields

Instances

Instances details
(FromJSON (PgTag ann r), Typeable ann, Typeable r) => FromField [PgTag ann r] Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromField :: FieldParser [PgTag ann r] #

ToJSON (PgTag ann r) => ToField [PgTag ann r] Source # 
Instance details

Defined in PgSchema.Ann

Methods

toField :: [PgTag ann r] -> Action #

Functor (PgTag s) Source # 
Instance details

Defined in PgSchema.Types

Methods

fmap :: (a -> b) -> PgTag s a -> PgTag s b #

(<$) :: a -> PgTag s b -> PgTag s a #

Foldable (PgTag s) Source # 
Instance details

Defined in PgSchema.Types

Methods

fold :: Monoid m => PgTag s m -> m #

foldMap :: Monoid m => (a -> m) -> PgTag s a -> m #

foldMap' :: Monoid m => (a -> m) -> PgTag s a -> m #

foldr :: (a -> b -> b) -> b -> PgTag s a -> b #

foldr' :: (a -> b -> b) -> b -> PgTag s a -> b #

foldl :: (b -> a -> b) -> b -> PgTag s a -> b #

foldl' :: (b -> a -> b) -> b -> PgTag s a -> b #

foldr1 :: (a -> a -> a) -> PgTag s a -> a #

foldl1 :: (a -> a -> a) -> PgTag s a -> a #

toList :: PgTag s a -> [a] #

null :: PgTag s a -> Bool #

length :: PgTag s a -> Int #

elem :: Eq a => a -> PgTag s a -> Bool #

maximum :: Ord a => PgTag s a -> a #

minimum :: Ord a => PgTag s a -> a #

sum :: Num a => PgTag s a -> a #

product :: Num a => PgTag s a -> a #

Traversable (PgTag s) Source # 
Instance details

Defined in PgSchema.Types

Methods

traverse :: Applicative f => (a -> f b) -> PgTag s a -> f (PgTag s b) #

sequenceA :: Applicative f => PgTag s (f a) -> f (PgTag s a) #

mapM :: Monad m => (a -> m b) -> PgTag s a -> m (PgTag s b) #

sequence :: Monad m => PgTag s (m a) -> m (PgTag s a) #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, FromJSONCols ann colsCase cols r) => FromJSON (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

parseJSON :: Value -> Parser (PgTag ann r) #

parseJSONList :: Value -> Parser [PgTag ann r] #

omittedField :: Maybe (PgTag ann r) #

FromJSON a => FromJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, ToJSONCols ann colsCase cols r) => ToJSON (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toJSON :: PgTag ann r -> Value #

toEncoding :: PgTag ann r -> Encoding #

toJSONList :: [PgTag ann r] -> Value #

toEncodingList :: [PgTag ann r] -> Encoding #

omitField :: PgTag ann r -> Bool #

ToJSON a => ToJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: PgTag s (PgArr a) -> Value #

toEncoding :: PgTag s (PgArr a) -> Encoding #

toJSONList :: [PgTag s (PgArr a)] -> Value #

toEncodingList :: [PgTag s (PgArr a)] -> Encoding #

omitField :: PgTag s (PgArr a) -> Bool #

Monoid t => Monoid (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Methods

mempty :: PgTag s t #

mappend :: PgTag s t -> PgTag s t -> PgTag s t #

mconcat :: [PgTag s t] -> PgTag s t #

Semigroup t => Semigroup (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Methods

(<>) :: PgTag s t -> PgTag s t -> PgTag s t #

sconcat :: NonEmpty (PgTag s t) -> PgTag s t #

stimes :: Integral b => b -> PgTag s t -> PgTag s t #

Read t => Read (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Show t => Show (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Methods

showsPrec :: Int -> PgTag s t -> ShowS #

show :: PgTag s t -> String #

showList :: [PgTag s t] -> ShowS #

Eq t => Eq (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: PgTag s t -> PgTag s t -> Bool #

(/=) :: PgTag s t -> PgTag s t -> Bool #

Ord t => Ord (PgTag s t) Source # 
Instance details

Defined in PgSchema.Types

Methods

compare :: PgTag s t -> PgTag s t -> Ordering #

(<) :: PgTag s t -> PgTag s t -> Bool #

(<=) :: PgTag s t -> PgTag s t -> Bool #

(>) :: PgTag s t -> PgTag s t -> Bool #

(>=) :: PgTag s t -> PgTag s t -> Bool #

max :: PgTag s t -> PgTag s t -> PgTag s t #

min :: PgTag s t -> PgTag s t -> PgTag s t #

(FromJSON (PgTag ann r), Typeable ann, Typeable r) => FromField (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromField :: FieldParser (PgTag ann r) #

(FromField a, Typeable a) => FromField (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

fromField :: FieldParser (PgTag s (PgArr a)) #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, FromRowCols ann colsCase cols r) => FromRow (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

fromRow :: RowParser (PgTag ann r) #

ToJSON (PgTag ann r) => ToField (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toField :: PgTag ann r -> Action #

(ToField a, ToStar s) => ToField (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PgTag s (PgArr a) -> Action #

(cols ~ Cols ann r, colsCase ~ ColsCaseOf r, ToRowCols ann colsCase cols r) => ToRow (PgTag ann r) Source # 
Instance details

Defined in PgSchema.Ann

Methods

toRow :: PgTag ann r -> [Action] #

Re-export from postgresql-simple

data h :. t infixr 3 #

A composite type to parse your custom data structures without having to define dummy newtype wrappers every time.

instance FromRow MyData where ...
instance FromRow MyData2 where ...

then I can do the following for free:

res <- query' c "..."
forM res $ \(MyData{..} :. MyData2{..}) -> do
  ....

Constructors

h :. t infixr 3 

Instances

Instances details
(Read h, Read t) => Read (h :. t) # 
Instance details

Defined in Database.PostgreSQL.Simple.Types

Methods

readsPrec :: Int -> ReadS (h :. t) #

readList :: ReadS [h :. t] #

readPrec :: ReadPrec (h :. t) #

readListPrec :: ReadPrec [h :. t] #

(Show h, Show t) => Show (h :. t) # 
Instance details

Defined in Database.PostgreSQL.Simple.Types

Methods

showsPrec :: Int -> (h :. t) -> ShowS #

show :: (h :. t) -> String #

showList :: [h :. t] -> ShowS #

(Eq h, Eq t) => Eq (h :. t) # 
Instance details

Defined in Database.PostgreSQL.Simple.Types

Methods

(==) :: (h :. t) -> (h :. t) -> Bool #

(/=) :: (h :. t) -> (h :. t) -> Bool #

(Ord h, Ord t) => Ord (h :. t) # 
Instance details

Defined in Database.PostgreSQL.Simple.Types

Methods

compare :: (h :. t) -> (h :. t) -> Ordering #

(<) :: (h :. t) -> (h :. t) -> Bool #

(<=) :: (h :. t) -> (h :. t) -> Bool #

(>) :: (h :. t) -> (h :. t) -> Bool #

(>=) :: (h :. t) -> (h :. t) -> Bool #

max :: (h :. t) -> (h :. t) -> h :. t #

min :: (h :. t) -> (h :. t) -> h :. t #

(FromRow a, FromRow b) => FromRow (a :. b) # 
Instance details

Defined in Database.PostgreSQL.Simple.FromRow

Methods

fromRow :: RowParser (a :. b) #

(ToRow a, ToRow b) => ToRow (a :. b) # 
Instance details

Defined in Database.PostgreSQL.Simple.ToRow

Methods

toRow :: (a :. b) -> [Action] #

Enum

data family PGEnum sch (name :: NameNSK) Source #

Introduce enum database types. Data instances are produced by schema generation. You can use these data instances in you records to SELECTINSERTUPSERT data

Instances

Instances details
(Read (PGEnum sch t), ToStar t) => FromJSON (PGEnum sch t) Source # 
Instance details

Defined in PgSchema.Types

Methods

parseJSON :: Value -> Parser (PGEnum sch t) #

parseJSONList :: Value -> Parser [PGEnum sch t] #

omittedField :: Maybe (PGEnum sch t) #

(Show (PGEnum sch t), ToStar t) => ToJSON (PGEnum sch t) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: PGEnum sch t -> Value #

toEncoding :: PGEnum sch t -> Encoding #

toJSONList :: [PGEnum sch t] -> Value #

toEncodingList :: [PGEnum sch t] -> Encoding #

omitField :: PGEnum sch t -> Bool #

(Read (PGEnum sch n), ToStar n, Typeable sch, Typeable n) => FromField (PGEnum sch n) Source # 
Instance details

Defined in PgSchema.Types

Methods

fromField :: FieldParser (PGEnum sch n) #

(Show (PGEnum sch n), ToStar n) => ToField (PGEnum sch n) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PGEnum sch n -> Action #

type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n)

Aggregates

newtype Aggr' (f :: AggrFun) t Source #

All aggregate functions except count can return NULL. But if field under aggregate is mandatory they return NULL only on empty set if there is no group by clause. E.g. `select min(a) from t where false` So we require Nullable for Aggr.

Aggr' is like Aggr but cannot be used in SELECT without `group by`. So it is mandatory if field is mandatory.

Constructors

Aggr' 

Fields

Instances

Instances details
FromJSON t => FromJSON (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

ToJSON t => ToJSON (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: Aggr' f t -> Value #

toEncoding :: Aggr' f t -> Encoding #

toJSONList :: [Aggr' f t] -> Value #

toEncodingList :: [Aggr' f t] -> Encoding #

omitField :: Aggr' f t -> Bool #

Show t => Show (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

showsPrec :: Int -> Aggr' f t -> ShowS #

show :: Aggr' f t -> String #

showList :: [Aggr' f t] -> ShowS #

Eq t => Eq (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: Aggr' f t -> Aggr' f t -> Bool #

(/=) :: Aggr' f t -> Aggr' f t -> Bool #

Ord t => Ord (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

compare :: Aggr' f t -> Aggr' f t -> Ordering #

(<) :: Aggr' f t -> Aggr' f t -> Bool #

(<=) :: Aggr' f t -> Aggr' f t -> Bool #

(>) :: Aggr' f t -> Aggr' f t -> Bool #

(>=) :: Aggr' f t -> Aggr' f t -> Bool #

max :: Aggr' f t -> Aggr' f t -> Aggr' f t #

min :: Aggr' f t -> Aggr' f t -> Aggr' f t #

FromField t => FromField (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

fromField :: FieldParser (Aggr' f t) #

ToField t => ToField (Aggr' f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: Aggr' f t -> Action #

newtype Aggr (f :: AggrFun) t Source #

Introduce aggregate functions.

I.e. "fld" := Aggr AMin (Maybe Int32) means "minimum value of the field fld"

Aggr requires a Maybe argument for all functions except count.

Only a small set of aggregations are supported currently: count, min, max, sum, avg.

Constructors

Aggr 

Fields

Instances

Instances details
FromJSON t => FromJSON (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

parseJSON :: Value -> Parser (Aggr f t) #

parseJSONList :: Value -> Parser [Aggr f t] #

omittedField :: Maybe (Aggr f t) #

ToJSON t => ToJSON (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: Aggr f t -> Value #

toEncoding :: Aggr f t -> Encoding #

toJSONList :: [Aggr f t] -> Value #

toEncodingList :: [Aggr f t] -> Encoding #

omitField :: Aggr f t -> Bool #

Show t => Show (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

showsPrec :: Int -> Aggr f t -> ShowS #

show :: Aggr f t -> String #

showList :: [Aggr f t] -> ShowS #

Eq t => Eq (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: Aggr f t -> Aggr f t -> Bool #

(/=) :: Aggr f t -> Aggr f t -> Bool #

Ord t => Ord (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

compare :: Aggr f t -> Aggr f t -> Ordering #

(<) :: Aggr f t -> Aggr f t -> Bool #

(<=) :: Aggr f t -> Aggr f t -> Bool #

(>) :: Aggr f t -> Aggr f t -> Bool #

(>=) :: Aggr f t -> Aggr f t -> Bool #

max :: Aggr f t -> Aggr f t -> Aggr f t #

min :: Aggr f t -> Aggr f t -> Aggr f t #

FromField t => FromField (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

fromField :: FieldParser (Aggr f t) #

ToField t => ToField (Aggr f t) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: Aggr f t -> Action #

data AggrFun Source #

Supported SQL aggregate functions

Constructors

ACount 
AMin 
AMax 
ASum 
AAvg 

Instances

Instances details
Show AggrFun Source # 
Instance details

Defined in PgSchema.Schema

SingKind AggrFun Source # 
Instance details

Defined in PgSchema.Schema

Associated Types

type Demote AggrFun 
Instance details

Defined in PgSchema.Schema

Methods

fromSing :: forall (a :: AggrFun). Sing a -> Demote AggrFun #

toSing :: Demote AggrFun -> SomeSing AggrFun #

SingI 'AAvg Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing 'AAvg #

SingI 'ACount Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing 'ACount #

SingI 'AMax Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing 'AMax #

SingI 'AMin Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing 'AMin #

SingI 'ASum Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing 'ASum #

SingI n => SingI2 ('RFAggr n :: AggrFun -> Bool -> RecField' s p) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: AggrFun) (y :: Bool). Sing x -> Sing y -> Sing ('RFAggr n x y :: RecField' s p) #

type Demote AggrFun Source # 
Instance details

Defined in PgSchema.Schema

type Sing Source # 
Instance details

Defined in PgSchema.Schema

type Sing

Arrays

newtype PgArr a Source #

PGArray has no JSON instances. '[]' has JSON, but no PG instances. This one has both.

Use this type to work with arrays in database.

All elements are Maybe because PostgreSQL does not guarantee that all elements are present. PgTag typeName PgArr can be safely converted to ToField with type information (e.g. val::int[]). This instance is used internally in the generation of SQL.

Constructors

PgArr 

Fields

Instances

Instances details
FromJSON a => FromJSON (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

ToJSON a => ToJSON (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Monoid (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Methods

mempty :: PgArr a #

mappend :: PgArr a -> PgArr a -> PgArr a #

mconcat :: [PgArr a] -> PgArr a #

Semigroup (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Methods

(<>) :: PgArr a -> PgArr a -> PgArr a #

sconcat :: NonEmpty (PgArr a) -> PgArr a #

stimes :: Integral b => b -> PgArr a -> PgArr a #

Read a => Read (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Show a => Show (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Methods

showsPrec :: Int -> PgArr a -> ShowS #

show :: PgArr a -> String #

showList :: [PgArr a] -> ShowS #

Eq a => Eq (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: PgArr a -> PgArr a -> Bool #

(/=) :: PgArr a -> PgArr a -> Bool #

Ord a => Ord (PgArr a) Source # 
Instance details

Defined in PgSchema.Types

Methods

compare :: PgArr a -> PgArr a -> Ordering #

(<) :: PgArr a -> PgArr a -> Bool #

(<=) :: PgArr a -> PgArr a -> Bool #

(>) :: PgArr a -> PgArr a -> Bool #

(>=) :: PgArr a -> PgArr a -> Bool #

max :: PgArr a -> PgArr a -> PgArr a #

min :: PgArr a -> PgArr a -> PgArr a #

FromJSON a => FromJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

ToJSON a => ToJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: PgTag s (PgArr a) -> Value #

toEncoding :: PgTag s (PgArr a) -> Encoding #

toJSONList :: [PgTag s (PgArr a)] -> Value #

toEncodingList :: [PgTag s (PgArr a)] -> Encoding #

omitField :: PgTag s (PgArr a) -> Bool #

(FromField a, Typeable a) => FromField (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

fromField :: FieldParser (PgTag s (PgArr a)) #

(ToField a, ToStar s) => ToField (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PgTag s (PgArr a) -> Action #

type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) = CanConvert1 sch tab fld n (TTypDef sch n) t

pgArr' :: [a] -> PgArr a Source #

Make PgArr from list. All elements are lifted to Maybe

unPgArr' :: PgArr a -> [a] Source #

Make list from PgArr. All empty (Nothing) elements are omitted.

Conversion checks

type family CanConvert sch (tab :: NameNSK) (fld :: Symbol) (fd :: FldDefK) t where ... Source #

Closed type family to check that field can be converted to or from Haskell type. To make your types convertible to some database type use open type family CanConvert1.

Equations

CanConvert sch tab fld fd t = CanConvertMaybe sch tab fld (FdType fd) (FdNullable fd) (TTypDef sch (FdType fd)) t 

type family CanConvert1 sch (tab :: NameNSK) (fld :: Symbol) (tn :: NameNSK) (td :: TypDefK) t Source #

Open mapping from a PostgreSQL type (non-nullable) to a Haskell type. Add your own equations to this family to support extra pairings.

Instances

Instances details
type CanConvert1 sch tab fld tn ('TypDef "B" x y) Bool Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld tn ('TypDef "B" x y) Bool = ()
type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) = CanConvert1 sch tab fld n (TTypDef sch n) t
type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n)
type CanConvert1 sch tab fld (PGC "char") ('TypDef "S" x y) PgChar Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "char") ('TypDef "S" x y) PgChar = ()
type CanConvert1 sch tab fld (PGC "date") ('TypDef "D" x y) Day Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "date") ('TypDef "D" x y) Day = ()
type CanConvert1 sch tab fld (PGC "float4") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "float4") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "float4") ('TypDef "N" x y) Double Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "float4") ('TypDef "N" x y) Double = ()
type CanConvert1 sch tab fld (PGC "float8") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "float8") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "float8") ('TypDef "N" x y) Double Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "float8") ('TypDef "N" x y) Double = ()
type CanConvert1 sch tab fld (PGC "int2") ('TypDef "N" x y) Int16 Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int2") ('TypDef "N" x y) Int16 = ()
type CanConvert1 sch tab fld (PGC "int2") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int2") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "int4") ('TypDef "N" x y) Int32 Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int4") ('TypDef "N" x y) Int32 = ()
type CanConvert1 sch tab fld (PGC "int4") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int4") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "int8") ('TypDef "N" x y) Int64 Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int8") ('TypDef "N" x y) Int64 = ()
type CanConvert1 sch tab fld (PGC "int8") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "int8") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "json") ('TypDef "U" x y) a Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "json") ('TypDef "U" x y) a = (FromJSON a, ToJSON a)
type CanConvert1 sch tab fld (PGC "jsonb") ('TypDef "U" x y) a Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "jsonb") ('TypDef "U" x y) a = (FromJSON a, ToJSON a)
type CanConvert1 sch tab fld (PGC "name") ('TypDef "S" x y) Text Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "name") ('TypDef "S" x y) Text = ()
type CanConvert1 sch tab fld (PGC "numeric") ('TypDef "N" x y) Scientific Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "numeric") ('TypDef "N" x y) Scientific = ()
type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) PgOid Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) PgOid = ()
type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) Int Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) Int = ()
type CanConvert1 sch tab fld (PGC "text") ('TypDef "S" x y) Text Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "text") ('TypDef "S" x y) Text = ()
type CanConvert1 sch tab fld (PGC "time") ('TypDef "D" x y) TimeOfDay Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "time") ('TypDef "D" x y) TimeOfDay = ()
type CanConvert1 sch tab fld (PGC "timestamp") ('TypDef "D" x y) LocalTime Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "timestamp") ('TypDef "D" x y) LocalTime = ()
type CanConvert1 sch tab fld (PGC "timestamptz") ('TypDef "D" x y) UTCTime Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "timestamptz") ('TypDef "D" x y) UTCTime = ()
type CanConvert1 sch tab fld (PGC "timestamptz") ('TypDef "D" x y) ZonedTime Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "timestamptz") ('TypDef "D" x y) ZonedTime = ()
type CanConvert1 sch tab fld (PGC "uuid") ('TypDef "U" x y) UUID Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "uuid") ('TypDef "U" x y) UUID = ()
type CanConvert1 sch tab fld (PGC "varchar") ('TypDef "S" x y) Text Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "varchar") ('TypDef "S" x y) Text = ()
type CanConvert1 sch tab fld (PGC "bytea") ('TypDef "U" x y) (Binary ByteString) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "bytea") ('TypDef "U" x y) (Binary ByteString) = ()
type CanConvert1 sch tab fld (PGC "bytea") ('TypDef "U" x y) (Binary ByteString) Source #

Binary ByteString has no FromJSON/ToJSON instances, so it can be used only in the root table.

Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "bytea") ('TypDef "U" x y) (Binary ByteString) = ()
type CanConvert1 sch tab fld (PGC "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) = ()
type CanConvert1 sch tab fld (PGC "numeric") ('TypDef "N" x y) (Fixed k2) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "numeric") ('TypDef "N" x y) (Fixed k2) = ()
type CanConvert1 sch tab fld ("public" ->> "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld ("public" ->> "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) = ()

data TypDef' s Source #

Description of a PostgreSQL type (category, array element, enum labels).

Constructors

TypDef 

Fields

Instances

Instances details
Show s => Show (TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

showsPrec :: Int -> TypDef' s -> ShowS #

show :: TypDef' s -> String #

showList :: [TypDef' s] -> ShowS #

SingKind s => SingKind (TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Associated Types

type Demote (TypDef' s) 
Instance details

Defined in PgSchema.Schema

type Demote (TypDef' s) = TypDef' (Demote s)

Methods

fromSing :: forall (a :: TypDef' s). Sing a -> Demote (TypDef' s) #

toSing :: Demote (TypDef' s) -> SomeSing (TypDef' s) #

SingI n => SingI2 ('TypDef n :: Maybe (NameNS' s) -> [s] -> TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: Maybe (NameNS' s)) (y :: [s]). Sing x -> Sing y -> Sing ('TypDef n x y) #

(SingI n1, SingI n2) => SingI1 ('TypDef n1 n2 :: [s] -> TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing :: forall (x :: [s]). Sing x -> Sing ('TypDef n1 n2 x) #

(SingI n1, SingI n2, SingI n3) => SingI ('TypDef n1 n2 n3 :: TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing ('TypDef n1 n2 n3) #

type Demote (TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

type Demote (TypDef' s) = TypDef' (Demote s)
type Sing Source # 
Instance details

Defined in PgSchema.Schema

type Sing

Other types

newtype PgChar Source #

Char has no ToField instance; this is a custom wrapper.

Constructors

PgChar 

Fields

Instances

Instances details
FromJSON PgChar Source # 
Instance details

Defined in PgSchema.Types

ToJSON PgChar Source # 
Instance details

Defined in PgSchema.Types

Bounded PgChar Source # 
Instance details

Defined in PgSchema.Types

Enum PgChar Source # 
Instance details

Defined in PgSchema.Types

Read PgChar Source # 
Instance details

Defined in PgSchema.Types

Show PgChar Source # 
Instance details

Defined in PgSchema.Types

Eq PgChar Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: PgChar -> PgChar -> Bool #

(/=) :: PgChar -> PgChar -> Bool #

Ord PgChar Source # 
Instance details

Defined in PgSchema.Types

FromField PgChar Source # 
Instance details

Defined in PgSchema.Types

ToField PgChar Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PgChar -> Action #

type CanConvert1 sch tab fld (PGC "char") ('TypDef "S" x y) PgChar Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "char") ('TypDef "S" x y) PgChar = ()

newtype PgOid Source #

Oid but with JSON instances

Constructors

PgOid 

Fields

Instances

Instances details
FromJSON PgOid Source # 
Instance details

Defined in PgSchema.Types

ToJSON PgOid Source # 
Instance details

Defined in PgSchema.Types

Read PgOid Source # 
Instance details

Defined in PgSchema.Types

Show PgOid Source # 
Instance details

Defined in PgSchema.Types

Methods

showsPrec :: Int -> PgOid -> ShowS #

show :: PgOid -> String #

showList :: [PgOid] -> ShowS #

Eq PgOid Source # 
Instance details

Defined in PgSchema.Types

Methods

(==) :: PgOid -> PgOid -> Bool #

(/=) :: PgOid -> PgOid -> Bool #

FromField PgOid Source # 
Instance details

Defined in PgSchema.Types

ToField PgOid Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PgOid -> Action #

type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) PgOid Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "oid") ('TypDef "N" x y) PgOid = ()

data NameNS' s Source #

Qualified PostgreSQL name: namespace (schema) + local name.

Constructors

NameNS 

Fields

  • nnsNamespace :: s

    Namespace (database schema), e.g. public or pg_catalog.

  • nnsName :: s

    Unqualified table relation type name.

Instances

Instances details
SingI2 ('NameNS :: k2 -> k2 -> NameNS' k2) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: k2) (y :: k2). Sing x -> Sing y -> Sing ('NameNS x y) #

SingI n => SingI1 ('NameNS n :: s -> NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing :: forall (x :: s). Sing x -> Sing ('NameNS n x) #

Show s => Show (NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

showsPrec :: Int -> NameNS' s -> ShowS #

show :: NameNS' s -> String #

showList :: [NameNS' s] -> ShowS #

Eq s => Eq (NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

(==) :: NameNS' s -> NameNS' s -> Bool #

(/=) :: NameNS' s -> NameNS' s -> Bool #

Ord s => Ord (NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

compare :: NameNS' s -> NameNS' s -> Ordering #

(<) :: NameNS' s -> NameNS' s -> Bool #

(<=) :: NameNS' s -> NameNS' s -> Bool #

(>) :: NameNS' s -> NameNS' s -> Bool #

(>=) :: NameNS' s -> NameNS' s -> Bool #

max :: NameNS' s -> NameNS' s -> NameNS' s #

min :: NameNS' s -> NameNS' s -> NameNS' s #

SingKind s => SingKind (NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Associated Types

type Demote (NameNS' s) 
Instance details

Defined in PgSchema.Schema

type Demote (NameNS' s) = NameNS' (Demote s)

Methods

fromSing :: forall (a :: NameNS' s). Sing a -> Demote (NameNS' s) #

toSing :: Demote (NameNS' s) -> SomeSing (NameNS' s) #

SingI n => SingI2 ('RelDef n :: NameNS' s -> [(s, s)] -> RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: NameNS' s) (y :: [(s, s)]). Sing x -> Sing y -> Sing ('RelDef n x y) #

SingI n => SingI2 ('TypDef n :: Maybe (NameNS' s) -> [s] -> TypDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: Maybe (NameNS' s)) (y :: [s]). Sing x -> Sing y -> Sing ('TypDef n x y) #

(SingI n1, SingI n2) => SingI ('NameNS n1 n2 :: NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing ('NameNS n1 n2) #

FromJSON a => FromJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

ToJSON a => ToJSON (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toJSON :: PgTag s (PgArr a) -> Value #

toEncoding :: PgTag s (PgArr a) -> Encoding #

toJSONList :: [PgTag s (PgArr a)] -> Value #

toEncodingList :: [PgTag s (PgArr a)] -> Encoding #

omitField :: PgTag s (PgArr a) -> Bool #

(ToField a, ToStar s) => ToField (PgTag s (PgArr a)) Source # 
Instance details

Defined in PgSchema.Types

Methods

toField :: PgTag s (PgArr a) -> Action #

type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld tn ('TypDef "A" ('Just n) y) (PgArr t) = CanConvert1 sch tab fld n (TTypDef sch n) t
type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld n ('TypDef "E" ('Nothing :: Maybe (NameNS' Symbol)) es) (PGEnum sch n)
type CanConvert1 sch tab fld (PGC "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld (PGC "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) = ()
type CanConvert1 sch tab fld ("public" ->> "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) Source # 
Instance details

Defined in PgSchema.Types

type CanConvert1 sch tab fld ("public" ->> "citext") ('TypDef "S" ('Nothing :: Maybe (NameNS' Symbol)) ('[] :: [Symbol])) (CI Text) = ()
type Demote (NameNS' s) Source # 
Instance details

Defined in PgSchema.Schema

type Demote (NameNS' s) = NameNS' (Demote s)
type Sing Source # 
Instance details

Defined in PgSchema.Schema

type Sing

type (->>) (ns :: s) (name :: s) = 'NameNS ns name infixr 9 Source #

(->>) :: Text -> Text -> NameNS infixr 9 Source #

type family TRelDef (sch :: k) (ref :: NameNSK) :: RelDefK Source #

Instances

Instances details
type TRelDef PgCatalog (PGC "attribute__class") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "attribute__class") = 'RelDef (PGC "pg_attribute") (PGC "pg_class") '['("attrelid", "oid")]
type TRelDef PgCatalog (PGC "attribute__type") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "attribute__type") = 'RelDef (PGC "pg_attribute") (PGC "pg_type") '['("atttypid", "oid")]
type TRelDef PgCatalog (PGC "class__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "class__namespace") = 'RelDef (PGC "pg_class") (PGC "pg_namespace") '['("relnamespace", "oid")]
type TRelDef PgCatalog (PGC "constraint__class") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__class") = 'RelDef (PGC "pg_constraint") (PGC "pg_class") '['("conrelid", "oid")]
type TRelDef PgCatalog (PGC "constraint__fclass") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__fclass") = 'RelDef (PGC "pg_constraint") (PGC "pg_class") '['("confrelid", "oid")]
type TRelDef PgCatalog (PGC "constraint__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "constraint__namespace") = 'RelDef (PGC "pg_constraint") (PGC "pg_namespace") '['("connamespace", "oid")]
type TRelDef PgCatalog (PGC "enum__type") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "enum__type") = 'RelDef (PGC "pg_enum") (PGC "pg_type") '['("enumtypid", "oid")]
type TRelDef PgCatalog (PGC "type__namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

type TRelDef PgCatalog (PGC "type__namespace") = 'RelDef (PGC "pg_type") (PGC "pg_namespace") '['("typnamespace", "oid")]

data RelDef' s Source #

Foreign-key-style link between two qualified tables and column mapping.

Constructors

RelDef 

Fields

Instances

Instances details
Show s => Show (RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

showsPrec :: Int -> RelDef' s -> ShowS #

show :: RelDef' s -> String #

showList :: [RelDef' s] -> ShowS #

SingKind s => SingKind (RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Associated Types

type Demote (RelDef' s) 
Instance details

Defined in PgSchema.Schema

type Demote (RelDef' s) = RelDef' (Demote s)

Methods

fromSing :: forall (a :: RelDef' s). Sing a -> Demote (RelDef' s) #

toSing :: Demote (RelDef' s) -> SomeSing (RelDef' s) #

SingI n => SingI2 ('RelDef n :: NameNS' s -> [(s, s)] -> RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing2 :: forall (x :: NameNS' s) (y :: [(s, s)]). Sing x -> Sing y -> Sing ('RelDef n x y) #

(SingI n1, SingI n2) => SingI1 ('RelDef n1 n2 :: [(s, s)] -> RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

liftSing :: forall (x :: [(s, s)]). Sing x -> Sing ('RelDef n1 n2 x) #

(SingI n1, SingI n2, SingI n3) => SingI ('RelDef n1 n2 n3 :: RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

Methods

sing :: Sing ('RelDef n1 n2 n3) #

type Demote (RelDef' s) Source # 
Instance details

Defined in PgSchema.Schema

type Demote (RelDef' s) = RelDef' (Demote s)
type Sing Source # 
Instance details

Defined in PgSchema.Schema

type Sing

type family RdFrom (a :: RelDef' s) :: NameNS' s where ... Source #

Equations

RdFrom ('RelDef field _1 _2 :: RelDef' s) = field 

type family RdTo (a :: RelDef' s) :: NameNS' s where ... Source #

Equations

RdTo ('RelDef _1 field _2 :: RelDef' s) = field 

type family FdType (a :: FldDef' s) :: NameNS' s where ... Source #

Equations

FdType ('FldDef field _1 _2 :: FldDef' s) = field 

type family FdNullable (a :: FldDef' s) :: Bool where ... Source #

Equations

FdNullable ('FldDef _1 field _2 :: FldDef' s) = field 

class (ToStar name, ToStar (TTabDef sch name)) => CTabDef (sch :: k) (name :: NameNSK) Source #

instances will be generated by code generation

Associated Types

type TTabDef (sch :: k) (name :: NameNSK) :: TabDefK Source #

Instances

Instances details
CTabDef PgCatalog (PGC "pg_attribute") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_attribute") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_attribute") = 'TabDef '["oid", "attrelid", "attname", "atttypid", "attnum", "attnotnull", "atthasdef"] '["oid"] '['["attrelid", "attname"], '["attrelid", "attnum"]]
CTabDef PgCatalog (PGC "pg_class") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_class") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_class") = 'TabDef '["oid", "relnamespace", "relname", "relkind"] '["oid"] '['["relnamespace", "relname"]]
CTabDef PgCatalog (PGC "pg_constraint") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_constraint") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_constraint") = 'TabDef '["oid", "connamespace", "conname", "contype", "conrelid", "confrelid", "conkey", "confkey", "confupdtypeid", "confdeltypeid"] '["oid"] '['["connamespace", "conname"]]
CTabDef PgCatalog (PGC "pg_enum") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_enum") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_enum") = 'TabDef '["oid", "enumtypid", "enumlabel", "enumsortorder"] '["oid"] '['["enumtypid", "enumlabel"], '["enumtypid", "enumsortorder"]]
CTabDef PgCatalog (PGC "pg_namespace") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_namespace") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_namespace") = 'TabDef '["oid", "nspname"] '["oid"] '['["nspname"]]
CTabDef PgCatalog (PGC "pg_type") Source # 
Instance details

Defined in PgSchema.Schema.Catalog

Associated Types

type TTabDef PgCatalog (PGC "pg_type") 
Instance details

Defined in PgSchema.Schema.Catalog

type TTabDef PgCatalog (PGC "pg_type") = 'TabDef '["oid", "typnamespace", "typname", "typcategory", "typelem"] '["oid"] '['["typnamespace", "typname"]]