{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-name-shadowing #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE UndecidableInstances #-}
module Database.Beam.Postgres.Syntax
( PgSyntaxF(..), PgSyntaxM
, PgSyntax(..)
, emit, emitBuilder, escapeString
, escapeBytea, escapeIdentifier
, pgParens
, nextSyntaxStep
, PgCommandSyntax(..), PgCommandType(..)
, PgSelectSyntax(..), PgSelectSetQuantifierSyntax(..)
, PgInsertSyntax(..)
, PgDeleteSyntax(..)
, PgUpdateSyntax(..)
, PgExpressionSyntax(..), PgFromSyntax(..), PgTableNameSyntax(..)
, PgComparisonQuantifierSyntax(..)
, PgExtractFieldSyntax(..)
, PgProjectionSyntax(..), PgGroupingSyntax(..)
, PgOrderingSyntax(..), PgValueSyntax(..)
, PgTableSourceSyntax(..), PgFieldNameSyntax(..)
, PgAggregationSetQuantifierSyntax(..)
, PgInsertValuesSyntax(..), PgInsertOnConflictSyntax(..)
, PgInsertOnConflictTargetSyntax(..), PgConflictActionSyntax(..)
, PgCreateTableSyntax(..), PgTableOptionsSyntax(..), PgColumnSchemaSyntax(..)
, PgDataTypeSyntax(..), PgColumnConstraintDefinitionSyntax(..), PgColumnConstraintSyntax(..)
, PgTableConstraintSyntax(..), PgMatchTypeSyntax(..), PgReferentialActionSyntax(..)
, PgAlterTableSyntax(..), PgAlterTableActionSyntax(..), PgAlterColumnActionSyntax(..)
, PgWindowFrameSyntax(..), PgWindowFrameBoundsSyntax(..), PgWindowFrameBoundSyntax(..)
, PgSelectLockingClauseSyntax(..)
, PgSelectLockingStrength(..)
, PgSelectLockingOptions(..)
, fromPgSelectLockingClause
, pgSelectStmt
, defaultPgValueSyntax
, PgDataTypeDescr(..)
, PgHasEnum(..)
, pgCreateExtensionSyntax, pgDropExtensionSyntax
, pgCreateEnumSyntax, pgDropTypeSyntax
, pgSimpleMatchSyntax
, pgSelectSetQuantifierDistinctOn
, pgDataTypeJSON
, pgTsQueryType, pgTsVectorType
, pgJsonType, pgJsonbType, pgUuidType
, pgMoneyType
, pgTsQueryTypeInfo, pgTsVectorTypeInfo
, pgByteaType, pgTextType, pgUnboundedArrayType
, pgSerialType, pgSmallSerialType, pgBigSerialType
, pgPointType, pgLineType, pgLineSegmentType, pgBoxType
, pgQuotedIdentifier, pgSepBy, pgDebugRenderSyntax
, pgRenderSyntaxScript, pgBuildAction
, pgBinOp, pgCompOp, pgUnOp, pgPostFix
, pgTestSyntax
, PostgresInaccessible ) where
import Database.Beam hiding (insert)
import Database.Beam.Backend.Internal.Compat
import Database.Beam.Backend.SQL
import Database.Beam.Migrate
import Database.Beam.Migrate.SQL.Builder hiding (fromSqlConstraintAttributes)
import Database.Beam.Migrate.Serialization
import Control.Monad (guard)
import Control.Monad.Free
import Control.Monad.Free.Church
import Data.Aeson (Value, object, (.=))
import Data.Bits
import Data.ByteString (ByteString)
import Data.ByteString.Builder (Builder, byteString, char8, toLazyByteString)
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Lazy.Char8 (toStrict)
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.CaseInsensitive (CI)
import qualified Data.CaseInsensitive as CI
import Data.Coerce
import Data.Functor.Classes
import Data.Hashable
import Data.Int
import Data.Maybe
#if !MIN_VERSION_base(4, 11, 0)
import Data.Semigroup
#endif
import Data.Scientific (Scientific)
import Data.String (IsString(..), fromString)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Lazy as TL
import Data.Time (LocalTime, UTCTime, TimeOfDay, NominalDiffTime, Day)
import Data.UUID.Types (UUID, toASCIIBytes)
import Data.Word
import qualified Data.Vector as V
import GHC.TypeLits
import qualified Database.PostgreSQL.Simple.ToField as Pg
import qualified Database.PostgreSQL.Simple.TypeInfo.Static as Pg
import qualified Database.PostgreSQL.Simple.Types as Pg (Oid(..), Binary(..), Null(..))
import qualified Database.PostgreSQL.Simple.Time as Pg (Date, LocalTimestamp, UTCTimestamp)
import qualified Database.PostgreSQL.Simple.HStore as Pg (HStoreList, HStoreMap, HStoreBuilder)
data PostgresInaccessible
data PgSyntaxF f where
EmitByteString :: ByteString -> f -> PgSyntaxF f
EmitBuilder :: Builder -> f -> PgSyntaxF f
EscapeString :: ByteString -> f -> PgSyntaxF f
EscapeBytea :: ByteString -> f -> PgSyntaxF f
EscapeIdentifier :: ByteString -> f -> PgSyntaxF f
deriving instance Functor PgSyntaxF
instance Eq1 PgSyntaxF where
liftEq :: forall a b. (a -> b -> Bool) -> PgSyntaxF a -> PgSyntaxF b -> Bool
liftEq a -> b -> Bool
eq (EmitByteString ByteString
b1 a
next1) (EmitByteString ByteString
b2 b
next2) =
ByteString
b1 forall a. Eq a => a -> a -> Bool
== ByteString
b2 Bool -> Bool -> Bool
&& a
next1 a -> b -> Bool
`eq` b
next2
liftEq a -> b -> Bool
eq (EmitBuilder Builder
b1 a
next1) (EmitBuilder Builder
b2 b
next2) =
Builder -> ByteString
toLazyByteString Builder
b1 forall a. Eq a => a -> a -> Bool
== Builder -> ByteString
toLazyByteString Builder
b2 Bool -> Bool -> Bool
&& a
next1 a -> b -> Bool
`eq` b
next2
liftEq a -> b -> Bool
eq (EscapeString ByteString
b1 a
next1) (EscapeString ByteString
b2 b
next2) =
ByteString
b1 forall a. Eq a => a -> a -> Bool
== ByteString
b2 Bool -> Bool -> Bool
&& a
next1 a -> b -> Bool
`eq` b
next2
liftEq a -> b -> Bool
eq (EscapeBytea ByteString
b1 a
next1) (EscapeBytea ByteString
b2 b
next2) =
ByteString
b1 forall a. Eq a => a -> a -> Bool
== ByteString
b2 Bool -> Bool -> Bool
&& a
next1 a -> b -> Bool
`eq` b
next2
liftEq a -> b -> Bool
eq (EscapeIdentifier ByteString
b1 a
next1) (EscapeIdentifier ByteString
b2 b
next2) =
ByteString
b1 forall a. Eq a => a -> a -> Bool
== ByteString
b2 Bool -> Bool -> Bool
&& a
next1 a -> b -> Bool
`eq` b
next2
liftEq a -> b -> Bool
_ PgSyntaxF a
_ PgSyntaxF b
_ = Bool
False
instance Eq f => Eq (PgSyntaxF f) where
== :: PgSyntaxF f -> PgSyntaxF f -> Bool
(==) = forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
eq1
instance Hashable PgSyntax where
hashWithSalt :: Int -> PgSyntax -> Int
hashWithSalt Int
salt (PgSyntax PgSyntaxM ()
s) = forall (f :: * -> *) a.
F f a -> forall r. (a -> r) -> (f r -> r) -> r
runF PgSyntaxM ()
s forall {p}. p -> Int -> Int
finish forall {t}. PgSyntaxF (Int -> t) -> Int -> t
step Int
salt
where
finish :: p -> Int -> Int
finish p
_ Int
salt = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt ()
step :: PgSyntaxF (Int -> t) -> Int -> t
step (EmitByteString ByteString
b Int -> t
hashRest) Int
salt = Int -> t
hashRest (forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
0 :: Int, ByteString
b))
step (EmitBuilder Builder
b Int -> t
hashRest) Int
salt = Int -> t
hashRest (forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
1 :: Int, Builder -> ByteString
toLazyByteString Builder
b))
step (EscapeString ByteString
b Int -> t
hashRest) Int
salt = Int -> t
hashRest (forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
2 :: Int, ByteString
b))
step (EscapeBytea ByteString
b Int -> t
hashRest) Int
salt = Int -> t
hashRest (forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
3 :: Int, ByteString
b))
step (EscapeIdentifier ByteString
b Int -> t
hashRest) Int
salt = Int -> t
hashRest (forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
4 :: Int, ByteString
b))
instance Sql92DisplaySyntax PgSyntax where
displaySyntax :: PgSyntax -> String
displaySyntax = ByteString -> String
BL.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgSyntax -> ByteString
pgRenderSyntaxScript
type PgSyntaxM = F PgSyntaxF
newtype PgSyntax
= PgSyntax { PgSyntax -> PgSyntaxM ()
buildPgSyntax :: PgSyntaxM () }
instance Semigroup PgSyntax where
PgSyntax
a <> :: PgSyntax -> PgSyntax -> PgSyntax
<> PgSyntax
b = PgSyntaxM () -> PgSyntax
PgSyntax (PgSyntax -> PgSyntaxM ()
buildPgSyntax PgSyntax
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PgSyntax -> PgSyntaxM ()
buildPgSyntax PgSyntax
b)
instance Monoid PgSyntax where
mempty :: PgSyntax
mempty = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
mappend :: PgSyntax -> PgSyntax -> PgSyntax
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Eq PgSyntax where
PgSyntax PgSyntaxM ()
x == :: PgSyntax -> PgSyntax -> Bool
== PgSyntax PgSyntaxM ()
y = (forall (f :: * -> *) (m :: * -> *) a. MonadFree f m => F f a -> m a
fromF PgSyntaxM ()
x :: Free PgSyntaxF ()) forall a. Eq a => a -> a -> Bool
== forall (f :: * -> *) (m :: * -> *) a. MonadFree f m => F f a -> m a
fromF PgSyntaxM ()
y
instance Show PgSyntax where
showsPrec :: Int -> PgSyntax -> ShowS
showsPrec Int
prec PgSyntax
s =
Bool -> ShowS -> ShowS
showParen (Int
prec forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"PgSyntax <" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => a -> ShowS
shows (PgSyntax -> [PgSyntaxPrim]
pgTestSyntax PgSyntax
s) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
">"
emit :: ByteString -> PgSyntax
emit :: ByteString -> PgSyntax
emit ByteString
bs = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall f. ByteString -> f -> PgSyntaxF f
EmitByteString ByteString
bs ()))
emitBuilder :: Builder -> PgSyntax
emitBuilder :: Builder -> PgSyntax
emitBuilder Builder
b = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall f. Builder -> f -> PgSyntaxF f
EmitBuilder Builder
b ()))
escapeString, escapeBytea, escapeIdentifier :: ByteString -> PgSyntax
escapeString :: ByteString -> PgSyntax
escapeString ByteString
bs = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall f. ByteString -> f -> PgSyntaxF f
EscapeString ByteString
bs ()))
escapeBytea :: ByteString -> PgSyntax
escapeBytea ByteString
bin = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall f. ByteString -> f -> PgSyntaxF f
EscapeBytea ByteString
bin ()))
escapeIdentifier :: ByteString -> PgSyntax
escapeIdentifier ByteString
id = PgSyntaxM () -> PgSyntax
PgSyntax (forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall f. ByteString -> f -> PgSyntaxF f
EscapeIdentifier ByteString
id ()))
nextSyntaxStep :: PgSyntaxF f -> f
nextSyntaxStep :: forall f. PgSyntaxF f -> f
nextSyntaxStep (EmitByteString ByteString
_ f
next) = f
next
nextSyntaxStep (EmitBuilder Builder
_ f
next) = f
next
nextSyntaxStep (EscapeString ByteString
_ f
next) = f
next
nextSyntaxStep (EscapeBytea ByteString
_ f
next) = f
next
nextSyntaxStep (EscapeIdentifier ByteString
_ f
next) = f
next
data PgCommandType
= PgCommandTypeQuery
| PgCommandTypeDdl
| PgCommandTypeDataUpdate
| PgCommandTypeDataUpdateReturning
deriving Int -> PgCommandType -> ShowS
[PgCommandType] -> ShowS
PgCommandType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgCommandType] -> ShowS
$cshowList :: [PgCommandType] -> ShowS
show :: PgCommandType -> String
$cshow :: PgCommandType -> String
showsPrec :: Int -> PgCommandType -> ShowS
$cshowsPrec :: Int -> PgCommandType -> ShowS
Show
data PgCommandSyntax
= PgCommandSyntax
{ PgCommandSyntax -> PgCommandType
pgCommandType :: PgCommandType
, PgCommandSyntax -> PgSyntax
fromPgCommand :: PgSyntax }
newtype PgSelectSyntax = PgSelectSyntax { PgSelectSyntax -> PgSyntax
fromPgSelect :: PgSyntax }
newtype PgSelectTableSyntax = PgSelectTableSyntax { PgSelectTableSyntax -> PgSyntax
fromPgSelectTable :: PgSyntax }
newtype PgInsertSyntax = PgInsertSyntax { PgInsertSyntax -> PgSyntax
fromPgInsert :: PgSyntax }
newtype PgDeleteSyntax = PgDeleteSyntax { PgDeleteSyntax -> PgSyntax
fromPgDelete :: PgSyntax }
newtype PgUpdateSyntax = PgUpdateSyntax { PgUpdateSyntax -> PgSyntax
fromPgUpdate :: PgSyntax }
newtype PgExpressionSyntax = PgExpressionSyntax { PgExpressionSyntax -> PgSyntax
fromPgExpression :: PgSyntax } deriving PgExpressionSyntax -> PgExpressionSyntax -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgExpressionSyntax -> PgExpressionSyntax -> Bool
$c/= :: PgExpressionSyntax -> PgExpressionSyntax -> Bool
== :: PgExpressionSyntax -> PgExpressionSyntax -> Bool
$c== :: PgExpressionSyntax -> PgExpressionSyntax -> Bool
Eq
newtype PgAggregationSetQuantifierSyntax = PgAggregationSetQuantifierSyntax { PgAggregationSetQuantifierSyntax -> PgSyntax
fromPgAggregationSetQuantifier :: PgSyntax }
newtype PgSelectSetQuantifierSyntax = PgSelectSetQuantifierSyntax { PgSelectSetQuantifierSyntax -> PgSyntax
fromPgSelectSetQuantifier :: PgSyntax }
newtype PgFromSyntax = PgFromSyntax { PgFromSyntax -> PgSyntax
fromPgFrom :: PgSyntax }
newtype PgTableNameSyntax = PgTableNameSyntax { PgTableNameSyntax -> PgSyntax
fromPgTableName :: PgSyntax }
newtype PgComparisonQuantifierSyntax = PgComparisonQuantifierSyntax { PgComparisonQuantifierSyntax -> PgSyntax
fromPgComparisonQuantifier :: PgSyntax }
newtype = { :: PgSyntax }
newtype PgProjectionSyntax = PgProjectionSyntax { PgProjectionSyntax -> PgSyntax
fromPgProjection :: PgSyntax }
newtype PgGroupingSyntax = PgGroupingSyntax { PgGroupingSyntax -> PgSyntax
fromPgGrouping :: PgSyntax }
newtype PgValueSyntax = PgValueSyntax { PgValueSyntax -> PgSyntax
fromPgValue :: PgSyntax }
newtype PgTableSourceSyntax = PgTableSourceSyntax { PgTableSourceSyntax -> PgSyntax
fromPgTableSource :: PgSyntax }
newtype PgFieldNameSyntax = PgFieldNameSyntax { PgFieldNameSyntax -> PgSyntax
fromPgFieldName :: PgSyntax }
newtype PgInsertValuesSyntax = PgInsertValuesSyntax { PgInsertValuesSyntax -> PgSyntax
fromPgInsertValues :: PgSyntax }
newtype PgInsertOnConflictSyntax = PgInsertOnConflictSyntax { PgInsertOnConflictSyntax -> PgSyntax
fromPgInsertOnConflict :: PgSyntax }
newtype PgInsertOnConflictTargetSyntax = PgInsertOnConflictTargetSyntax { PgInsertOnConflictTargetSyntax -> PgSyntax
fromPgInsertOnConflictTarget :: PgSyntax }
newtype PgInsertOnConflictUpdateSyntax = PgInsertOnConflictUpdateSyntax { PgInsertOnConflictUpdateSyntax -> PgSyntax
fromPgInsertOnConflictUpdate :: PgSyntax }
newtype PgConflictActionSyntax = PgConflictActionSyntax { PgConflictActionSyntax -> PgSyntax
fromPgConflictAction :: PgSyntax }
data PgOrderingSyntax = PgOrderingSyntax { PgOrderingSyntax -> PgSyntax
pgOrderingSyntax :: PgSyntax, PgOrderingSyntax -> Maybe PgNullOrdering
pgOrderingNullOrdering :: Maybe PgNullOrdering }
data PgSelectLockingClauseSyntax = PgSelectLockingClauseSyntax { PgSelectLockingClauseSyntax -> PgSelectLockingStrength
pgSelectLockingClauseStrength :: PgSelectLockingStrength
, PgSelectLockingClauseSyntax -> [Text]
pgSelectLockingTables :: [T.Text]
, PgSelectLockingClauseSyntax -> Maybe PgSelectLockingOptions
pgSelectLockingClauseOptions :: Maybe PgSelectLockingOptions }
newtype PgCommonTableExpressionSyntax
= PgCommonTableExpressionSyntax { PgCommonTableExpressionSyntax -> PgSyntax
fromPgCommonTableExpression :: PgSyntax }
fromPgOrdering :: PgOrderingSyntax -> PgSyntax
fromPgOrdering :: PgOrderingSyntax -> PgSyntax
fromPgOrdering (PgOrderingSyntax PgSyntax
s Maybe PgNullOrdering
Nothing) = PgSyntax
s
fromPgOrdering (PgOrderingSyntax PgSyntax
s (Just PgNullOrdering
PgNullOrderingNullsFirst)) = PgSyntax
s forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" NULLS FIRST"
fromPgOrdering (PgOrderingSyntax PgSyntax
s (Just PgNullOrdering
PgNullOrderingNullsLast)) = PgSyntax
s forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" NULLS LAST"
data PgNullOrdering
= PgNullOrderingNullsFirst
| PgNullOrderingNullsLast
deriving (Int -> PgNullOrdering -> ShowS
[PgNullOrdering] -> ShowS
PgNullOrdering -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgNullOrdering] -> ShowS
$cshowList :: [PgNullOrdering] -> ShowS
show :: PgNullOrdering -> String
$cshow :: PgNullOrdering -> String
showsPrec :: Int -> PgNullOrdering -> ShowS
$cshowsPrec :: Int -> PgNullOrdering -> ShowS
Show, PgNullOrdering -> PgNullOrdering -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgNullOrdering -> PgNullOrdering -> Bool
$c/= :: PgNullOrdering -> PgNullOrdering -> Bool
== :: PgNullOrdering -> PgNullOrdering -> Bool
$c== :: PgNullOrdering -> PgNullOrdering -> Bool
Eq, forall x. Rep PgNullOrdering x -> PgNullOrdering
forall x. PgNullOrdering -> Rep PgNullOrdering x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PgNullOrdering x -> PgNullOrdering
$cfrom :: forall x. PgNullOrdering -> Rep PgNullOrdering x
Generic)
fromPgSelectLockingClause :: PgSelectLockingClauseSyntax -> PgSyntax
fromPgSelectLockingClause :: PgSelectLockingClauseSyntax -> PgSyntax
fromPgSelectLockingClause PgSelectLockingClauseSyntax
s =
ByteString -> PgSyntax
emit ByteString
" FOR " forall a. Semigroup a => a -> a -> a
<>
(case PgSelectLockingClauseSyntax -> PgSelectLockingStrength
pgSelectLockingClauseStrength PgSelectLockingClauseSyntax
s of
PgSelectLockingStrength
PgSelectLockingStrengthUpdate -> ByteString -> PgSyntax
emit ByteString
"UPDATE"
PgSelectLockingStrength
PgSelectLockingStrengthNoKeyUpdate -> ByteString -> PgSyntax
emit ByteString
"NO KEY UPDATE"
PgSelectLockingStrength
PgSelectLockingStrengthShare -> ByteString -> PgSyntax
emit ByteString
"SHARE"
PgSelectLockingStrength
PgSelectLockingStrengthKeyShare -> ByteString -> PgSyntax
emit ByteString
"KEY SHARE") forall a. Semigroup a => a -> a -> a
<>
PgSyntax
emitTables forall a. Semigroup a => a -> a -> a
<>
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty PgSelectLockingOptions -> PgSyntax
emitOptions forall a b. (a -> b) -> a -> b
$ PgSelectLockingClauseSyntax -> Maybe PgSelectLockingOptions
pgSelectLockingClauseOptions PgSelectLockingClauseSyntax
s)
where
emitTables :: PgSyntax
emitTables = case PgSelectLockingClauseSyntax -> [Text]
pgSelectLockingTables PgSelectLockingClauseSyntax
s of
[] -> forall a. Monoid a => a
mempty
[Text]
tableNames -> ByteString -> PgSyntax
emit ByteString
" OF " forall a. Semigroup a => a -> a -> a
<> (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
tableNames))
emitOptions :: PgSelectLockingOptions -> PgSyntax
emitOptions PgSelectLockingOptions
PgSelectLockingOptionsNoWait = ByteString -> PgSyntax
emit ByteString
" NOWAIT"
emitOptions PgSelectLockingOptions
PgSelectLockingOptionsSkipLocked = ByteString -> PgSyntax
emit ByteString
" SKIP LOCKED"
data PgSelectLockingStrength
= PgSelectLockingStrengthUpdate
| PgSelectLockingStrengthNoKeyUpdate
| PgSelectLockingStrengthShare
| PgSelectLockingStrengthKeyShare
deriving (Int -> PgSelectLockingStrength -> ShowS
[PgSelectLockingStrength] -> ShowS
PgSelectLockingStrength -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgSelectLockingStrength] -> ShowS
$cshowList :: [PgSelectLockingStrength] -> ShowS
show :: PgSelectLockingStrength -> String
$cshow :: PgSelectLockingStrength -> String
showsPrec :: Int -> PgSelectLockingStrength -> ShowS
$cshowsPrec :: Int -> PgSelectLockingStrength -> ShowS
Show, PgSelectLockingStrength -> PgSelectLockingStrength -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgSelectLockingStrength -> PgSelectLockingStrength -> Bool
$c/= :: PgSelectLockingStrength -> PgSelectLockingStrength -> Bool
== :: PgSelectLockingStrength -> PgSelectLockingStrength -> Bool
$c== :: PgSelectLockingStrength -> PgSelectLockingStrength -> Bool
Eq, forall x. Rep PgSelectLockingStrength x -> PgSelectLockingStrength
forall x. PgSelectLockingStrength -> Rep PgSelectLockingStrength x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PgSelectLockingStrength x -> PgSelectLockingStrength
$cfrom :: forall x. PgSelectLockingStrength -> Rep PgSelectLockingStrength x
Generic)
data PgSelectLockingOptions
= PgSelectLockingOptionsNoWait
| PgSelectLockingOptionsSkipLocked
deriving (Int -> PgSelectLockingOptions -> ShowS
[PgSelectLockingOptions] -> ShowS
PgSelectLockingOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgSelectLockingOptions] -> ShowS
$cshowList :: [PgSelectLockingOptions] -> ShowS
show :: PgSelectLockingOptions -> String
$cshow :: PgSelectLockingOptions -> String
showsPrec :: Int -> PgSelectLockingOptions -> ShowS
$cshowsPrec :: Int -> PgSelectLockingOptions -> ShowS
Show, PgSelectLockingOptions -> PgSelectLockingOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgSelectLockingOptions -> PgSelectLockingOptions -> Bool
$c/= :: PgSelectLockingOptions -> PgSelectLockingOptions -> Bool
== :: PgSelectLockingOptions -> PgSelectLockingOptions -> Bool
$c== :: PgSelectLockingOptions -> PgSelectLockingOptions -> Bool
Eq, forall x. Rep PgSelectLockingOptions x -> PgSelectLockingOptions
forall x. PgSelectLockingOptions -> Rep PgSelectLockingOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PgSelectLockingOptions x -> PgSelectLockingOptions
$cfrom :: forall x. PgSelectLockingOptions -> Rep PgSelectLockingOptions x
Generic)
data PgDataTypeDescr
= PgDataTypeDescrOid Pg.Oid (Maybe Int32)
| PgDataTypeDescrDomain T.Text
deriving (Int -> PgDataTypeDescr -> ShowS
[PgDataTypeDescr] -> ShowS
PgDataTypeDescr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgDataTypeDescr] -> ShowS
$cshowList :: [PgDataTypeDescr] -> ShowS
show :: PgDataTypeDescr -> String
$cshow :: PgDataTypeDescr -> String
showsPrec :: Int -> PgDataTypeDescr -> ShowS
$cshowsPrec :: Int -> PgDataTypeDescr -> ShowS
Show, PgDataTypeDescr -> PgDataTypeDescr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgDataTypeDescr -> PgDataTypeDescr -> Bool
$c/= :: PgDataTypeDescr -> PgDataTypeDescr -> Bool
== :: PgDataTypeDescr -> PgDataTypeDescr -> Bool
$c== :: PgDataTypeDescr -> PgDataTypeDescr -> Bool
Eq, forall x. Rep PgDataTypeDescr x -> PgDataTypeDescr
forall x. PgDataTypeDescr -> Rep PgDataTypeDescr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PgDataTypeDescr x -> PgDataTypeDescr
$cfrom :: forall x. PgDataTypeDescr -> Rep PgDataTypeDescr x
Generic)
instance Hashable PgDataTypeDescr where
hashWithSalt :: Int -> PgDataTypeDescr -> Int
hashWithSalt Int
salt (PgDataTypeDescrOid (Pg.Oid CUInt
oid) Maybe Int32
dim) =
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
0 :: Int, forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
oid :: Word32, Maybe Int32
dim)
hashWithSalt Int
salt (PgDataTypeDescrDomain Text
t) =
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
1 :: Int, Text
t)
newtype PgCreateTableSyntax = PgCreateTableSyntax { PgCreateTableSyntax -> PgSyntax
fromPgCreateTable :: PgSyntax }
data PgTableOptionsSyntax = PgTableOptionsSyntax PgSyntax PgSyntax
newtype PgColumnSchemaSyntax = PgColumnSchemaSyntax { PgColumnSchemaSyntax -> PgSyntax
fromPgColumnSchema :: PgSyntax } deriving (Int -> PgColumnSchemaSyntax -> ShowS
[PgColumnSchemaSyntax] -> ShowS
PgColumnSchemaSyntax -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgColumnSchemaSyntax] -> ShowS
$cshowList :: [PgColumnSchemaSyntax] -> ShowS
show :: PgColumnSchemaSyntax -> String
$cshow :: PgColumnSchemaSyntax -> String
showsPrec :: Int -> PgColumnSchemaSyntax -> ShowS
$cshowsPrec :: Int -> PgColumnSchemaSyntax -> ShowS
Show, PgColumnSchemaSyntax -> PgColumnSchemaSyntax -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgColumnSchemaSyntax -> PgColumnSchemaSyntax -> Bool
$c/= :: PgColumnSchemaSyntax -> PgColumnSchemaSyntax -> Bool
== :: PgColumnSchemaSyntax -> PgColumnSchemaSyntax -> Bool
$c== :: PgColumnSchemaSyntax -> PgColumnSchemaSyntax -> Bool
Eq)
instance Sql92DisplaySyntax PgColumnSchemaSyntax where
displaySyntax :: PgColumnSchemaSyntax -> String
displaySyntax = forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgColumnSchemaSyntax -> PgSyntax
fromPgColumnSchema
data PgDataTypeSyntax
= PgDataTypeSyntax
{ PgDataTypeSyntax -> PgDataTypeDescr
pgDataTypeDescr :: PgDataTypeDescr
, PgDataTypeSyntax -> PgSyntax
fromPgDataType :: PgSyntax
, PgDataTypeSyntax -> BeamSerializedDataType
pgDataTypeSerialized :: BeamSerializedDataType
} deriving Int -> PgDataTypeSyntax -> ShowS
[PgDataTypeSyntax] -> ShowS
PgDataTypeSyntax -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgDataTypeSyntax] -> ShowS
$cshowList :: [PgDataTypeSyntax] -> ShowS
show :: PgDataTypeSyntax -> String
$cshow :: PgDataTypeSyntax -> String
showsPrec :: Int -> PgDataTypeSyntax -> ShowS
$cshowsPrec :: Int -> PgDataTypeSyntax -> ShowS
Show
instance Sql92DisplaySyntax PgDataTypeSyntax where
displaySyntax :: PgDataTypeSyntax -> String
displaySyntax = forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgDataTypeSyntax -> PgSyntax
fromPgDataType
data PgColumnConstraintDefinitionSyntax
= PgColumnConstraintDefinitionSyntax
{ PgColumnConstraintDefinitionSyntax -> PgSyntax
fromPgColumnConstraintDefinition :: PgSyntax
, PgColumnConstraintDefinitionSyntax
-> BeamSerializedConstraintDefinition
pgColumnConstraintDefinitionSerialized :: BeamSerializedConstraintDefinition
} deriving Int -> PgColumnConstraintDefinitionSyntax -> ShowS
[PgColumnConstraintDefinitionSyntax] -> ShowS
PgColumnConstraintDefinitionSyntax -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgColumnConstraintDefinitionSyntax] -> ShowS
$cshowList :: [PgColumnConstraintDefinitionSyntax] -> ShowS
show :: PgColumnConstraintDefinitionSyntax -> String
$cshow :: PgColumnConstraintDefinitionSyntax -> String
showsPrec :: Int -> PgColumnConstraintDefinitionSyntax -> ShowS
$cshowsPrec :: Int -> PgColumnConstraintDefinitionSyntax -> ShowS
Show
instance Sql92DisplaySyntax PgColumnConstraintDefinitionSyntax where
displaySyntax :: PgColumnConstraintDefinitionSyntax -> String
displaySyntax = forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgColumnConstraintDefinitionSyntax -> PgSyntax
fromPgColumnConstraintDefinition
data PgColumnConstraintSyntax
= PgColumnConstraintSyntax
{ PgColumnConstraintSyntax -> PgSyntax
fromPgColumnConstraint :: PgSyntax
, PgColumnConstraintSyntax -> BeamSerializedConstraint
pgColumnConstraintSerialized :: BeamSerializedConstraint
}
newtype PgTableConstraintSyntax = PgTableConstraintSyntax { PgTableConstraintSyntax -> PgSyntax
fromPgTableConstraint :: PgSyntax }
data PgMatchTypeSyntax
= PgMatchTypeSyntax
{ PgMatchTypeSyntax -> PgSyntax
fromPgMatchType :: PgSyntax
, PgMatchTypeSyntax -> BeamSerializedMatchType
pgMatchTypeSerialized :: BeamSerializedMatchType
}
data PgReferentialActionSyntax
= PgReferentialActionSyntax
{ PgReferentialActionSyntax -> PgSyntax
fromPgReferentialAction :: PgSyntax
, PgReferentialActionSyntax -> BeamSerializedReferentialAction
pgReferentialActionSerialized :: BeamSerializedReferentialAction
}
newtype PgDropTableSyntax = PgDropTableSyntax { PgDropTableSyntax -> PgSyntax
fromPgDropTable :: PgSyntax }
newtype PgAlterTableSyntax = PgAlterTableSyntax { PgAlterTableSyntax -> PgSyntax
fromPgAlterTable :: PgSyntax }
newtype PgAlterTableActionSyntax = PgAlterTableActionSyntax { PgAlterTableActionSyntax -> PgSyntax
fromPgAlterTableAction :: PgSyntax }
newtype PgAlterColumnActionSyntax = PgAlterColumnActionSyntax { PgAlterColumnActionSyntax -> PgSyntax
fromPgAlterColumnAction :: PgSyntax }
newtype PgWindowFrameSyntax = PgWindowFrameSyntax { PgWindowFrameSyntax -> PgSyntax
fromPgWindowFrame :: PgSyntax }
newtype PgWindowFrameBoundsSyntax = PgWindowFrameBoundsSyntax { PgWindowFrameBoundsSyntax -> PgSyntax
fromPgWindowFrameBounds :: PgSyntax }
newtype PgWindowFrameBoundSyntax = PgWindowFrameBoundSyntax { PgWindowFrameBoundSyntax -> ByteString -> PgSyntax
fromPgWindowFrameBound :: ByteString -> PgSyntax }
instance Hashable PgDataTypeSyntax where
hashWithSalt :: Int -> PgDataTypeSyntax -> Int
hashWithSalt Int
salt (PgDataTypeSyntax PgDataTypeDescr
a PgSyntax
_ BeamSerializedDataType
_) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt PgDataTypeDescr
a
instance Eq PgDataTypeSyntax where
PgDataTypeSyntax PgDataTypeDescr
a PgSyntax
_ BeamSerializedDataType
_ == :: PgDataTypeSyntax -> PgDataTypeSyntax -> Bool
== PgDataTypeSyntax PgDataTypeDescr
b PgSyntax
_ BeamSerializedDataType
_ = PgDataTypeDescr
a forall a. Eq a => a -> a -> Bool
== PgDataTypeDescr
b
instance HasDataTypeCreatedCheck PgDataTypeSyntax where
dataTypeHasBeenCreated :: PgDataTypeSyntax
-> (forall preCondition. Typeable preCondition => [preCondition])
-> Bool
dataTypeHasBeenCreated (PgDataTypeSyntax (PgDataTypeDescrOid {}) PgSyntax
_ BeamSerializedDataType
_) forall preCondition. Typeable preCondition => [preCondition]
_ = Bool
True
dataTypeHasBeenCreated (PgDataTypeSyntax (PgDataTypeDescrDomain Text
d) PgSyntax
_ BeamSerializedDataType
_) forall preCondition. Typeable preCondition => [preCondition]
pre =
Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall a b. (a -> b) -> a -> b
$
do PgHasEnum Text
nm [Text]
_ <- forall preCondition. Typeable preCondition => [preCondition]
pre
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Text
nm forall a. Eq a => a -> a -> Bool
== Text
d)
instance Eq PgColumnConstraintDefinitionSyntax where
PgColumnConstraintDefinitionSyntax PgSyntax
a BeamSerializedConstraintDefinition
_ == :: PgColumnConstraintDefinitionSyntax
-> PgColumnConstraintDefinitionSyntax -> Bool
==
PgColumnConstraintDefinitionSyntax PgSyntax
b BeamSerializedConstraintDefinition
_ =
PgSyntax
a forall a. Eq a => a -> a -> Bool
== PgSyntax
b
instance IsSql92Syntax PgCommandSyntax where
type Sql92SelectSyntax PgCommandSyntax = PgSelectSyntax
type Sql92InsertSyntax PgCommandSyntax = PgInsertSyntax
type Sql92UpdateSyntax PgCommandSyntax = PgUpdateSyntax
type Sql92DeleteSyntax PgCommandSyntax = PgDeleteSyntax
selectCmd :: Sql92SelectSyntax PgCommandSyntax -> PgCommandSyntax
selectCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeQuery forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
insertCmd :: Sql92InsertSyntax PgCommandSyntax -> PgCommandSyntax
insertCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDataUpdate forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
deleteCmd :: Sql92DeleteSyntax PgCommandSyntax -> PgCommandSyntax
deleteCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDataUpdate forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
updateCmd :: Sql92UpdateSyntax PgCommandSyntax -> PgCommandSyntax
updateCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDataUpdate forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
instance IsSql92DdlCommandSyntax PgCommandSyntax where
type Sql92DdlCommandCreateTableSyntax PgCommandSyntax = PgCreateTableSyntax
type Sql92DdlCommandDropTableSyntax PgCommandSyntax = PgDropTableSyntax
type Sql92DdlCommandAlterTableSyntax PgCommandSyntax = PgAlterTableSyntax
createTableCmd :: Sql92DdlCommandCreateTableSyntax PgCommandSyntax -> PgCommandSyntax
createTableCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
dropTableCmd :: Sql92DdlCommandDropTableSyntax PgCommandSyntax -> PgCommandSyntax
dropTableCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
alterTableCmd :: Sql92DdlCommandAlterTableSyntax PgCommandSyntax -> PgCommandSyntax
alterTableCmd = PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
instance IsSql92TableNameSyntax PgTableNameSyntax where
tableName :: Maybe Text -> Text -> PgTableNameSyntax
tableName Maybe Text
Nothing Text
t = PgSyntax -> PgTableNameSyntax
PgTableNameSyntax (Text -> PgSyntax
pgQuotedIdentifier Text
t)
tableName (Just Text
s) Text
t = PgSyntax -> PgTableNameSyntax
PgTableNameSyntax (Text -> PgSyntax
pgQuotedIdentifier Text
s forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"." forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
t)
instance IsSql92UpdateSyntax PgUpdateSyntax where
type Sql92UpdateFieldNameSyntax PgUpdateSyntax = PgFieldNameSyntax
type Sql92UpdateExpressionSyntax PgUpdateSyntax = PgExpressionSyntax
type Sql92UpdateTableNameSyntax PgUpdateSyntax = PgTableNameSyntax
updateStmt :: Sql92UpdateTableNameSyntax PgUpdateSyntax
-> [(Sql92UpdateFieldNameSyntax PgUpdateSyntax,
Sql92UpdateExpressionSyntax PgUpdateSyntax)]
-> Maybe (Sql92UpdateExpressionSyntax PgUpdateSyntax)
-> PgUpdateSyntax
updateStmt Sql92UpdateTableNameSyntax PgUpdateSyntax
tbl [(Sql92UpdateFieldNameSyntax PgUpdateSyntax,
Sql92UpdateExpressionSyntax PgUpdateSyntax)]
fields Maybe (Sql92UpdateExpressionSyntax PgUpdateSyntax)
where_ =
PgSyntax -> PgUpdateSyntax
PgUpdateSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"UPDATE " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92UpdateTableNameSyntax PgUpdateSyntax
tbl forall a. Semigroup a => a -> a -> a
<>
(case [(Sql92UpdateFieldNameSyntax PgUpdateSyntax,
Sql92UpdateExpressionSyntax PgUpdateSyntax)]
fields of
[] -> forall a. Monoid a => a
mempty
[(Sql92UpdateFieldNameSyntax PgUpdateSyntax,
Sql92UpdateExpressionSyntax PgUpdateSyntax)]
fields ->
ByteString -> PgSyntax
emit ByteString
" SET " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map (\(PgFieldNameSyntax
field, PgExpressionSyntax
val) -> PgFieldNameSyntax -> PgSyntax
fromPgFieldName PgFieldNameSyntax
field forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"=" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
val) [(Sql92UpdateFieldNameSyntax PgUpdateSyntax,
Sql92UpdateExpressionSyntax PgUpdateSyntax)]
fields)) forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgExpressionSyntax
where_ -> ByteString -> PgSyntax
emit ByteString
" WHERE " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
where_) Maybe (Sql92UpdateExpressionSyntax PgUpdateSyntax)
where_
instance IsSql92DeleteSyntax PgDeleteSyntax where
type Sql92DeleteExpressionSyntax PgDeleteSyntax = PgExpressionSyntax
type Sql92DeleteTableNameSyntax PgDeleteSyntax = PgTableNameSyntax
deleteStmt :: Sql92DeleteTableNameSyntax PgDeleteSyntax
-> Maybe Text
-> Maybe (Sql92DeleteExpressionSyntax PgDeleteSyntax)
-> PgDeleteSyntax
deleteStmt Sql92DeleteTableNameSyntax PgDeleteSyntax
tbl Maybe Text
alias Maybe (Sql92DeleteExpressionSyntax PgDeleteSyntax)
where_ =
PgSyntax -> PgDeleteSyntax
PgDeleteSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"DELETE FROM " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92DeleteTableNameSyntax PgDeleteSyntax
tbl forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Text
alias_ -> ByteString -> PgSyntax
emit ByteString
" AS " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
alias_) Maybe Text
alias forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgExpressionSyntax
where_ -> ByteString -> PgSyntax
emit ByteString
" WHERE " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
where_) Maybe (Sql92DeleteExpressionSyntax PgDeleteSyntax)
where_
deleteSupportsAlias :: Proxy PgDeleteSyntax -> Bool
deleteSupportsAlias Proxy PgDeleteSyntax
_ = Bool
True
instance IsSql92SelectSyntax PgSelectSyntax where
type Sql92SelectSelectTableSyntax PgSelectSyntax = PgSelectTableSyntax
type Sql92SelectOrderingSyntax PgSelectSyntax = PgOrderingSyntax
selectStmt :: Sql92SelectSelectTableSyntax PgSelectSyntax
-> [Sql92SelectOrderingSyntax PgSelectSyntax]
-> Maybe Integer
-> Maybe Integer
-> PgSelectSyntax
selectStmt Sql92SelectSelectTableSyntax PgSelectSyntax
tbl [Sql92SelectOrderingSyntax PgSelectSyntax]
ordering Maybe Integer
limit Maybe Integer
offset =
PgSelectTableSyntax
-> [PgOrderingSyntax]
-> Maybe Integer
-> Maybe Integer
-> Maybe PgSelectLockingClauseSyntax
-> PgSelectSyntax
pgSelectStmt Sql92SelectSelectTableSyntax PgSelectSyntax
tbl [Sql92SelectOrderingSyntax PgSelectSyntax]
ordering Maybe Integer
limit Maybe Integer
offset forall a. Maybe a
Nothing
instance IsSql92SelectTableSyntax PgSelectTableSyntax where
type Sql92SelectTableSelectSyntax PgSelectTableSyntax = PgSelectSyntax
type Sql92SelectTableExpressionSyntax PgSelectTableSyntax = PgExpressionSyntax
type Sql92SelectTableProjectionSyntax PgSelectTableSyntax = PgProjectionSyntax
type Sql92SelectTableFromSyntax PgSelectTableSyntax = PgFromSyntax
type Sql92SelectTableGroupingSyntax PgSelectTableSyntax = PgGroupingSyntax
type Sql92SelectTableSetQuantifierSyntax PgSelectTableSyntax = PgSelectSetQuantifierSyntax
selectTableStmt :: Maybe (Sql92SelectTableSetQuantifierSyntax PgSelectTableSyntax)
-> Sql92SelectTableProjectionSyntax PgSelectTableSyntax
-> Maybe (Sql92SelectTableFromSyntax PgSelectTableSyntax)
-> Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
-> Maybe (Sql92SelectTableGroupingSyntax PgSelectTableSyntax)
-> Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
-> PgSelectTableSyntax
selectTableStmt Maybe (Sql92SelectTableSetQuantifierSyntax PgSelectTableSyntax)
setQuantifier Sql92SelectTableProjectionSyntax PgSelectTableSyntax
proj Maybe (Sql92SelectTableFromSyntax PgSelectTableSyntax)
from Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
where_ Maybe (Sql92SelectTableGroupingSyntax PgSelectTableSyntax)
grouping Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
having =
PgSyntax -> PgSelectTableSyntax
PgSelectTableSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"SELECT " forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgSelectSetQuantifierSyntax
setQuantifier' -> PgSelectSetQuantifierSyntax -> PgSyntax
fromPgSelectSetQuantifier PgSelectSetQuantifierSyntax
setQuantifier' forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ") Maybe (Sql92SelectTableSetQuantifierSyntax PgSelectTableSyntax)
setQuantifier forall a. Semigroup a => a -> a -> a
<>
PgProjectionSyntax -> PgSyntax
fromPgProjection Sql92SelectTableProjectionSyntax PgSelectTableSyntax
proj forall a. Semigroup a => a -> a -> a
<>
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit ByteString
" FROM " forall a. Semigroup a => a -> a -> a
<> ) (coerce :: forall a b. Coercible a b => a -> b
coerce Maybe (Sql92SelectTableFromSyntax PgSelectTableSyntax)
from)) forall a. Semigroup a => a -> a -> a
<>
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit ByteString
" WHERE " forall a. Semigroup a => a -> a -> a
<>) (coerce :: forall a b. Coercible a b => a -> b
coerce Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
where_)) forall a. Semigroup a => a -> a -> a
<>
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit ByteString
" GROUP BY " forall a. Semigroup a => a -> a -> a
<>) (coerce :: forall a b. Coercible a b => a -> b
coerce Maybe (Sql92SelectTableGroupingSyntax PgSelectTableSyntax)
grouping)) forall a. Semigroup a => a -> a -> a
<>
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit ByteString
" HAVING " forall a. Semigroup a => a -> a -> a
<>) (coerce :: forall a b. Coercible a b => a -> b
coerce Maybe (Sql92SelectTableExpressionSyntax PgSelectTableSyntax)
having))
unionTables :: Bool
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
unionTables Bool
all = ByteString
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
pgTableOp (if Bool
all then ByteString
"UNION ALL" else ByteString
"UNION")
intersectTables :: Bool
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
intersectTables Bool
all = ByteString
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
pgTableOp (if Bool
all then ByteString
"INTERSECT ALL" else ByteString
"INTERSECT")
exceptTable :: Bool
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
exceptTable Bool
all = ByteString
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
pgTableOp (if Bool
all then ByteString
"EXCEPT ALL" else ByteString
"EXCEPT")
instance IsSql92GroupingSyntax PgGroupingSyntax where
type Sql92GroupingExpressionSyntax PgGroupingSyntax = PgExpressionSyntax
groupByExpressions :: [Sql92GroupingExpressionSyntax PgGroupingSyntax]
-> PgGroupingSyntax
groupByExpressions [Sql92GroupingExpressionSyntax PgGroupingSyntax]
es =
PgSyntax -> PgGroupingSyntax
PgGroupingSyntax forall a b. (a -> b) -> a -> b
$
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [Sql92GroupingExpressionSyntax PgGroupingSyntax]
es)
instance IsSql92FromSyntax PgFromSyntax where
type Sql92FromExpressionSyntax PgFromSyntax = PgExpressionSyntax
type Sql92FromTableSourceSyntax PgFromSyntax = PgTableSourceSyntax
fromTable :: Sql92FromTableSourceSyntax PgFromSyntax
-> Maybe (Text, Maybe [Text]) -> PgFromSyntax
fromTable Sql92FromTableSourceSyntax PgFromSyntax
tableSrc Maybe (Text, Maybe [Text])
Nothing = coerce :: forall a b. Coercible a b => a -> b
coerce Sql92FromTableSourceSyntax PgFromSyntax
tableSrc
fromTable Sql92FromTableSourceSyntax PgFromSyntax
tableSrc (Just (Text
nm, Maybe [Text]
colNms)) =
PgSyntax -> PgFromSyntax
PgFromSyntax forall a b. (a -> b) -> a -> b
$
coerce :: forall a b. Coercible a b => a -> b
coerce Sql92FromTableSourceSyntax PgFromSyntax
tableSrc forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" AS " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
nm forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\[Text]
colNms' -> PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
",") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
colNms'))) Maybe [Text]
colNms
innerJoin :: PgFromSyntax
-> PgFromSyntax
-> Maybe (Sql92FromExpressionSyntax PgFromSyntax)
-> PgFromSyntax
innerJoin PgFromSyntax
a PgFromSyntax
b Maybe (Sql92FromExpressionSyntax PgFromSyntax)
Nothing = PgSyntax -> PgFromSyntax
PgFromSyntax (PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" CROSS JOIN " forall a. Semigroup a => a -> a -> a
<> PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
b)
innerJoin PgFromSyntax
a PgFromSyntax
b (Just Sql92FromExpressionSyntax PgFromSyntax
e) = ByteString
-> PgFromSyntax
-> PgFromSyntax
-> Maybe PgExpressionSyntax
-> PgFromSyntax
pgJoin ByteString
"INNER JOIN" PgFromSyntax
a PgFromSyntax
b (forall a. a -> Maybe a
Just Sql92FromExpressionSyntax PgFromSyntax
e)
leftJoin :: PgFromSyntax
-> PgFromSyntax
-> Maybe (Sql92FromExpressionSyntax PgFromSyntax)
-> PgFromSyntax
leftJoin = ByteString
-> PgFromSyntax
-> PgFromSyntax
-> Maybe PgExpressionSyntax
-> PgFromSyntax
pgJoin ByteString
"LEFT JOIN"
rightJoin :: PgFromSyntax
-> PgFromSyntax
-> Maybe (Sql92FromExpressionSyntax PgFromSyntax)
-> PgFromSyntax
rightJoin = ByteString
-> PgFromSyntax
-> PgFromSyntax
-> Maybe PgExpressionSyntax
-> PgFromSyntax
pgJoin ByteString
"RIGHT JOIN"
instance IsSql92FromOuterJoinSyntax PgFromSyntax where
outerJoin :: PgFromSyntax
-> PgFromSyntax
-> Maybe (Sql92FromExpressionSyntax PgFromSyntax)
-> PgFromSyntax
outerJoin = ByteString
-> PgFromSyntax
-> PgFromSyntax
-> Maybe PgExpressionSyntax
-> PgFromSyntax
pgJoin ByteString
"FULL OUTER JOIN"
instance IsSql92OrderingSyntax PgOrderingSyntax where
type Sql92OrderingExpressionSyntax PgOrderingSyntax = PgExpressionSyntax
ascOrdering :: Sql92OrderingExpressionSyntax PgOrderingSyntax -> PgOrderingSyntax
ascOrdering Sql92OrderingExpressionSyntax PgOrderingSyntax
e = PgSyntax -> Maybe PgNullOrdering -> PgOrderingSyntax
PgOrderingSyntax (PgExpressionSyntax -> PgSyntax
fromPgExpression Sql92OrderingExpressionSyntax PgOrderingSyntax
e forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ASC") forall a. Maybe a
Nothing
descOrdering :: Sql92OrderingExpressionSyntax PgOrderingSyntax -> PgOrderingSyntax
descOrdering Sql92OrderingExpressionSyntax PgOrderingSyntax
e = PgSyntax -> Maybe PgNullOrdering -> PgOrderingSyntax
PgOrderingSyntax (PgExpressionSyntax -> PgSyntax
fromPgExpression Sql92OrderingExpressionSyntax PgOrderingSyntax
e forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" DESC") forall a. Maybe a
Nothing
instance IsSql2003OrderingElementaryOLAPOperationsSyntax PgOrderingSyntax where
nullsFirstOrdering :: PgOrderingSyntax -> PgOrderingSyntax
nullsFirstOrdering PgOrderingSyntax
o = PgOrderingSyntax
o { pgOrderingNullOrdering :: Maybe PgNullOrdering
pgOrderingNullOrdering = forall a. a -> Maybe a
Just PgNullOrdering
PgNullOrderingNullsFirst }
nullsLastOrdering :: PgOrderingSyntax -> PgOrderingSyntax
nullsLastOrdering PgOrderingSyntax
o = PgOrderingSyntax
o { pgOrderingNullOrdering :: Maybe PgNullOrdering
pgOrderingNullOrdering = forall a. a -> Maybe a
Just PgNullOrdering
PgNullOrderingNullsLast }
instance IsSql92DataTypeSyntax PgDataTypeSyntax where
domainType :: Text -> PgDataTypeSyntax
domainType Text
nm = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Text -> PgDataTypeDescr
PgDataTypeDescrDomain Text
nm) (Text -> PgSyntax
pgQuotedIdentifier Text
nm)
(forall dataType. IsSql92DataTypeSyntax dataType => Text -> dataType
domainType Text
nm)
charType :: Maybe Word -> Maybe Text -> PgDataTypeSyntax
charType Maybe Word
prec Maybe Text
charSet = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.bpchar) (forall a. a -> Maybe a
Just (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. a -> Maybe a -> a
fromMaybe Word
1 Maybe Word
prec))))
(ByteString -> PgSyntax
emit ByteString
"CHAR" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec forall a. Semigroup a => a -> a -> a
<> Maybe Text -> PgSyntax
pgOptCharSet Maybe Text
charSet)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
charType Maybe Word
prec Maybe Text
charSet)
varCharType :: Maybe Word -> Maybe Text -> PgDataTypeSyntax
varCharType Maybe Word
prec Maybe Text
charSet = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.varchar) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral Maybe Word
prec))
(ByteString -> PgSyntax
emit ByteString
"VARCHAR" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec forall a. Semigroup a => a -> a -> a
<> Maybe Text -> PgSyntax
pgOptCharSet Maybe Text
charSet)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
varCharType Maybe Word
prec Maybe Text
charSet)
nationalCharType :: Maybe Word -> PgDataTypeSyntax
nationalCharType Maybe Word
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.bpchar) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral Maybe Word
prec))
(ByteString -> PgSyntax
emit ByteString
"NATIONAL CHAR" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalCharType Maybe Word
prec)
nationalVarCharType :: Maybe Word -> PgDataTypeSyntax
nationalVarCharType Maybe Word
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.varchar) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral Maybe Word
prec))
(ByteString -> PgSyntax
emit ByteString
"NATIONAL CHARACTER VARYING" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalVarCharType Maybe Word
prec)
bitType :: Maybe Word -> PgDataTypeSyntax
bitType Maybe Word
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.bit) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral Maybe Word
prec))
(ByteString -> PgSyntax
emit ByteString
"BIT" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
bitType Maybe Word
prec)
varBitType :: Maybe Word -> PgDataTypeSyntax
varBitType Maybe Word
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.varbit) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral Maybe Word
prec))
(ByteString -> PgSyntax
emit ByteString
"BIT VARYING" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
varBitType Maybe Word
prec)
numericType :: Maybe (Word, Maybe Word) -> PgDataTypeSyntax
numericType Maybe (Word, Maybe Word)
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.numeric) (Maybe (Word, Maybe Word) -> Maybe Int32
mkNumericPrec Maybe (Word, Maybe Word)
prec))
(ByteString -> PgSyntax
emit ByteString
"NUMERIC" forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> PgSyntax
pgOptNumericPrec Maybe (Word, Maybe Word)
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
numericType Maybe (Word, Maybe Word)
prec)
decimalType :: Maybe (Word, Maybe Word) -> PgDataTypeSyntax
decimalType Maybe (Word, Maybe Word)
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.numeric) (Maybe (Word, Maybe Word) -> Maybe Int32
mkNumericPrec Maybe (Word, Maybe Word)
prec))
(ByteString -> PgSyntax
emit ByteString
"DECIMAL" forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> PgSyntax
pgOptNumericPrec Maybe (Word, Maybe Word)
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
decimalType Maybe (Word, Maybe Word)
prec)
intType :: PgDataTypeSyntax
intType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.int4) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"INT") forall dataType. IsSql92DataTypeSyntax dataType => dataType
intType
smallIntType :: PgDataTypeSyntax
smallIntType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.int2) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"SMALLINT") forall dataType. IsSql92DataTypeSyntax dataType => dataType
smallIntType
floatType :: Maybe Word -> PgDataTypeSyntax
floatType Maybe Word
prec = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.float4) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"FLOAT" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
floatType Maybe Word
prec)
doubleType :: PgDataTypeSyntax
doubleType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.float8) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"DOUBLE PRECISION") forall dataType. IsSql92DataTypeSyntax dataType => dataType
doubleType
realType :: PgDataTypeSyntax
realType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.float4) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"REAL") forall dataType. IsSql92DataTypeSyntax dataType => dataType
realType
dateType :: PgDataTypeSyntax
dateType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.date) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"DATE") forall dataType. IsSql92DataTypeSyntax dataType => dataType
dateType
timeType :: Maybe Word -> Bool -> PgDataTypeSyntax
timeType Maybe Word
prec Bool
withTz = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.time) forall a. Maybe a
Nothing)
(ByteString -> PgSyntax
emit ByteString
"TIME" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then ByteString -> PgSyntax
emit ByteString
" WITH TIME ZONE" else forall a. Monoid a => a
mempty)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timeType Maybe Word
prec Bool
withTz)
timestampType :: Maybe Word -> Bool -> PgDataTypeSyntax
timestampType Maybe Word
prec Bool
withTz = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid (if Bool
withTz then TypeInfo
Pg.timestamptz else TypeInfo
Pg.timestamp)) forall a. Maybe a
Nothing)
(ByteString -> PgSyntax
emit ByteString
"TIMESTAMP" forall a. Semigroup a => a -> a -> a
<> Maybe Word -> PgSyntax
pgOptPrec Maybe Word
prec forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then ByteString -> PgSyntax
emit ByteString
" WITH TIME ZONE" else forall a. Monoid a => a
mempty)
(forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timestampType Maybe Word
prec Bool
withTz)
instance IsSql99DataTypeSyntax PgDataTypeSyntax where
characterLargeObjectType :: PgDataTypeSyntax
characterLargeObjectType = PgDataTypeSyntax
pgTextType { pgDataTypeSerialized :: BeamSerializedDataType
pgDataTypeSerialized = forall dataType. IsSql99DataTypeSyntax dataType => dataType
characterLargeObjectType }
binaryLargeObjectType :: PgDataTypeSyntax
binaryLargeObjectType = PgDataTypeSyntax
pgByteaType { pgDataTypeSerialized :: BeamSerializedDataType
pgDataTypeSerialized = forall dataType. IsSql99DataTypeSyntax dataType => dataType
binaryLargeObjectType }
booleanType :: PgDataTypeSyntax
booleanType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.bool) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"BOOLEAN")
forall dataType. IsSql99DataTypeSyntax dataType => dataType
booleanType
arrayType :: PgDataTypeSyntax -> Int -> PgDataTypeSyntax
arrayType (PgDataTypeSyntax PgDataTypeDescr
_ PgSyntax
syntax BeamSerializedDataType
serialized) Int
sz =
PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (forall a. HasCallStack => String -> a
error String
"TODO: array migrations")
(PgSyntax
syntax forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"[" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (forall a. IsString a => String -> a
fromString (forall a. Show a => a -> String
show Int
sz)) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"]")
(forall dataType.
IsSql99DataTypeSyntax dataType =>
dataType -> Int -> dataType
arrayType BeamSerializedDataType
serialized Int
sz)
rowType :: [(Text, PgDataTypeSyntax)] -> PgDataTypeSyntax
rowType = forall a. HasCallStack => String -> a
error String
"rowType"
instance IsSql99CommonTableExpressionSelectSyntax PgSelectSyntax where
type Sql99SelectCTESyntax PgSelectSyntax = PgCommonTableExpressionSyntax
withSyntax :: [Sql99SelectCTESyntax PgSelectSyntax]
-> PgSelectSyntax -> PgSelectSyntax
withSyntax [Sql99SelectCTESyntax PgSelectSyntax]
ctes (PgSelectSyntax PgSyntax
select) =
PgSyntax -> PgSelectSyntax
PgSelectSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"WITH " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgCommonTableExpressionSyntax -> PgSyntax
fromPgCommonTableExpression [Sql99SelectCTESyntax PgSelectSyntax]
ctes) forall a. Semigroup a => a -> a -> a
<>
PgSyntax
select
instance IsSql99RecursiveCommonTableExpressionSelectSyntax PgSelectSyntax where
withRecursiveSyntax :: [Sql99SelectCTESyntax PgSelectSyntax]
-> PgSelectSyntax -> PgSelectSyntax
withRecursiveSyntax [Sql99SelectCTESyntax PgSelectSyntax]
ctes (PgSelectSyntax PgSyntax
select) =
PgSyntax -> PgSelectSyntax
PgSelectSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"WITH RECURSIVE " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgCommonTableExpressionSyntax -> PgSyntax
fromPgCommonTableExpression [Sql99SelectCTESyntax PgSelectSyntax]
ctes) forall a. Semigroup a => a -> a -> a
<>
PgSyntax
select
instance IsSql99CommonTableExpressionSyntax PgCommonTableExpressionSyntax where
type Sql99CTESelectSyntax PgCommonTableExpressionSyntax = PgSelectSyntax
cteSubquerySyntax :: Text
-> [Text]
-> Sql99CTESelectSyntax PgCommonTableExpressionSyntax
-> PgCommonTableExpressionSyntax
cteSubquerySyntax Text
tbl [Text]
fields (PgSelectSyntax PgSyntax
select) =
PgSyntax -> PgCommonTableExpressionSyntax
PgCommonTableExpressionSyntax forall a b. (a -> b) -> a -> b
$
Text -> PgSyntax
pgQuotedIdentifier Text
tbl forall a. Semigroup a => a -> a -> a
<> PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
",") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
fields)) forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
" AS " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> PgSyntax
pgParens PgSyntax
select
instance IsSql2008BigIntDataTypeSyntax PgDataTypeSyntax where
bigIntType :: PgDataTypeSyntax
bigIntType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.int8) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"BIGINT") forall dataType. IsSql2008BigIntDataTypeSyntax dataType => dataType
bigIntType
instance Sql92SerializableDataTypeSyntax PgDataTypeSyntax where
serializeDataType :: PgDataTypeSyntax -> Value
serializeDataType = BeamSerializedDataType -> Value
fromBeamSerializedDataType forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgDataTypeSyntax -> BeamSerializedDataType
pgDataTypeSerialized
pgOptPrec :: Maybe Word -> PgSyntax
pgOptPrec :: Maybe Word -> PgSyntax
pgOptPrec Maybe Word
Nothing = forall a. Monoid a => a
mempty
pgOptPrec (Just Word
x) = ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (forall a. IsString a => String -> a
fromString (forall a. Show a => a -> String
show Word
x)) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgOptCharSet :: Maybe T.Text -> PgSyntax
pgOptCharSet :: Maybe Text -> PgSyntax
pgOptCharSet Maybe Text
Nothing = forall a. Monoid a => a
mempty
pgOptCharSet (Just Text
cs) = ByteString -> PgSyntax
emit ByteString
" CHARACTER SET " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (Text -> ByteString
TE.encodeUtf8 Text
cs)
pgOptNumericPrec :: Maybe (Word, Maybe Word) -> PgSyntax
pgOptNumericPrec :: Maybe (Word, Maybe Word) -> PgSyntax
pgOptNumericPrec Maybe (Word, Maybe Word)
Nothing = forall a. Monoid a => a
mempty
pgOptNumericPrec (Just (Word
prec, Maybe Word
Nothing)) = Maybe Word -> PgSyntax
pgOptPrec (forall a. a -> Maybe a
Just Word
prec)
pgOptNumericPrec (Just (Word
prec, Just Word
dec)) = ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (forall a. IsString a => String -> a
fromString (forall a. Show a => a -> String
show Word
prec)) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (forall a. IsString a => String -> a
fromString (forall a. Show a => a -> String
show Word
dec)) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgDataTypeJSON :: Value -> BeamSerializedDataType
pgDataTypeJSON :: Value -> BeamSerializedDataType
pgDataTypeJSON Value
v = Value -> BeamSerializedDataType
BeamSerializedDataType (Text -> Value -> Value
beamSerializeJSON Text
"postgres" Value
v)
pgByteaType :: PgDataTypeSyntax
pgByteaType :: PgDataTypeSyntax
pgByteaType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.bytea) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"BYTEA")
(Value -> BeamSerializedDataType
pgDataTypeJSON Value
"bytea")
pgSmallSerialType, pgSerialType, pgBigSerialType :: PgDataTypeSyntax
pgSmallSerialType :: PgDataTypeSyntax
pgSmallSerialType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (PgDataTypeSyntax -> PgDataTypeDescr
pgDataTypeDescr forall dataType. IsSql92DataTypeSyntax dataType => dataType
smallIntType) (ByteString -> PgSyntax
emit ByteString
"SMALLSERIAL") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"smallserial")
pgSerialType :: PgDataTypeSyntax
pgSerialType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (PgDataTypeSyntax -> PgDataTypeDescr
pgDataTypeDescr forall dataType. IsSql92DataTypeSyntax dataType => dataType
intType) (ByteString -> PgSyntax
emit ByteString
"SERIAL") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"serial")
pgBigSerialType :: PgDataTypeSyntax
pgBigSerialType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.int8) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"BIGSERIAL") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"bigserial")
pgPointType, pgLineType, pgLineSegmentType, pgBoxType :: PgDataTypeSyntax
pgPointType :: PgDataTypeSyntax
pgPointType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.point) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"POINT") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"point")
pgLineType :: PgDataTypeSyntax
pgLineType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.line) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"LINE") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"line")
pgLineSegmentType :: PgDataTypeSyntax
pgLineSegmentType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.lseg) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"LSEG") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"lseg")
pgBoxType :: PgDataTypeSyntax
pgBoxType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.box) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"BOX") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"box")
pgUnboundedArrayType :: PgDataTypeSyntax -> PgDataTypeSyntax
pgUnboundedArrayType :: PgDataTypeSyntax -> PgDataTypeSyntax
pgUnboundedArrayType (PgDataTypeSyntax PgDataTypeDescr
_ PgSyntax
syntax BeamSerializedDataType
serialized) =
PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (forall a. HasCallStack => String -> a
error String
"Can't do array migrations yet")
(PgSyntax
syntax forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"[]")
(Value -> BeamSerializedDataType
pgDataTypeJSON ([Pair] -> Value
object [ Key
"unbounded-array" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= BeamSerializedDataType -> Value
fromBeamSerializedDataType BeamSerializedDataType
serialized ]))
pgTsQueryTypeInfo :: Pg.TypeInfo
pgTsQueryTypeInfo :: TypeInfo
pgTsQueryTypeInfo = Oid -> Char -> Char -> ByteString -> TypeInfo
Pg.Basic (CUInt -> Oid
Pg.Oid CUInt
3615) Char
'U' Char
',' ByteString
"tsquery"
pgTsQueryType :: PgDataTypeSyntax
pgTsQueryType :: PgDataTypeSyntax
pgTsQueryType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
pgTsQueryTypeInfo) forall a. Maybe a
Nothing)
(ByteString -> PgSyntax
emit ByteString
"TSQUERY") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"tsquery")
pgTsVectorTypeInfo :: Pg.TypeInfo
pgTsVectorTypeInfo :: TypeInfo
pgTsVectorTypeInfo = Oid -> Char -> Char -> ByteString -> TypeInfo
Pg.Basic (CUInt -> Oid
Pg.Oid CUInt
3614) Char
'U' Char
',' ByteString
"tsvector"
pgTsVectorType :: PgDataTypeSyntax
pgTsVectorType :: PgDataTypeSyntax
pgTsVectorType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
pgTsVectorTypeInfo) forall a. Maybe a
Nothing)
(ByteString -> PgSyntax
emit ByteString
"TSVECTOR")
(Value -> BeamSerializedDataType
pgDataTypeJSON Value
"tsvector")
pgTextType :: PgDataTypeSyntax
pgTextType :: PgDataTypeSyntax
pgTextType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.text) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"TEXT")
(Value -> BeamSerializedDataType
pgDataTypeJSON Value
"text")
pgJsonType, pgJsonbType :: PgDataTypeSyntax
pgJsonType :: PgDataTypeSyntax
pgJsonType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.json) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"JSON") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"json")
pgJsonbType :: PgDataTypeSyntax
pgJsonbType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.jsonb) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"JSONB") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"jsonb")
pgUuidType :: PgDataTypeSyntax
pgUuidType :: PgDataTypeSyntax
pgUuidType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.uuid) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"UUID") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"uuid")
pgMoneyType :: PgDataTypeSyntax
pgMoneyType :: PgDataTypeSyntax
pgMoneyType = PgDataTypeDescr
-> PgSyntax -> BeamSerializedDataType -> PgDataTypeSyntax
PgDataTypeSyntax (Oid -> Maybe Int32 -> PgDataTypeDescr
PgDataTypeDescrOid (TypeInfo -> Oid
Pg.typoid TypeInfo
Pg.money) forall a. Maybe a
Nothing) (ByteString -> PgSyntax
emit ByteString
"MONEY") (Value -> BeamSerializedDataType
pgDataTypeJSON Value
"money")
mkNumericPrec :: Maybe (Word, Maybe Word) -> Maybe Int32
mkNumericPrec :: Maybe (Word, Maybe Word) -> Maybe Int32
mkNumericPrec Maybe (Word, Maybe Word)
Nothing = forall a. Maybe a
Nothing
mkNumericPrec (Just (Word
whole, Maybe Word
dec)) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ (forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
whole forall a. Bits a => a -> Int -> a
`shiftL` Int
16) forall a. Bits a => a -> a -> a
.|. (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. a -> Maybe a -> a
fromMaybe Word
0 Maybe Word
dec) forall a. Bits a => a -> a -> a
.&. Int32
0xFFFF)
instance IsCustomSqlSyntax PgExpressionSyntax where
newtype CustomSqlSyntax PgExpressionSyntax =
PgCustomExpressionSyntax { CustomSqlSyntax PgExpressionSyntax -> PgSyntax
fromPgCustomExpression :: PgSyntax }
deriving Semigroup (CustomSqlSyntax PgExpressionSyntax)
CustomSqlSyntax PgExpressionSyntax
[CustomSqlSyntax PgExpressionSyntax]
-> CustomSqlSyntax PgExpressionSyntax
CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [CustomSqlSyntax PgExpressionSyntax]
-> CustomSqlSyntax PgExpressionSyntax
$cmconcat :: [CustomSqlSyntax PgExpressionSyntax]
-> CustomSqlSyntax PgExpressionSyntax
mappend :: CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
$cmappend :: CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
mempty :: CustomSqlSyntax PgExpressionSyntax
$cmempty :: CustomSqlSyntax PgExpressionSyntax
Monoid
customExprSyntax :: CustomSqlSyntax PgExpressionSyntax -> PgExpressionSyntax
customExprSyntax = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. CustomSqlSyntax PgExpressionSyntax -> PgSyntax
fromPgCustomExpression
renderSyntax :: PgExpressionSyntax -> CustomSqlSyntax PgExpressionSyntax
renderSyntax = PgSyntax -> CustomSqlSyntax PgExpressionSyntax
PgCustomExpressionSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgSyntax -> PgSyntax
pgParens forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgExpressionSyntax -> PgSyntax
fromPgExpression
instance Semigroup (CustomSqlSyntax PgExpressionSyntax) where
<> :: CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
-> CustomSqlSyntax PgExpressionSyntax
(<>) = forall a. Monoid a => a -> a -> a
mappend
instance IsString (CustomSqlSyntax PgExpressionSyntax) where
fromString :: String -> CustomSqlSyntax PgExpressionSyntax
fromString = PgSyntax -> CustomSqlSyntax PgExpressionSyntax
PgCustomExpressionSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> PgSyntax
emit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
instance IsSql92QuantifierSyntax PgComparisonQuantifierSyntax where
quantifyOverAll :: PgComparisonQuantifierSyntax
quantifyOverAll = PgSyntax -> PgComparisonQuantifierSyntax
PgComparisonQuantifierSyntax (ByteString -> PgSyntax
emit ByteString
"ALL")
quantifyOverAny :: PgComparisonQuantifierSyntax
quantifyOverAny = PgSyntax -> PgComparisonQuantifierSyntax
PgComparisonQuantifierSyntax (ByteString -> PgSyntax
emit ByteString
"ANY")
instance IsSql92ExtractFieldSyntax PgExtractFieldSyntax where
secondsField :: PgExtractFieldSyntax
secondsField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"SECOND")
minutesField :: PgExtractFieldSyntax
minutesField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"MINUTE")
hourField :: PgExtractFieldSyntax
hourField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"HOUR")
dayField :: PgExtractFieldSyntax
dayField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"DAY")
monthField :: PgExtractFieldSyntax
monthField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"MONTH")
yearField :: PgExtractFieldSyntax
yearField = PgSyntax -> PgExtractFieldSyntax
PgExtractFieldSyntax (ByteString -> PgSyntax
emit ByteString
"YEAR")
instance IsSql92ExpressionSyntax PgExpressionSyntax where
type Sql92ExpressionValueSyntax PgExpressionSyntax = PgValueSyntax
type Sql92ExpressionSelectSyntax PgExpressionSyntax = PgSelectSyntax
type Sql92ExpressionFieldNameSyntax PgExpressionSyntax = PgFieldNameSyntax
type Sql92ExpressionQuantifierSyntax PgExpressionSyntax = PgComparisonQuantifierSyntax
type Sql92ExpressionCastTargetSyntax PgExpressionSyntax = PgDataTypeSyntax
type PgExpressionSyntax = PgExtractFieldSyntax
addE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
addE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"+"
subE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
subE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"-"
mulE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
mulE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"*"
divE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
divE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"/"
modE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
modE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"%"
orE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
orE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"OR"
andE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
andE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"AND"
likeE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
likeE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"LIKE"
overlapsE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
overlapsE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"OVERLAPS"
eqE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
eqE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
"="
neqE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
neqE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
"<>"
eqMaybeE :: PgExpressionSyntax
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
eqMaybeE PgExpressionSyntax
a PgExpressionSyntax
b PgExpressionSyntax
_ = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"IS NOT DISTINCT FROM" PgExpressionSyntax
a PgExpressionSyntax
b
neqMaybeE :: PgExpressionSyntax
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
neqMaybeE PgExpressionSyntax
a PgExpressionSyntax
b PgExpressionSyntax
_ = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"IS DISTINCT FROM" PgExpressionSyntax
a PgExpressionSyntax
b
ltE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
ltE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
"<"
gtE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
gtE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
">"
leE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
leE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
"<="
geE :: Maybe (Sql92ExpressionQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
geE = ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
">="
negateE :: PgExpressionSyntax -> PgExpressionSyntax
negateE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgUnOp ByteString
"-"
notE :: PgExpressionSyntax -> PgExpressionSyntax
notE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgUnOp ByteString
"NOT"
existsE :: Sql92ExpressionSelectSyntax PgExpressionSyntax
-> PgExpressionSyntax
existsE Sql92ExpressionSelectSyntax PgExpressionSyntax
select = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"EXISTS (" forall a. Semigroup a => a -> a -> a
<> PgSelectSyntax -> PgSyntax
fromPgSelect Sql92ExpressionSelectSyntax PgExpressionSyntax
select forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
uniqueE :: Sql92ExpressionSelectSyntax PgExpressionSyntax
-> PgExpressionSyntax
uniqueE Sql92ExpressionSelectSyntax PgExpressionSyntax
select = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"UNIQUE (" forall a. Semigroup a => a -> a -> a
<> PgSelectSyntax -> PgSyntax
fromPgSelect Sql92ExpressionSelectSyntax PgExpressionSyntax
select forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
isNotNullE :: PgExpressionSyntax -> PgExpressionSyntax
isNotNullE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS NOT NULL"
isNullE :: PgExpressionSyntax -> PgExpressionSyntax
isNullE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS NULL"
isTrueE :: PgExpressionSyntax -> PgExpressionSyntax
isTrueE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS TRUE"
isFalseE :: PgExpressionSyntax -> PgExpressionSyntax
isFalseE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS FALSE"
isNotTrueE :: PgExpressionSyntax -> PgExpressionSyntax
isNotTrueE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS NOT TRUE"
isNotFalseE :: PgExpressionSyntax -> PgExpressionSyntax
isNotFalseE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS NOT FALSE"
isUnknownE :: PgExpressionSyntax -> PgExpressionSyntax
isUnknownE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS UNKNOWN"
isNotUnknownE :: PgExpressionSyntax -> PgExpressionSyntax
isNotUnknownE = ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
"IS NOT UNKNOWN"
betweenE :: PgExpressionSyntax
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
betweenE PgExpressionSyntax
a PgExpressionSyntax
b PgExpressionSyntax
c = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") BETWEEN (" forall a. Semigroup a => a -> a -> a
<>
PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
b forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") AND (" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
c forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
valueE :: Sql92ExpressionValueSyntax PgExpressionSyntax -> PgExpressionSyntax
valueE = coerce :: forall a b. Coercible a b => a -> b
coerce
rowE :: [PgExpressionSyntax] -> PgExpressionSyntax
rowE [PgExpressionSyntax]
vs = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (coerce :: forall a b. Coercible a b => a -> b
coerce [PgExpressionSyntax]
vs) forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
")"
quantifierListE :: [PgExpressionSyntax] -> PgExpressionSyntax
quantifierListE [PgExpressionSyntax]
vs =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(VALUES " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PgSyntax -> PgSyntax
pgParens forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgExpressionSyntax -> PgSyntax
fromPgExpression) [PgExpressionSyntax]
vs) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
fieldE :: Sql92ExpressionFieldNameSyntax PgExpressionSyntax
-> PgExpressionSyntax
fieldE = coerce :: forall a b. Coercible a b => a -> b
coerce
subqueryE :: Sql92ExpressionSelectSyntax PgExpressionSyntax
-> PgExpressionSyntax
subqueryE Sql92ExpressionSelectSyntax PgExpressionSyntax
s = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgSelectSyntax -> PgSyntax
fromPgSelect Sql92ExpressionSelectSyntax PgExpressionSyntax
s forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
positionE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
positionE PgExpressionSyntax
needle PgExpressionSyntax
haystack =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"POSITION((" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
needle forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") IN (" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
haystack forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"))"
nullIfE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
nullIfE PgExpressionSyntax
a PgExpressionSyntax
b = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"NULLIF(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
b forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
absE :: PgExpressionSyntax -> PgExpressionSyntax
absE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"ABS(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
bitLengthE :: PgExpressionSyntax -> PgExpressionSyntax
bitLengthE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"BIT_LENGTH(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
charLengthE :: PgExpressionSyntax -> PgExpressionSyntax
charLengthE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"CHAR_LENGTH(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
octetLengthE :: PgExpressionSyntax -> PgExpressionSyntax
octetLengthE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"OCTET_LENGTH(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lowerE :: PgExpressionSyntax -> PgExpressionSyntax
lowerE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LOWER(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
upperE :: PgExpressionSyntax -> PgExpressionSyntax
upperE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"UPPER(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
trimE :: PgExpressionSyntax -> PgExpressionSyntax
trimE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"TRIM(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
coalesceE :: [PgExpressionSyntax] -> PgExpressionSyntax
coalesceE [PgExpressionSyntax]
es = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"COALESCE(" forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
es) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
extractE :: Sql92ExpressionExtractFieldSyntax PgExpressionSyntax
-> PgExpressionSyntax -> PgExpressionSyntax
extractE Sql92ExpressionExtractFieldSyntax PgExpressionSyntax
field PgExpressionSyntax
from = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"EXTRACT(" forall a. Semigroup a => a -> a -> a
<> PgExtractFieldSyntax -> PgSyntax
fromPgExtractField Sql92ExpressionExtractFieldSyntax PgExpressionSyntax
field forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" FROM (" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
from forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"))")
castE :: PgExpressionSyntax
-> Sql92ExpressionCastTargetSyntax PgExpressionSyntax
-> PgExpressionSyntax
castE PgExpressionSyntax
e Sql92ExpressionCastTargetSyntax PgExpressionSyntax
to = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"CAST((" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
e forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") AS " forall a. Semigroup a => a -> a -> a
<> PgDataTypeSyntax -> PgSyntax
fromPgDataType Sql92ExpressionCastTargetSyntax PgExpressionSyntax
to forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
caseE :: [(PgExpressionSyntax, PgExpressionSyntax)]
-> PgExpressionSyntax -> PgExpressionSyntax
caseE [(PgExpressionSyntax, PgExpressionSyntax)]
cases PgExpressionSyntax
else_ =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"CASE " forall a. Semigroup a => a -> a -> a
<>
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(PgExpressionSyntax
cond, PgExpressionSyntax
res) -> ByteString -> PgSyntax
emit ByteString
"WHEN " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
cond forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" THEN " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
res forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ") [(PgExpressionSyntax, PgExpressionSyntax)]
cases forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
"ELSE " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
else_ forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" END"
currentTimestampE :: PgExpressionSyntax
currentTimestampE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"CURRENT_TIMESTAMP"
defaultE :: PgExpressionSyntax
defaultE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"DEFAULT"
inE :: PgExpressionSyntax -> [PgExpressionSyntax] -> PgExpressionSyntax
inE PgExpressionSyntax
e [PgExpressionSyntax]
es = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ PgSyntax -> PgSyntax
pgParens (PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
e) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" IN " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
es))
inSelectE :: PgExpressionSyntax
-> Sql92ExpressionSelectSyntax PgExpressionSyntax
-> PgExpressionSyntax
inSelectE PgExpressionSyntax
e Sql92ExpressionSelectSyntax PgExpressionSyntax
sel = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ PgSyntax -> PgSyntax
pgParens (PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
e) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" IN " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> PgSyntax
pgParens (PgSelectSyntax -> PgSyntax
fromPgSelect Sql92ExpressionSelectSyntax PgExpressionSyntax
sel)
instance IsSql99FunctionExpressionSyntax PgExpressionSyntax where
functionCallE :: PgExpressionSyntax -> [PgExpressionSyntax] -> PgExpressionSyntax
functionCallE PgExpressionSyntax
name [PgExpressionSyntax]
args =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
name forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
args))
functionNameE :: Text -> PgExpressionSyntax
functionNameE Text
nm = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit (Text -> ByteString
TE.encodeUtf8 Text
nm))
instance IsSql99ExpressionSyntax PgExpressionSyntax where
distinctE :: Sql92ExpressionSelectSyntax PgExpressionSyntax
-> PgExpressionSyntax
distinctE Sql92ExpressionSelectSyntax PgExpressionSyntax
select = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"DISTINCT (" forall a. Semigroup a => a -> a -> a
<> PgSelectSyntax -> PgSyntax
fromPgSelect Sql92ExpressionSelectSyntax PgExpressionSyntax
select forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
similarToE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
similarToE = ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
"SIMILAR TO"
instanceFieldE :: PgExpressionSyntax -> Text -> PgExpressionSyntax
instanceFieldE PgExpressionSyntax
i Text
nm =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
PgSyntax -> PgSyntax
pgParens (PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
i) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"." forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
escapeIdentifier (Text -> ByteString
TE.encodeUtf8 Text
nm)
refFieldE :: PgExpressionSyntax -> Text -> PgExpressionSyntax
refFieldE PgExpressionSyntax
i Text
nm =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
PgSyntax -> PgSyntax
pgParens (PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
i) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"->" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
escapeIdentifier (Text -> ByteString
TE.encodeUtf8 Text
nm)
instance IsSql99ConcatExpressionSyntax PgExpressionSyntax where
concatE :: [PgExpressionSyntax] -> PgExpressionSyntax
concatE [] = forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax (Text
"" :: T.Text))
concatE [PgExpressionSyntax
x] = PgExpressionSyntax
x
concatE [PgExpressionSyntax]
es =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"CONCAT" forall a. Semigroup a => a -> a -> a
<> PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
es))
instance IsSql2003ExpressionSyntax PgExpressionSyntax where
type Sql2003ExpressionWindowFrameSyntax PgExpressionSyntax =
PgWindowFrameSyntax
overE :: PgExpressionSyntax
-> Sql2003ExpressionWindowFrameSyntax PgExpressionSyntax
-> PgExpressionSyntax
overE PgExpressionSyntax
expr Sql2003ExpressionWindowFrameSyntax PgExpressionSyntax
frame =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
expr forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgWindowFrameSyntax -> PgSyntax
fromPgWindowFrame Sql2003ExpressionWindowFrameSyntax PgExpressionSyntax
frame
rowNumberE :: PgExpressionSyntax
rowNumberE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"ROW_NUMBER()"
instance IsSql2003EnhancedNumericFunctionsExpressionSyntax PgExpressionSyntax where
lnE :: PgExpressionSyntax -> PgExpressionSyntax
lnE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LN(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
expE :: PgExpressionSyntax -> PgExpressionSyntax
expE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"EXP(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
sqrtE :: PgExpressionSyntax -> PgExpressionSyntax
sqrtE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"SQRT(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
ceilE :: PgExpressionSyntax -> PgExpressionSyntax
ceilE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"CEIL(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
floorE :: PgExpressionSyntax -> PgExpressionSyntax
floorE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"FLOOR(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
powerE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
powerE PgExpressionSyntax
x PgExpressionSyntax
y = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"POWER(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
y forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
instance IsSql2003ExpressionAdvancedOLAPOperationsSyntax PgExpressionSyntax where
denseRankAggE :: PgExpressionSyntax
denseRankAggE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"DENSE_RANK()"
percentRankAggE :: PgExpressionSyntax
percentRankAggE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"PERCENT_RANK()"
cumeDistAggE :: PgExpressionSyntax
cumeDistAggE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"CUME_DIST()"
instance IsSql2003ExpressionElementaryOLAPOperationsSyntax PgExpressionSyntax where
rankAggE :: PgExpressionSyntax
rankAggE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"RANK()"
filterAggE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
filterAggE PgExpressionSyntax
agg PgExpressionSyntax
filter =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
agg forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" FILTER (WHERE " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
filter forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
instance IsSql2003EnhancedNumericFunctionsAggregationExpressionSyntax PgExpressionSyntax where
stddevPopE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
stddevPopE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"STDDEV_POP"
stddevSampE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
stddevSampE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"STDDEV_SAMP"
varPopE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
varPopE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"VAR_POP"
varSampE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
varSampE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"VAR_SAMP"
covarPopE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
covarPopE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"COVAR_POP"
covarSampE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
covarSampE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"COVAR_SAMP"
corrE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
corrE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"CORR"
regrSlopeE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrSlopeE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_SLOPE"
regrInterceptE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrInterceptE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_INTERCEPT"
regrCountE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrCountE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_COUNT"
regrRSquaredE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrRSquaredE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_R2"
regrAvgXE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrAvgXE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_AVGX"
regrAvgYE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrAvgYE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_AVGY"
regrSXXE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrSXXE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_SXX"
regrSYYE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrSYYE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_SYY"
regrSXYE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
regrSXYE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
"REGR_SXY"
instance IsSql2003NtileExpressionSyntax PgExpressionSyntax where
ntileE :: PgExpressionSyntax -> PgExpressionSyntax
ntileE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"NTILE(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
instance IsSql2003LeadAndLagExpressionSyntax PgExpressionSyntax where
leadE :: PgExpressionSyntax
-> Maybe PgExpressionSyntax
-> Maybe PgExpressionSyntax
-> PgExpressionSyntax
leadE PgExpressionSyntax
x Maybe PgExpressionSyntax
Nothing Maybe PgExpressionSyntax
Nothing =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LEAD(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
leadE PgExpressionSyntax
x (Just PgExpressionSyntax
n) Maybe PgExpressionSyntax
Nothing =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LEAD(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
n forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
leadE PgExpressionSyntax
x (Just PgExpressionSyntax
n) (Just PgExpressionSyntax
def) =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LEAD(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
n forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
def forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
leadE PgExpressionSyntax
x Maybe PgExpressionSyntax
Nothing (Just PgExpressionSyntax
def) =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LEAD(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", 1, " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
def forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lagE :: PgExpressionSyntax
-> Maybe PgExpressionSyntax
-> Maybe PgExpressionSyntax
-> PgExpressionSyntax
lagE PgExpressionSyntax
x Maybe PgExpressionSyntax
Nothing Maybe PgExpressionSyntax
Nothing =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LAG(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lagE PgExpressionSyntax
x (Just PgExpressionSyntax
n) Maybe PgExpressionSyntax
Nothing =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LAG(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
n forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lagE PgExpressionSyntax
x (Just PgExpressionSyntax
n) (Just PgExpressionSyntax
def) =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LAG(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
n forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
def forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lagE PgExpressionSyntax
x Maybe PgExpressionSyntax
Nothing (Just PgExpressionSyntax
def) =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LAG(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", 1, " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
def forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
instance IsSql2003FirstValueAndLastValueExpressionSyntax PgExpressionSyntax where
firstValueE :: PgExpressionSyntax -> PgExpressionSyntax
firstValueE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"FIRST_VALUE(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
lastValueE :: PgExpressionSyntax -> PgExpressionSyntax
lastValueE PgExpressionSyntax
x = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"LAST_VALUE(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
instance IsSql2003NthValueExpressionSyntax PgExpressionSyntax where
nthValueE :: PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
nthValueE PgExpressionSyntax
x PgExpressionSyntax
n = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"NTH_VALUE(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
n forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
instance IsSql2003WindowFrameSyntax PgWindowFrameSyntax where
type Sql2003WindowFrameExpressionSyntax PgWindowFrameSyntax = PgExpressionSyntax
type Sql2003WindowFrameOrderingSyntax PgWindowFrameSyntax = PgOrderingSyntax
type Sql2003WindowFrameBoundsSyntax PgWindowFrameSyntax = PgWindowFrameBoundsSyntax
frameSyntax :: Maybe [Sql2003WindowFrameExpressionSyntax PgWindowFrameSyntax]
-> Maybe [Sql2003WindowFrameOrderingSyntax PgWindowFrameSyntax]
-> Maybe (Sql2003WindowFrameBoundsSyntax PgWindowFrameSyntax)
-> PgWindowFrameSyntax
frameSyntax Maybe [Sql2003WindowFrameExpressionSyntax PgWindowFrameSyntax]
partition_ Maybe [Sql2003WindowFrameOrderingSyntax PgWindowFrameSyntax]
ordering_ Maybe (Sql2003WindowFrameBoundsSyntax PgWindowFrameSyntax)
bounds_ =
PgSyntax -> PgWindowFrameSyntax
PgWindowFrameSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"OVER " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> PgSyntax
pgParens
(
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\[PgExpressionSyntax]
p -> ByteString -> PgSyntax
emit ByteString
"PARTITION BY " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
p)) Maybe [Sql2003WindowFrameExpressionSyntax PgWindowFrameSyntax]
partition_ forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\[PgOrderingSyntax]
o -> ByteString -> PgSyntax
emit ByteString
" ORDER BY " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgOrderingSyntax -> PgSyntax
fromPgOrdering [PgOrderingSyntax]
o)) Maybe [Sql2003WindowFrameOrderingSyntax PgWindowFrameSyntax]
ordering_ forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgWindowFrameBoundsSyntax
b -> ByteString -> PgSyntax
emit ByteString
" ROWS " forall a. Semigroup a => a -> a -> a
<> PgWindowFrameBoundsSyntax -> PgSyntax
fromPgWindowFrameBounds PgWindowFrameBoundsSyntax
b) Maybe (Sql2003WindowFrameBoundsSyntax PgWindowFrameSyntax)
bounds_
)
instance IsSql2003WindowFrameBoundsSyntax PgWindowFrameBoundsSyntax where
type Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax = PgWindowFrameBoundSyntax
fromToBoundSyntax :: Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
-> Maybe
(Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax)
-> PgWindowFrameBoundsSyntax
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
from Maybe
(Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax)
Nothing =
PgSyntax -> PgWindowFrameBoundsSyntax
PgWindowFrameBoundsSyntax (PgWindowFrameBoundSyntax -> ByteString -> PgSyntax
fromPgWindowFrameBound Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
from ByteString
"PRECEDING")
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
from (Just Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
to) =
PgSyntax -> PgWindowFrameBoundsSyntax
PgWindowFrameBoundsSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"BETWEEN " forall a. Semigroup a => a -> a -> a
<> PgWindowFrameBoundSyntax -> ByteString -> PgSyntax
fromPgWindowFrameBound Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
from ByteString
"PRECEDING" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" AND " forall a. Semigroup a => a -> a -> a
<> PgWindowFrameBoundSyntax -> ByteString -> PgSyntax
fromPgWindowFrameBound Sql2003WindowFrameBoundsBoundSyntax PgWindowFrameBoundsSyntax
to ByteString
"FOLLOWING"
instance IsSql2003WindowFrameBoundSyntax PgWindowFrameBoundSyntax where
unboundedSyntax :: PgWindowFrameBoundSyntax
unboundedSyntax = (ByteString -> PgSyntax) -> PgWindowFrameBoundSyntax
PgWindowFrameBoundSyntax forall a b. (a -> b) -> a -> b
$ \ByteString
where_ -> ByteString -> PgSyntax
emit ByteString
"UNBOUNDED " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
where_
nrowsBoundSyntax :: Int -> PgWindowFrameBoundSyntax
nrowsBoundSyntax Int
0 = (ByteString -> PgSyntax) -> PgWindowFrameBoundSyntax
PgWindowFrameBoundSyntax forall a b. (a -> b) -> a -> b
$ \ByteString
_ -> ByteString -> PgSyntax
emit ByteString
"CURRENT ROW"
nrowsBoundSyntax Int
n = (ByteString -> PgSyntax) -> PgWindowFrameBoundSyntax
PgWindowFrameBoundSyntax forall a b. (a -> b) -> a -> b
$ \ByteString
where_ -> ByteString -> PgSyntax
emit (forall a. IsString a => String -> a
fromString (forall a. Show a => a -> String
show Int
n)) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
where_
instance IsSql92AggregationExpressionSyntax PgExpressionSyntax where
type Sql92AggregationSetQuantifierSyntax PgExpressionSyntax = PgAggregationSetQuantifierSyntax
countAllE :: PgExpressionSyntax
countAllE = PgSyntax -> PgExpressionSyntax
PgExpressionSyntax (ByteString -> PgSyntax
emit ByteString
"COUNT(*)")
countE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
countE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"COUNT"
avgE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
avgE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"AVG"
sumE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
sumE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"SUM"
minE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
minE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"MIN"
maxE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
maxE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"MAX"
instance IsSql99AggregationExpressionSyntax PgExpressionSyntax where
everyE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
everyE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"EVERY"
someE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
someE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"BOOL_OR"
anyE :: Maybe (Sql92AggregationSetQuantifierSyntax PgExpressionSyntax)
-> PgExpressionSyntax -> PgExpressionSyntax
anyE = ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
"BOOL_OR"
instance IsSql92AggregationSetQuantifierSyntax PgAggregationSetQuantifierSyntax where
setQuantifierDistinct :: PgAggregationSetQuantifierSyntax
setQuantifierDistinct = PgSyntax -> PgAggregationSetQuantifierSyntax
PgAggregationSetQuantifierSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"DISTINCT"
setQuantifierAll :: PgAggregationSetQuantifierSyntax
setQuantifierAll = PgSyntax -> PgAggregationSetQuantifierSyntax
PgAggregationSetQuantifierSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"ALL"
instance IsSql92AggregationSetQuantifierSyntax PgSelectSetQuantifierSyntax where
setQuantifierDistinct :: PgSelectSetQuantifierSyntax
setQuantifierDistinct = PgSyntax -> PgSelectSetQuantifierSyntax
PgSelectSetQuantifierSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"DISTINCT"
setQuantifierAll :: PgSelectSetQuantifierSyntax
setQuantifierAll = PgSyntax -> PgSelectSetQuantifierSyntax
PgSelectSetQuantifierSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"ALL"
pgSelectSetQuantifierDistinctOn :: [PgExpressionSyntax] -> PgSelectSetQuantifierSyntax
pgSelectSetQuantifierDistinctOn :: [PgExpressionSyntax] -> PgSelectSetQuantifierSyntax
pgSelectSetQuantifierDistinctOn [PgExpressionSyntax]
exprs =
PgSyntax -> PgSelectSetQuantifierSyntax
PgSelectSetQuantifierSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"DISTINCT ON " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (PgExpressionSyntax -> PgSyntax
fromPgExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [PgExpressionSyntax]
exprs))
pgUnAgg :: ByteString -> Maybe PgAggregationSetQuantifierSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgUnAgg :: ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgUnAgg ByteString
fn Maybe PgAggregationSetQuantifierSyntax
q PgExpressionSyntax
e =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
fn forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgAggregationSetQuantifierSyntax
q -> PgAggregationSetQuantifierSyntax -> PgSyntax
fromPgAggregationSetQuantifier PgAggregationSetQuantifierSyntax
q forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ") Maybe PgAggregationSetQuantifierSyntax
q forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
e forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgBinAgg :: ByteString -> Maybe PgAggregationSetQuantifierSyntax -> PgExpressionSyntax -> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg :: ByteString
-> Maybe PgAggregationSetQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgBinAgg ByteString
fn Maybe PgAggregationSetQuantifierSyntax
q PgExpressionSyntax
x PgExpressionSyntax
y =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
fn forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgAggregationSetQuantifierSyntax
q -> PgAggregationSetQuantifierSyntax -> PgSyntax
fromPgAggregationSetQuantifier PgAggregationSetQuantifierSyntax
q forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ") Maybe PgAggregationSetQuantifierSyntax
q
forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
x forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
", " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
y forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
instance IsSql92FieldNameSyntax PgFieldNameSyntax where
qualifiedField :: Text -> Text -> PgFieldNameSyntax
qualifiedField Text
a Text
b =
PgSyntax -> PgFieldNameSyntax
PgFieldNameSyntax forall a b. (a -> b) -> a -> b
$
Text -> PgSyntax
pgQuotedIdentifier Text
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"." forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
b
unqualifiedField :: Text -> PgFieldNameSyntax
unqualifiedField = PgSyntax -> PgFieldNameSyntax
PgFieldNameSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PgSyntax
pgQuotedIdentifier
instance IsSql92TableSourceSyntax PgTableSourceSyntax where
type Sql92TableSourceSelectSyntax PgTableSourceSyntax = PgSelectSyntax
type Sql92TableSourceExpressionSyntax PgTableSourceSyntax = PgExpressionSyntax
type Sql92TableSourceTableNameSyntax PgTableSourceSyntax = PgTableNameSyntax
tableNamed :: Sql92TableSourceTableNameSyntax PgTableSourceSyntax
-> PgTableSourceSyntax
tableNamed = PgSyntax -> PgTableSourceSyntax
PgTableSourceSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgTableNameSyntax -> PgSyntax
fromPgTableName
tableFromSubSelect :: Sql92TableSourceSelectSyntax PgTableSourceSyntax
-> PgTableSourceSyntax
tableFromSubSelect Sql92TableSourceSelectSyntax PgTableSourceSyntax
s = PgSyntax -> PgTableSourceSyntax
PgTableSourceSyntax forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgSelectSyntax -> PgSyntax
fromPgSelect Sql92TableSourceSelectSyntax PgTableSourceSyntax
s forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
tableFromValues :: [[Sql92TableSourceExpressionSyntax PgTableSourceSyntax]]
-> PgTableSourceSyntax
tableFromValues [[Sql92TableSourceExpressionSyntax PgTableSourceSyntax]]
vss = PgSyntax -> PgTableSourceSyntax
PgTableSourceSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgSyntax -> PgSyntax
pgParens forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"VALUES " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ")
(forall a b. (a -> b) -> [a] -> [b]
map (\[PgExpressionSyntax]
vs -> PgSyntax -> PgSyntax
pgParens (PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ")
(forall a b. (a -> b) -> [a] -> [b]
map PgExpressionSyntax -> PgSyntax
fromPgExpression [PgExpressionSyntax]
vs))) [[Sql92TableSourceExpressionSyntax PgTableSourceSyntax]]
vss)
instance IsSql92ProjectionSyntax PgProjectionSyntax where
type Sql92ProjectionExpressionSyntax PgProjectionSyntax = PgExpressionSyntax
projExprs :: [(Sql92ProjectionExpressionSyntax PgProjectionSyntax, Maybe Text)]
-> PgProjectionSyntax
projExprs [(Sql92ProjectionExpressionSyntax PgProjectionSyntax, Maybe Text)]
exprs =
PgSyntax -> PgProjectionSyntax
PgProjectionSyntax forall a b. (a -> b) -> a -> b
$
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ")
(forall a b. (a -> b) -> [a] -> [b]
map (\(PgExpressionSyntax
expr, Maybe Text
nm) -> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
expr forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Text
nm -> ByteString -> PgSyntax
emit ByteString
" AS " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
nm) Maybe Text
nm) [(Sql92ProjectionExpressionSyntax PgProjectionSyntax, Maybe Text)]
exprs)
instance IsSql92InsertSyntax PgInsertSyntax where
type Sql92InsertTableNameSyntax PgInsertSyntax = PgTableNameSyntax
type Sql92InsertValuesSyntax PgInsertSyntax = PgInsertValuesSyntax
insertStmt :: Sql92InsertTableNameSyntax PgInsertSyntax
-> [Text]
-> Sql92InsertValuesSyntax PgInsertSyntax
-> PgInsertSyntax
insertStmt Sql92InsertTableNameSyntax PgInsertSyntax
tblName [Text]
fields Sql92InsertValuesSyntax PgInsertSyntax
values =
PgSyntax -> PgInsertSyntax
PgInsertSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"INSERT INTO " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92InsertTableNameSyntax PgInsertSyntax
tblName forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
fields) forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
") " forall a. Semigroup a => a -> a -> a
<> PgInsertValuesSyntax -> PgSyntax
fromPgInsertValues Sql92InsertValuesSyntax PgInsertSyntax
values
instance IsSql92InsertValuesSyntax PgInsertValuesSyntax where
type Sql92InsertValuesExpressionSyntax PgInsertValuesSyntax = PgExpressionSyntax
type Sql92InsertValuesSelectSyntax PgInsertValuesSyntax = PgSelectSyntax
insertSqlExpressions :: [[Sql92InsertValuesExpressionSyntax PgInsertValuesSyntax]]
-> PgInsertValuesSyntax
insertSqlExpressions [[Sql92InsertValuesExpressionSyntax PgInsertValuesSyntax]]
es =
PgSyntax -> PgInsertValuesSyntax
PgInsertValuesSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"VALUES " forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ")
(forall a b. (a -> b) -> [a] -> [b]
map (\[PgExpressionSyntax]
es -> ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (coerce :: forall a b. Coercible a b => a -> b
coerce [PgExpressionSyntax]
es) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
[[Sql92InsertValuesExpressionSyntax PgInsertValuesSyntax]]
es)
insertFromSql :: Sql92InsertValuesSelectSyntax PgInsertValuesSyntax
-> PgInsertValuesSyntax
insertFromSql (PgSelectSyntax PgSyntax
a) = PgSyntax -> PgInsertValuesSyntax
PgInsertValuesSyntax PgSyntax
a
instance IsSql92DropTableSyntax PgDropTableSyntax where
type Sql92DropTableTableNameSyntax PgDropTableSyntax = PgTableNameSyntax
dropTableSyntax :: Sql92DropTableTableNameSyntax PgDropTableSyntax
-> PgDropTableSyntax
dropTableSyntax Sql92DropTableTableNameSyntax PgDropTableSyntax
tblNm =
PgSyntax -> PgDropTableSyntax
PgDropTableSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"DROP TABLE " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92DropTableTableNameSyntax PgDropTableSyntax
tblNm
instance IsSql92AlterTableSyntax PgAlterTableSyntax where
type Sql92AlterTableAlterTableActionSyntax PgAlterTableSyntax = PgAlterTableActionSyntax
type Sql92AlterTableTableNameSyntax PgAlterTableSyntax = PgTableNameSyntax
alterTableSyntax :: Sql92AlterTableTableNameSyntax PgAlterTableSyntax
-> Sql92AlterTableAlterTableActionSyntax PgAlterTableSyntax
-> PgAlterTableSyntax
alterTableSyntax Sql92AlterTableTableNameSyntax PgAlterTableSyntax
tblNm Sql92AlterTableAlterTableActionSyntax PgAlterTableSyntax
action =
PgSyntax -> PgAlterTableSyntax
PgAlterTableSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"ALTER TABLE " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92AlterTableTableNameSyntax PgAlterTableSyntax
tblNm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgAlterTableActionSyntax -> PgSyntax
fromPgAlterTableAction Sql92AlterTableAlterTableActionSyntax PgAlterTableSyntax
action
instance IsSql92AlterTableActionSyntax PgAlterTableActionSyntax where
type Sql92AlterTableAlterColumnActionSyntax PgAlterTableActionSyntax = PgAlterColumnActionSyntax
type Sql92AlterTableColumnSchemaSyntax PgAlterTableActionSyntax = PgColumnSchemaSyntax
alterColumnSyntax :: Text
-> Sql92AlterTableAlterColumnActionSyntax PgAlterTableActionSyntax
-> PgAlterTableActionSyntax
alterColumnSyntax Text
colNm Sql92AlterTableAlterColumnActionSyntax PgAlterTableActionSyntax
action =
PgSyntax -> PgAlterTableActionSyntax
PgAlterTableActionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"ALTER COLUMN " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
colNm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgAlterColumnActionSyntax -> PgSyntax
fromPgAlterColumnAction Sql92AlterTableAlterColumnActionSyntax PgAlterTableActionSyntax
action
addColumnSyntax :: Text
-> Sql92AlterTableColumnSchemaSyntax PgAlterTableActionSyntax
-> PgAlterTableActionSyntax
addColumnSyntax Text
colNm Sql92AlterTableColumnSchemaSyntax PgAlterTableActionSyntax
schema =
PgSyntax -> PgAlterTableActionSyntax
PgAlterTableActionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"ADD COLUMN " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
colNm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgColumnSchemaSyntax -> PgSyntax
fromPgColumnSchema Sql92AlterTableColumnSchemaSyntax PgAlterTableActionSyntax
schema
dropColumnSyntax :: Text -> PgAlterTableActionSyntax
dropColumnSyntax Text
colNm =
PgSyntax -> PgAlterTableActionSyntax
PgAlterTableActionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"DROP COLUMN " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
colNm
renameTableToSyntax :: Text -> PgAlterTableActionSyntax
renameTableToSyntax Text
newNm =
PgSyntax -> PgAlterTableActionSyntax
PgAlterTableActionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"RENAME TO " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
newNm
renameColumnToSyntax :: Text -> Text -> PgAlterTableActionSyntax
renameColumnToSyntax Text
oldNm Text
newNm =
PgSyntax -> PgAlterTableActionSyntax
PgAlterTableActionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"RENAME COLUMN " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
oldNm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" TO " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
newNm
instance IsSql92AlterColumnActionSyntax PgAlterColumnActionSyntax where
setNullSyntax :: PgAlterColumnActionSyntax
setNullSyntax = PgSyntax -> PgAlterColumnActionSyntax
PgAlterColumnActionSyntax (ByteString -> PgSyntax
emit ByteString
"DROP NOT NULL")
setNotNullSyntax :: PgAlterColumnActionSyntax
setNotNullSyntax = PgSyntax -> PgAlterColumnActionSyntax
PgAlterColumnActionSyntax (ByteString -> PgSyntax
emit ByteString
"SET NOT NULL")
instance IsSql92CreateTableSyntax PgCreateTableSyntax where
type Sql92CreateTableTableNameSyntax PgCreateTableSyntax = PgTableNameSyntax
type Sql92CreateTableColumnSchemaSyntax PgCreateTableSyntax = PgColumnSchemaSyntax
type Sql92CreateTableTableConstraintSyntax PgCreateTableSyntax = PgTableConstraintSyntax
type Sql92CreateTableOptionsSyntax PgCreateTableSyntax = PgTableOptionsSyntax
createTableSyntax :: Maybe (Sql92CreateTableOptionsSyntax PgCreateTableSyntax)
-> Sql92CreateTableTableNameSyntax PgCreateTableSyntax
-> [(Text, Sql92CreateTableColumnSchemaSyntax PgCreateTableSyntax)]
-> [Sql92CreateTableTableConstraintSyntax PgCreateTableSyntax]
-> PgCreateTableSyntax
createTableSyntax Maybe (Sql92CreateTableOptionsSyntax PgCreateTableSyntax)
options Sql92CreateTableTableNameSyntax PgCreateTableSyntax
tblNm [(Text, Sql92CreateTableColumnSchemaSyntax PgCreateTableSyntax)]
fieldTypes [Sql92CreateTableTableConstraintSyntax PgCreateTableSyntax]
constraints =
let (PgSyntax
beforeOptions, PgSyntax
afterOptions) =
case Maybe (Sql92CreateTableOptionsSyntax PgCreateTableSyntax)
options of
Maybe (Sql92CreateTableOptionsSyntax PgCreateTableSyntax)
Nothing -> (ByteString -> PgSyntax
emit ByteString
" ", ByteString -> PgSyntax
emit ByteString
" ")
Just (PgTableOptionsSyntax PgSyntax
before PgSyntax
after) ->
( ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgSyntax
before forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" "
, ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgSyntax
after forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " )
in PgSyntax -> PgCreateTableSyntax
PgCreateTableSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"CREATE" forall a. Semigroup a => a -> a -> a
<> PgSyntax
beforeOptions forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"TABLE " forall a. Semigroup a => a -> a -> a
<> PgTableNameSyntax -> PgSyntax
fromPgTableName Sql92CreateTableTableNameSyntax PgCreateTableSyntax
tblNm forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
" (" forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ")
(forall a b. (a -> b) -> [a] -> [b]
map (\(Text
nm, PgColumnSchemaSyntax
type_) -> Text -> PgSyntax
pgQuotedIdentifier Text
nm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgColumnSchemaSyntax -> PgSyntax
fromPgColumnSchema PgColumnSchemaSyntax
type_) [(Text, Sql92CreateTableColumnSchemaSyntax PgCreateTableSyntax)]
fieldTypes forall a. Semigroup a => a -> a -> a
<>
forall a b. (a -> b) -> [a] -> [b]
map PgTableConstraintSyntax -> PgSyntax
fromPgTableConstraint [Sql92CreateTableTableConstraintSyntax PgCreateTableSyntax]
constraints)
forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")" forall a. Semigroup a => a -> a -> a
<> PgSyntax
afterOptions
instance IsSql92TableConstraintSyntax PgTableConstraintSyntax where
primaryKeyConstraintSyntax :: [Text] -> PgTableConstraintSyntax
primaryKeyConstraintSyntax [Text]
fieldNames =
PgSyntax -> PgTableConstraintSyntax
PgTableConstraintSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"PRIMARY KEY(" forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
fieldNames) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
instance Hashable PgColumnSchemaSyntax where
hashWithSalt :: Int -> PgColumnSchemaSyntax -> Int
hashWithSalt Int
salt = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgColumnSchemaSyntax -> PgSyntax
fromPgColumnSchema
instance IsSql92ColumnSchemaSyntax PgColumnSchemaSyntax where
type Sql92ColumnSchemaColumnTypeSyntax PgColumnSchemaSyntax = PgDataTypeSyntax
type Sql92ColumnSchemaExpressionSyntax PgColumnSchemaSyntax = PgExpressionSyntax
type Sql92ColumnSchemaColumnConstraintDefinitionSyntax PgColumnSchemaSyntax = PgColumnConstraintDefinitionSyntax
columnSchemaSyntax :: Sql92ColumnSchemaColumnTypeSyntax PgColumnSchemaSyntax
-> Maybe (Sql92ColumnSchemaExpressionSyntax PgColumnSchemaSyntax)
-> [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
PgColumnSchemaSyntax]
-> Maybe Text
-> PgColumnSchemaSyntax
columnSchemaSyntax Sql92ColumnSchemaColumnTypeSyntax PgColumnSchemaSyntax
colType Maybe (Sql92ColumnSchemaExpressionSyntax PgColumnSchemaSyntax)
defaultClause [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
PgColumnSchemaSyntax]
constraints Maybe Text
collation =
PgSyntax -> PgColumnSchemaSyntax
PgColumnSchemaSyntax PgSyntax
syntax
where
syntax :: PgSyntax
syntax =
PgDataTypeSyntax -> PgSyntax
fromPgDataType Sql92ColumnSchemaColumnTypeSyntax PgColumnSchemaSyntax
colType forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgExpressionSyntax
d -> ByteString -> PgSyntax
emit ByteString
" DEFAULT " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
d) Maybe (Sql92ColumnSchemaExpressionSyntax PgColumnSchemaSyntax)
defaultClause forall a. Semigroup a => a -> a -> a
<>
(case [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
PgColumnSchemaSyntax]
constraints of
[] -> forall a. Monoid a => a
mempty
[Sql92ColumnSchemaColumnConstraintDefinitionSyntax
PgColumnSchemaSyntax]
_ -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\PgColumnConstraintDefinitionSyntax
c -> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgColumnConstraintDefinitionSyntax -> PgSyntax
fromPgColumnConstraintDefinition PgColumnConstraintDefinitionSyntax
c) [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
PgColumnSchemaSyntax]
constraints) forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Text
nm -> ByteString -> PgSyntax
emit ByteString
" COLLATE " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
nm) Maybe Text
collation
instance IsSql92MatchTypeSyntax PgMatchTypeSyntax where
fullMatchSyntax :: PgMatchTypeSyntax
fullMatchSyntax = PgSyntax -> BeamSerializedMatchType -> PgMatchTypeSyntax
PgMatchTypeSyntax (ByteString -> PgSyntax
emit ByteString
"FULL") forall match. IsSql92MatchTypeSyntax match => match
fullMatchSyntax
partialMatchSyntax :: PgMatchTypeSyntax
partialMatchSyntax = PgSyntax -> BeamSerializedMatchType -> PgMatchTypeSyntax
PgMatchTypeSyntax (ByteString -> PgSyntax
emit ByteString
"PARTIAL") forall match. IsSql92MatchTypeSyntax match => match
partialMatchSyntax
pgMatchTypeJSON :: Value -> BeamSerializedMatchType
pgMatchTypeJSON :: Value -> BeamSerializedMatchType
pgMatchTypeJSON Value
v = Value -> BeamSerializedMatchType
BeamSerializedMatchType (Text -> Value -> Value
beamSerializeJSON Text
"postgres" Value
v)
pgSimpleMatchSyntax :: PgMatchTypeSyntax
pgSimpleMatchSyntax :: PgMatchTypeSyntax
pgSimpleMatchSyntax = PgSyntax -> BeamSerializedMatchType -> PgMatchTypeSyntax
PgMatchTypeSyntax (ByteString -> PgSyntax
emit ByteString
"SIMPLE") (Value -> BeamSerializedMatchType
pgMatchTypeJSON Value
"simple")
instance IsSql92ReferentialActionSyntax PgReferentialActionSyntax where
referentialActionCascadeSyntax :: PgReferentialActionSyntax
referentialActionCascadeSyntax = PgSyntax
-> BeamSerializedReferentialAction -> PgReferentialActionSyntax
PgReferentialActionSyntax (ByteString -> PgSyntax
emit ByteString
"CASCADE") forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionCascadeSyntax
referentialActionNoActionSyntax :: PgReferentialActionSyntax
referentialActionNoActionSyntax = PgSyntax
-> BeamSerializedReferentialAction -> PgReferentialActionSyntax
PgReferentialActionSyntax (ByteString -> PgSyntax
emit ByteString
"NO ACTION") forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionNoActionSyntax
referentialActionSetDefaultSyntax :: PgReferentialActionSyntax
referentialActionSetDefaultSyntax = PgSyntax
-> BeamSerializedReferentialAction -> PgReferentialActionSyntax
PgReferentialActionSyntax (ByteString -> PgSyntax
emit ByteString
"SET DEFAULT") forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionSetDefaultSyntax
referentialActionSetNullSyntax :: PgReferentialActionSyntax
referentialActionSetNullSyntax = PgSyntax
-> BeamSerializedReferentialAction -> PgReferentialActionSyntax
PgReferentialActionSyntax (ByteString -> PgSyntax
emit ByteString
"SET NULL") forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionSetNullSyntax
fromSqlConstraintAttributes :: SqlConstraintAttributesBuilder -> PgSyntax
fromSqlConstraintAttributes :: SqlConstraintAttributesBuilder -> PgSyntax
fromSqlConstraintAttributes (SqlConstraintAttributesBuilder Maybe ConstraintAttributeTiming
timing Maybe Bool
deferrable) =
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty ConstraintAttributeTiming -> PgSyntax
timingBuilder Maybe ConstraintAttributeTiming
timing forall a. Semigroup a => a -> a -> a
<> forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty Bool -> PgSyntax
deferrableBuilder Maybe Bool
deferrable
where timingBuilder :: ConstraintAttributeTiming -> PgSyntax
timingBuilder ConstraintAttributeTiming
InitiallyDeferred = ByteString -> PgSyntax
emit ByteString
"INITIALLY DEFERRED"
timingBuilder ConstraintAttributeTiming
InitiallyImmediate = ByteString -> PgSyntax
emit ByteString
"INITIALLY IMMEDIATE"
deferrableBuilder :: Bool -> PgSyntax
deferrableBuilder Bool
False = ByteString -> PgSyntax
emit ByteString
"NOT DEFERRABLE"
deferrableBuilder Bool
True = ByteString -> PgSyntax
emit ByteString
"DEFERRABLE"
instance Hashable PgColumnConstraintDefinitionSyntax where
hashWithSalt :: Int -> PgColumnConstraintDefinitionSyntax -> Int
hashWithSalt Int
salt = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgColumnConstraintDefinitionSyntax -> PgSyntax
fromPgColumnConstraintDefinition
instance IsSql92ColumnConstraintDefinitionSyntax PgColumnConstraintDefinitionSyntax where
type Sql92ColumnConstraintDefinitionConstraintSyntax PgColumnConstraintDefinitionSyntax = PgColumnConstraintSyntax
type Sql92ColumnConstraintDefinitionAttributesSyntax PgColumnConstraintDefinitionSyntax = SqlConstraintAttributesBuilder
constraintDefinitionSyntax :: Maybe Text
-> Sql92ColumnConstraintDefinitionConstraintSyntax
PgColumnConstraintDefinitionSyntax
-> Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
PgColumnConstraintDefinitionSyntax)
-> PgColumnConstraintDefinitionSyntax
constraintDefinitionSyntax Maybe Text
nm Sql92ColumnConstraintDefinitionConstraintSyntax
PgColumnConstraintDefinitionSyntax
constraint Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
PgColumnConstraintDefinitionSyntax)
attrs =
PgSyntax
-> BeamSerializedConstraintDefinition
-> PgColumnConstraintDefinitionSyntax
PgColumnConstraintDefinitionSyntax PgSyntax
syntax
(forall constraint.
IsSql92ColumnConstraintDefinitionSyntax constraint =>
Maybe Text
-> Sql92ColumnConstraintDefinitionConstraintSyntax constraint
-> Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax constraint)
-> constraint
constraintDefinitionSyntax Maybe Text
nm (PgColumnConstraintSyntax -> BeamSerializedConstraint
pgColumnConstraintSerialized Sql92ColumnConstraintDefinitionConstraintSyntax
PgColumnConstraintDefinitionSyntax
constraint) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqlConstraintAttributesBuilder
-> BeamSerializedConstraintAttributes
sqlConstraintAttributesSerialized Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
PgColumnConstraintDefinitionSyntax)
attrs))
where
syntax :: PgSyntax
syntax =
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Text
nm -> ByteString -> PgSyntax
emit ByteString
"CONSTRAINT " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
nm forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " ) Maybe Text
nm forall a. Semigroup a => a -> a -> a
<>
PgColumnConstraintSyntax -> PgSyntax
fromPgColumnConstraint Sql92ColumnConstraintDefinitionConstraintSyntax
PgColumnConstraintDefinitionSyntax
constraint forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\SqlConstraintAttributesBuilder
a -> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> SqlConstraintAttributesBuilder -> PgSyntax
fromSqlConstraintAttributes SqlConstraintAttributesBuilder
a) Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
PgColumnConstraintDefinitionSyntax)
attrs
instance Sql92SerializableConstraintDefinitionSyntax PgColumnConstraintDefinitionSyntax where
serializeConstraint :: PgColumnConstraintDefinitionSyntax -> Value
serializeConstraint = BeamSerializedConstraintDefinition -> Value
fromBeamSerializedConstraintDefinition forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgColumnConstraintDefinitionSyntax
-> BeamSerializedConstraintDefinition
pgColumnConstraintDefinitionSerialized
instance IsSql92ColumnConstraintSyntax PgColumnConstraintSyntax where
type Sql92ColumnConstraintMatchTypeSyntax PgColumnConstraintSyntax = PgMatchTypeSyntax
type Sql92ColumnConstraintReferentialActionSyntax PgColumnConstraintSyntax = PgReferentialActionSyntax
type Sql92ColumnConstraintExpressionSyntax PgColumnConstraintSyntax = PgExpressionSyntax
notNullConstraintSyntax :: PgColumnConstraintSyntax
notNullConstraintSyntax = PgSyntax -> BeamSerializedConstraint -> PgColumnConstraintSyntax
PgColumnConstraintSyntax (ByteString -> PgSyntax
emit ByteString
"NOT NULL") forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
notNullConstraintSyntax
uniqueColumnConstraintSyntax :: PgColumnConstraintSyntax
uniqueColumnConstraintSyntax = PgSyntax -> BeamSerializedConstraint -> PgColumnConstraintSyntax
PgColumnConstraintSyntax (ByteString -> PgSyntax
emit ByteString
"UNIQUE") forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
uniqueColumnConstraintSyntax
primaryKeyColumnConstraintSyntax :: PgColumnConstraintSyntax
primaryKeyColumnConstraintSyntax = PgSyntax -> BeamSerializedConstraint -> PgColumnConstraintSyntax
PgColumnConstraintSyntax (ByteString -> PgSyntax
emit ByteString
"PRIMARY KEY") forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
primaryKeyColumnConstraintSyntax
checkColumnConstraintSyntax :: Sql92ColumnConstraintExpressionSyntax PgColumnConstraintSyntax
-> PgColumnConstraintSyntax
checkColumnConstraintSyntax Sql92ColumnConstraintExpressionSyntax PgColumnConstraintSyntax
expr =
PgSyntax -> BeamSerializedConstraint -> PgColumnConstraintSyntax
PgColumnConstraintSyntax (ByteString -> PgSyntax
emit ByteString
"CHECK(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression Sql92ColumnConstraintExpressionSyntax PgColumnConstraintSyntax
expr forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
(forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
Sql92ColumnConstraintExpressionSyntax constraint -> constraint
checkColumnConstraintSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> BeamSerializedExpression
BeamSerializedExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
TE.decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ByteString -> ByteString
toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgSyntax -> ByteString
pgRenderSyntaxScript forall b c a. (b -> c) -> (a -> b) -> a -> c
. PgExpressionSyntax -> PgSyntax
fromPgExpression forall a b. (a -> b) -> a -> b
$ Sql92ColumnConstraintExpressionSyntax PgColumnConstraintSyntax
expr)
referencesConstraintSyntax :: Text
-> [Text]
-> Maybe
(Sql92ColumnConstraintMatchTypeSyntax PgColumnConstraintSyntax)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
-> PgColumnConstraintSyntax
referencesConstraintSyntax Text
tbl [Text]
fields Maybe
(Sql92ColumnConstraintMatchTypeSyntax PgColumnConstraintSyntax)
matchType Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onUpdate Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onDelete =
PgSyntax -> BeamSerializedConstraint -> PgColumnConstraintSyntax
PgColumnConstraintSyntax PgSyntax
syntax
(forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
Text
-> [Text]
-> Maybe (Sql92ColumnConstraintMatchTypeSyntax constraint)
-> Maybe (Sql92ColumnConstraintReferentialActionSyntax constraint)
-> Maybe (Sql92ColumnConstraintReferentialActionSyntax constraint)
-> constraint
referencesConstraintSyntax Text
tbl [Text]
fields (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PgMatchTypeSyntax -> BeamSerializedMatchType
pgMatchTypeSerialized Maybe
(Sql92ColumnConstraintMatchTypeSyntax PgColumnConstraintSyntax)
matchType)
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PgReferentialActionSyntax -> BeamSerializedReferentialAction
pgReferentialActionSerialized Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onUpdate)
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PgReferentialActionSyntax -> BeamSerializedReferentialAction
pgReferentialActionSerialized Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onDelete))
where
syntax :: PgSyntax
syntax =
ByteString -> PgSyntax
emit ByteString
"REFERENCES " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
tbl forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"("
forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map Text -> PgSyntax
pgQuotedIdentifier [Text]
fields) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")" forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgMatchTypeSyntax
m -> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgMatchTypeSyntax -> PgSyntax
fromPgMatchType PgMatchTypeSyntax
m) Maybe
(Sql92ColumnConstraintMatchTypeSyntax PgColumnConstraintSyntax)
matchType forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgReferentialActionSyntax
a -> ByteString -> PgSyntax
emit ByteString
" ON UPDATE " forall a. Semigroup a => a -> a -> a
<> PgReferentialActionSyntax -> PgSyntax
fromPgReferentialAction PgReferentialActionSyntax
a) Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onUpdate forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\PgReferentialActionSyntax
a -> ByteString -> PgSyntax
emit ByteString
" ON DELETE " forall a. Semigroup a => a -> a -> a
<> PgReferentialActionSyntax -> PgSyntax
fromPgReferentialAction PgReferentialActionSyntax
a) Maybe
(Sql92ColumnConstraintReferentialActionSyntax
PgColumnConstraintSyntax)
onDelete
defaultPgValueSyntax :: Pg.ToField a => a -> PgValueSyntax
defaultPgValueSyntax :: forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax =
PgSyntax -> PgValueSyntax
PgValueSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Action] -> PgSyntax
pgBuildAction forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToField a => a -> Action
Pg.toField
data PgHasEnum = PgHasEnum T.Text [T.Text]
deriving (Int -> PgHasEnum -> ShowS
[PgHasEnum] -> ShowS
PgHasEnum -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgHasEnum] -> ShowS
$cshowList :: [PgHasEnum] -> ShowS
show :: PgHasEnum -> String
$cshow :: PgHasEnum -> String
showsPrec :: Int -> PgHasEnum -> ShowS
$cshowsPrec :: Int -> PgHasEnum -> ShowS
Show, PgHasEnum -> PgHasEnum -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgHasEnum -> PgHasEnum -> Bool
$c/= :: PgHasEnum -> PgHasEnum -> Bool
== :: PgHasEnum -> PgHasEnum -> Bool
$c== :: PgHasEnum -> PgHasEnum -> Bool
Eq, forall x. Rep PgHasEnum x -> PgHasEnum
forall x. PgHasEnum -> Rep PgHasEnum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PgHasEnum x -> PgHasEnum
$cfrom :: forall x. PgHasEnum -> Rep PgHasEnum x
Generic)
instance Hashable PgHasEnum
instance DatabasePredicate PgHasEnum where
englishDescription :: PgHasEnum -> String
englishDescription (PgHasEnum Text
enumName [Text]
values) =
String
"Has postgres enumeration " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Text
enumName forall a. [a] -> [a] -> [a]
++ String
" with values " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show [Text]
values
predicateSpecificity :: forall (proxy :: * -> *). proxy PgHasEnum -> PredicateSpecificity
predicateSpecificity proxy PgHasEnum
_ = String -> PredicateSpecificity
PredicateSpecificityOnlyBackend String
"postgres"
serializePredicate :: PgHasEnum -> Value
serializePredicate (PgHasEnum Text
name [Text]
values) =
[Pair] -> Value
object [ Key
"has-postgres-enum" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [ Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
name
, Key
"values" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Text]
values ] ]
#define DEFAULT_SQL_SYNTAX(ty) \
instance HasSqlValueSyntax PgValueSyntax ty where \
sqlValueSyntax = defaultPgValueSyntax
DEFAULT_SQL_SYNTAX(Bool)
DEFAULT_SQL_SYNTAX(Double)
DEFAULT_SQL_SYNTAX(Float)
DEFAULT_SQL_SYNTAX(Int8)
DEFAULT_SQL_SYNTAX(Int16)
DEFAULT_SQL_SYNTAX(Int32)
DEFAULT_SQL_SYNTAX(Int64)
DEFAULT_SQL_SYNTAX(Integer)
DEFAULT_SQL_SYNTAX(Word8)
DEFAULT_SQL_SYNTAX(Word16)
DEFAULT_SQL_SYNTAX(Word32)
DEFAULT_SQL_SYNTAX(Word64)
DEFAULT_SQL_SYNTAX(T.Text)
DEFAULT_SQL_SYNTAX(TL.Text)
DEFAULT_SQL_SYNTAX(Value)
DEFAULT_SQL_SYNTAX(Pg.Oid)
DEFAULT_SQL_SYNTAX(LocalTime)
DEFAULT_SQL_SYNTAX(UTCTime)
DEFAULT_SQL_SYNTAX(TimeOfDay)
DEFAULT_SQL_SYNTAX(NominalDiffTime)
DEFAULT_SQL_SYNTAX(Day)
DEFAULT_SQL_SYNTAX([Char])
DEFAULT_SQL_SYNTAX(Pg.HStoreMap)
DEFAULT_SQL_SYNTAX(Pg.HStoreList)
DEFAULT_SQL_SYNTAX(Pg.HStoreBuilder)
DEFAULT_SQL_SYNTAX(Pg.Date)
DEFAULT_SQL_SYNTAX(Pg.LocalTimestamp)
DEFAULT_SQL_SYNTAX(Pg.UTCTimestamp)
DEFAULT_SQL_SYNTAX(Scientific)
instance HasSqlValueSyntax PgValueSyntax (CI T.Text) where
sqlValueSyntax :: CI Text -> PgValueSyntax
sqlValueSyntax = forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. CI s -> s
CI.original
instance HasSqlValueSyntax PgValueSyntax (CI TL.Text) where
sqlValueSyntax :: CI Text -> PgValueSyntax
sqlValueSyntax = forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. CI s -> s
CI.original
instance HasSqlValueSyntax PgValueSyntax SqlNull where
sqlValueSyntax :: SqlNull -> PgValueSyntax
sqlValueSyntax SqlNull
_ = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax Null
Pg.Null
instance HasSqlValueSyntax PgValueSyntax x => HasSqlValueSyntax PgValueSyntax (Maybe x) where
sqlValueSyntax :: Maybe x -> PgValueSyntax
sqlValueSyntax Maybe x
Nothing = forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax SqlNull
SqlNull
sqlValueSyntax (Just x
x) = forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax x
x
instance HasSqlValueSyntax PgValueSyntax B.ByteString where
sqlValueSyntax :: ByteString -> PgValueSyntax
sqlValueSyntax = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Binary a
Pg.Binary
instance HasSqlValueSyntax PgValueSyntax BL.ByteString where
sqlValueSyntax :: ByteString -> PgValueSyntax
sqlValueSyntax = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Binary a
Pg.Binary
instance HasSqlValueSyntax PgValueSyntax UUID where
sqlValueSyntax :: UUID -> PgValueSyntax
sqlValueSyntax UUID
v = PgSyntax -> PgValueSyntax
PgValueSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"'" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (UUID -> ByteString
toASCIIBytes UUID
v) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"'::uuid"
instance Pg.ToField a => HasSqlValueSyntax PgValueSyntax (V.Vector a) where
sqlValueSyntax :: Vector a -> PgValueSyntax
sqlValueSyntax = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax
instance TypeError (PreferExplicitSize Int Int32) => HasSqlValueSyntax PgValueSyntax Int where
sqlValueSyntax :: Int -> PgValueSyntax
sqlValueSyntax = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax
instance TypeError (PreferExplicitSize Word Word32) => HasSqlValueSyntax PgValueSyntax Word where
sqlValueSyntax :: Word -> PgValueSyntax
sqlValueSyntax = forall a. ToField a => a -> PgValueSyntax
defaultPgValueSyntax
pgQuotedIdentifier :: T.Text -> PgSyntax
pgQuotedIdentifier :: Text -> PgSyntax
pgQuotedIdentifier Text
t =
ByteString -> PgSyntax
escapeIdentifier (Text -> ByteString
TE.encodeUtf8 Text
t)
pgParens :: PgSyntax -> PgSyntax
pgParens :: PgSyntax -> PgSyntax
pgParens PgSyntax
a = ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgTableOp :: ByteString -> PgSelectTableSyntax -> PgSelectTableSyntax
-> PgSelectTableSyntax
pgTableOp :: ByteString
-> PgSelectTableSyntax
-> PgSelectTableSyntax
-> PgSelectTableSyntax
pgTableOp ByteString
op PgSelectTableSyntax
tbl1 PgSelectTableSyntax
tbl2 =
PgSyntax -> PgSelectTableSyntax
PgSelectTableSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgSelectTableSyntax -> PgSyntax
fromPgSelectTable PgSelectTableSyntax
tbl1 forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
op forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
" (" forall a. Semigroup a => a -> a -> a
<> PgSelectTableSyntax -> PgSyntax
fromPgSelectTable PgSelectTableSyntax
tbl2 forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgCompOp :: ByteString -> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgCompOp :: ByteString
-> Maybe PgComparisonQuantifierSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
-> PgExpressionSyntax
pgCompOp ByteString
op Maybe PgComparisonQuantifierSyntax
quantifier PgExpressionSyntax
a PgExpressionSyntax
b =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit (ByteString
") " forall a. Semigroup a => a -> a -> a
<> ByteString
op) forall a. Semigroup a => a -> a -> a
<>
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ByteString -> PgSyntax
emit ByteString
" (" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
b forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")")
(\PgComparisonQuantifierSyntax
q -> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgComparisonQuantifierSyntax -> PgSyntax
fromPgComparisonQuantifier PgComparisonQuantifierSyntax
q forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
b)
Maybe PgComparisonQuantifierSyntax
quantifier
pgBinOp :: ByteString -> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp :: ByteString
-> PgExpressionSyntax -> PgExpressionSyntax -> PgExpressionSyntax
pgBinOp ByteString
op PgExpressionSyntax
a PgExpressionSyntax
b =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (ByteString
") " forall a. Semigroup a => a -> a -> a
<> ByteString
op forall a. Semigroup a => a -> a -> a
<> ByteString
" (") forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
b forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgPostFix, pgUnOp :: ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix :: ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgPostFix ByteString
op PgExpressionSyntax
a =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"(" forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
") " forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
op
pgUnOp :: ByteString -> PgExpressionSyntax -> PgExpressionSyntax
pgUnOp ByteString
op PgExpressionSyntax
a =
PgSyntax -> PgExpressionSyntax
PgExpressionSyntax forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit (ByteString
op forall a. Semigroup a => a -> a -> a
<> ByteString
"(") forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgJoin :: ByteString -> PgFromSyntax -> PgFromSyntax -> Maybe PgExpressionSyntax -> PgFromSyntax
pgJoin :: ByteString
-> PgFromSyntax
-> PgFromSyntax
-> Maybe PgExpressionSyntax
-> PgFromSyntax
pgJoin ByteString
joinType PgFromSyntax
a PgFromSyntax
b Maybe PgExpressionSyntax
Nothing =
PgSyntax -> PgFromSyntax
PgFromSyntax forall a b. (a -> b) -> a -> b
$
PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (ByteString
" " forall a. Semigroup a => a -> a -> a
<> ByteString
joinType forall a. Semigroup a => a -> a -> a
<> ByteString
" ") forall a. Semigroup a => a -> a -> a
<> PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
b forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" ON TRUE"
pgJoin ByteString
joinType PgFromSyntax
a PgFromSyntax
b (Just PgExpressionSyntax
on) =
PgSyntax -> PgFromSyntax
PgFromSyntax forall a b. (a -> b) -> a -> b
$
PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
a forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit (ByteString
" " forall a. Semigroup a => a -> a -> a
<> ByteString
joinType forall a. Semigroup a => a -> a -> a
<> ByteString
" ") forall a. Semigroup a => a -> a -> a
<> PgFromSyntax -> PgSyntax
fromPgFrom PgFromSyntax
b forall a. Semigroup a => a -> a -> a
<>
ByteString -> PgSyntax
emit ByteString
" ON " forall a. Semigroup a => a -> a -> a
<> PgExpressionSyntax -> PgSyntax
fromPgExpression PgExpressionSyntax
on
pgSepBy :: PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy :: PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy PgSyntax
_ [] = forall a. Monoid a => a
mempty
pgSepBy PgSyntax
_ [PgSyntax
x] = PgSyntax
x
pgSepBy PgSyntax
sep (PgSyntax
x:[PgSyntax]
xs) = PgSyntax
x forall a. Semigroup a => a -> a -> a
<> PgSyntax
sep forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy PgSyntax
sep [PgSyntax]
xs
pgDebugRenderSyntax :: PgSyntax -> IO ()
pgDebugRenderSyntax :: PgSyntax -> IO ()
pgDebugRenderSyntax (PgSyntax PgSyntaxM ()
p) = PgSyntaxM () -> Maybe (PgSyntaxF ()) -> IO ()
go PgSyntaxM ()
p forall a. Maybe a
Nothing
where go :: PgSyntaxM () -> Maybe (PgSyntaxF ()) -> IO ()
go :: PgSyntaxM () -> Maybe (PgSyntaxF ()) -> IO ()
go PgSyntaxM ()
p = forall (f :: * -> *) a.
F f a -> forall r. (a -> r) -> (f r -> r) -> r
runF PgSyntaxM ()
p forall {a} {f}. a -> Maybe (PgSyntaxF f) -> IO a
finish forall {b} {f}.
PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
-> Maybe (PgSyntaxF f) -> IO b
step
step :: PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
-> Maybe (PgSyntaxF f) -> IO b
step PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
x Maybe (PgSyntaxF f)
lastBs =
case (PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
x, Maybe (PgSyntaxF f)
lastBs) of
(EmitBuilder Builder
s Maybe (PgSyntaxF ()) -> IO b
next, Maybe (PgSyntaxF f)
lastBs) ->
PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
-> Maybe (PgSyntaxF f) -> IO b
step (forall f. ByteString -> f -> PgSyntaxF f
EmitByteString (ByteString -> ByteString
toStrict (Builder -> ByteString
toLazyByteString Builder
s)) Maybe (PgSyntaxF ()) -> IO b
next) Maybe (PgSyntaxF f)
lastBs
(PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
x, Maybe (PgSyntaxF f)
Nothing) ->
forall f. PgSyntaxF f -> f
nextSyntaxStep PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
x (forall a. a -> Maybe a
Just (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const ()) PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
x))
(EmitByteString ByteString
x Maybe (PgSyntaxF ()) -> IO b
next, Just (EmitByteString ByteString
before f
_)) ->
Maybe (PgSyntaxF ()) -> IO b
next (forall a. a -> Maybe a
Just (forall f. ByteString -> f -> PgSyntaxF f
EmitByteString (ByteString
before forall a. Semigroup a => a -> a -> a
<> ByteString
x) ()))
(EscapeString ByteString
x Maybe (PgSyntaxF ()) -> IO b
next, Just (EscapeString ByteString
before f
_)) ->
Maybe (PgSyntaxF ()) -> IO b
next (forall a. a -> Maybe a
Just (forall f. ByteString -> f -> PgSyntaxF f
EscapeString (ByteString
before forall a. Semigroup a => a -> a -> a
<> ByteString
x) ()))
(EscapeBytea ByteString
x Maybe (PgSyntaxF ()) -> IO b
next, Just (EscapeBytea ByteString
before f
_)) ->
Maybe (PgSyntaxF ()) -> IO b
next (forall a. a -> Maybe a
Just (forall f. ByteString -> f -> PgSyntaxF f
EscapeBytea (ByteString
before forall a. Semigroup a => a -> a -> a
<> ByteString
x) ()))
(EscapeIdentifier ByteString
x Maybe (PgSyntaxF ()) -> IO b
next, Just (EscapeIdentifier ByteString
before f
_)) ->
Maybe (PgSyntaxF ()) -> IO b
next (forall a. a -> Maybe a
Just (forall f. ByteString -> f -> PgSyntaxF f
EscapeIdentifier (ByteString
before forall a. Semigroup a => a -> a -> a
<> ByteString
x) ()))
(PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
s, Just PgSyntaxF f
e) ->
forall {f}. PgSyntaxF f -> IO ()
renderStep PgSyntaxF f
e forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall f. PgSyntaxF f -> f
nextSyntaxStep PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
s (forall a. a -> Maybe a
Just (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const ()) PgSyntaxF (Maybe (PgSyntaxF ()) -> IO b)
s))
renderStep :: PgSyntaxF f -> IO ()
renderStep (EmitByteString ByteString
x f
_) = String -> IO ()
putStrLn (String
"EmitByteString " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show ByteString
x)
renderStep (EmitBuilder Builder
x f
_) = String -> IO ()
putStrLn (String
"EmitBuilder " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show (Builder -> ByteString
toLazyByteString Builder
x))
renderStep (EscapeString ByteString
x f
_) = String -> IO ()
putStrLn (String
"EscapeString " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show ByteString
x)
renderStep (EscapeBytea ByteString
x f
_) = String -> IO ()
putStrLn (String
"EscapeBytea " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show ByteString
x)
renderStep (EscapeIdentifier ByteString
x f
_) = String -> IO ()
putStrLn (String
"EscapeIdentifier " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show ByteString
x)
finish :: a -> Maybe (PgSyntaxF f) -> IO a
finish a
x Maybe (PgSyntaxF f)
Nothing = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
finish a
x (Just PgSyntaxF f
s) = forall {f}. PgSyntaxF f -> IO ()
renderStep PgSyntaxF f
s forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
pgBuildAction :: [ Pg.Action ] -> PgSyntax
pgBuildAction :: [Action] -> PgSyntax
pgBuildAction =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a b. (a -> b) -> a -> b
$ \Action
action ->
case Action
action of
Pg.Plain Builder
x -> Builder -> PgSyntax
emitBuilder Builder
x
Pg.Escape ByteString
str -> ByteString -> PgSyntax
emit ByteString
"'" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
escapeString ByteString
str forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"'"
Pg.EscapeByteA ByteString
bin -> ByteString -> PgSyntax
emit ByteString
"'" forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
escapeBytea ByteString
bin forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
"'"
Pg.EscapeIdentifier ByteString
id -> ByteString -> PgSyntax
escapeIdentifier ByteString
id
Pg.Many [Action]
as -> [Action] -> PgSyntax
pgBuildAction [Action]
as
pgSelectStmt :: PgSelectTableSyntax
-> [PgOrderingSyntax]
-> Maybe Integer
-> Maybe Integer
-> Maybe PgSelectLockingClauseSyntax
-> PgSelectSyntax
pgSelectStmt :: PgSelectTableSyntax
-> [PgOrderingSyntax]
-> Maybe Integer
-> Maybe Integer
-> Maybe PgSelectLockingClauseSyntax
-> PgSelectSyntax
pgSelectStmt PgSelectTableSyntax
tbl [PgOrderingSyntax]
ordering Maybe Integer
limit Maybe Integer
offset Maybe PgSelectLockingClauseSyntax
locking =
PgSyntax -> PgSelectSyntax
PgSelectSyntax forall a b. (a -> b) -> a -> b
$
forall a. Monoid a => [a] -> a
mconcat [ coerce :: forall a b. Coercible a b => a -> b
coerce PgSelectTableSyntax
tbl
, case [PgOrderingSyntax]
ordering of
[] -> forall a. Monoid a => a
mempty
[PgOrderingSyntax]
ordering -> ByteString -> PgSyntax
emit ByteString
" ORDER BY " forall a. Semigroup a => a -> a -> a
<> PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall a b. (a -> b) -> [a] -> [b]
map PgOrderingSyntax -> PgSyntax
fromPgOrdering [PgOrderingSyntax]
ordering)
, forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
" LIMIT " forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) Maybe Integer
limit
, forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (ByteString -> PgSyntax
emit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
" OFFSET " forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) Maybe Integer
offset
, forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty PgSelectLockingClauseSyntax -> PgSyntax
fromPgSelectLockingClause Maybe PgSelectLockingClauseSyntax
locking ]
pgCreateExtensionSyntax :: T.Text -> PgCommandSyntax
pgCreateExtensionSyntax :: Text -> PgCommandSyntax
pgCreateExtensionSyntax Text
extName =
PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"CREATE EXTENSION " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
extName
pgDropExtensionSyntax :: T.Text -> PgCommandSyntax
pgDropExtensionSyntax :: Text -> PgCommandSyntax
pgDropExtensionSyntax Text
extName =
PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall a b. (a -> b) -> a -> b
$ ByteString -> PgSyntax
emit ByteString
"DROP EXTENSION " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
extName
pgCreateEnumSyntax :: T.Text -> [PgValueSyntax] -> PgCommandSyntax
pgCreateEnumSyntax :: Text -> [PgValueSyntax] -> PgCommandSyntax
pgCreateEnumSyntax Text
enumName [PgValueSyntax]
vals =
PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"CREATE TYPE " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
enumName forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
" AS ENUM(" forall a. Semigroup a => a -> a -> a
<>
PgSyntax -> [PgSyntax] -> PgSyntax
pgSepBy (ByteString -> PgSyntax
emit ByteString
", ") (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PgValueSyntax -> PgSyntax
fromPgValue [PgValueSyntax]
vals) forall a. Semigroup a => a -> a -> a
<> ByteString -> PgSyntax
emit ByteString
")"
pgDropTypeSyntax :: T.Text -> PgCommandSyntax
pgDropTypeSyntax :: Text -> PgCommandSyntax
pgDropTypeSyntax Text
typeName =
PgCommandType -> PgSyntax -> PgCommandSyntax
PgCommandSyntax PgCommandType
PgCommandTypeDdl forall a b. (a -> b) -> a -> b
$
ByteString -> PgSyntax
emit ByteString
"DROP TYPE " forall a. Semigroup a => a -> a -> a
<> Text -> PgSyntax
pgQuotedIdentifier Text
typeName
data PgEscapeType = PgEscapeString | PgEscapeBytea | PgEscapeIdentifier
deriving (Int -> PgEscapeType -> ShowS
[PgEscapeType] -> ShowS
PgEscapeType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgEscapeType] -> ShowS
$cshowList :: [PgEscapeType] -> ShowS
show :: PgEscapeType -> String
$cshow :: PgEscapeType -> String
showsPrec :: Int -> PgEscapeType -> ShowS
$cshowsPrec :: Int -> PgEscapeType -> ShowS
Show, PgEscapeType -> PgEscapeType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PgEscapeType -> PgEscapeType -> Bool
$c/= :: PgEscapeType -> PgEscapeType -> Bool
== :: PgEscapeType -> PgEscapeType -> Bool
$c== :: PgEscapeType -> PgEscapeType -> Bool
Eq, Eq PgEscapeType
PgEscapeType -> PgEscapeType -> Bool
PgEscapeType -> PgEscapeType -> Ordering
PgEscapeType -> PgEscapeType -> PgEscapeType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PgEscapeType -> PgEscapeType -> PgEscapeType
$cmin :: PgEscapeType -> PgEscapeType -> PgEscapeType
max :: PgEscapeType -> PgEscapeType -> PgEscapeType
$cmax :: PgEscapeType -> PgEscapeType -> PgEscapeType
>= :: PgEscapeType -> PgEscapeType -> Bool
$c>= :: PgEscapeType -> PgEscapeType -> Bool
> :: PgEscapeType -> PgEscapeType -> Bool
$c> :: PgEscapeType -> PgEscapeType -> Bool
<= :: PgEscapeType -> PgEscapeType -> Bool
$c<= :: PgEscapeType -> PgEscapeType -> Bool
< :: PgEscapeType -> PgEscapeType -> Bool
$c< :: PgEscapeType -> PgEscapeType -> Bool
compare :: PgEscapeType -> PgEscapeType -> Ordering
$ccompare :: PgEscapeType -> PgEscapeType -> Ordering
Ord, Int -> PgEscapeType
PgEscapeType -> Int
PgEscapeType -> [PgEscapeType]
PgEscapeType -> PgEscapeType
PgEscapeType -> PgEscapeType -> [PgEscapeType]
PgEscapeType -> PgEscapeType -> PgEscapeType -> [PgEscapeType]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: PgEscapeType -> PgEscapeType -> PgEscapeType -> [PgEscapeType]
$cenumFromThenTo :: PgEscapeType -> PgEscapeType -> PgEscapeType -> [PgEscapeType]
enumFromTo :: PgEscapeType -> PgEscapeType -> [PgEscapeType]
$cenumFromTo :: PgEscapeType -> PgEscapeType -> [PgEscapeType]
enumFromThen :: PgEscapeType -> PgEscapeType -> [PgEscapeType]
$cenumFromThen :: PgEscapeType -> PgEscapeType -> [PgEscapeType]
enumFrom :: PgEscapeType -> [PgEscapeType]
$cenumFrom :: PgEscapeType -> [PgEscapeType]
fromEnum :: PgEscapeType -> Int
$cfromEnum :: PgEscapeType -> Int
toEnum :: Int -> PgEscapeType
$ctoEnum :: Int -> PgEscapeType
pred :: PgEscapeType -> PgEscapeType
$cpred :: PgEscapeType -> PgEscapeType
succ :: PgEscapeType -> PgEscapeType
$csucc :: PgEscapeType -> PgEscapeType
Enum, PgEscapeType
forall a. a -> a -> Bounded a
maxBound :: PgEscapeType
$cmaxBound :: PgEscapeType
minBound :: PgEscapeType
$cminBound :: PgEscapeType
Bounded)
data PgSyntaxPrim = PgSyntaxPrim (Maybe PgEscapeType) BL.ByteString deriving Int -> PgSyntaxPrim -> ShowS
[PgSyntaxPrim] -> ShowS
PgSyntaxPrim -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PgSyntaxPrim] -> ShowS
$cshowList :: [PgSyntaxPrim] -> ShowS
show :: PgSyntaxPrim -> String
$cshow :: PgSyntaxPrim -> String
showsPrec :: Int -> PgSyntaxPrim -> ShowS
$cshowsPrec :: Int -> PgSyntaxPrim -> ShowS
Show
instance IsString PgSyntaxPrim where
fromString :: String -> PgSyntaxPrim
fromString = Maybe PgEscapeType -> ByteString -> PgSyntaxPrim
PgSyntaxPrim forall a. Maybe a
Nothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
pgTestSyntax :: PgSyntax -> [ PgSyntaxPrim ]
pgTestSyntax :: PgSyntax -> [PgSyntaxPrim]
pgTestSyntax (PgSyntax PgSyntaxM ()
syntax) = forall (f :: * -> *) a.
F f a -> forall r. (a -> r) -> (f r -> r) -> r
runF PgSyntaxM ()
syntax forall {p} {t}.
p -> Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> t) -> t
finish forall {c} {t}.
PgSyntaxF
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
step forall a. Maybe a
Nothing forall a. Monoid a => a
mempty forall a. a -> a
id
where
finish :: p -> Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> t) -> t
finish p
_ Maybe PgEscapeType
escapeType Builder
curBuilder [PgSyntaxPrim] -> t
a =
let chunk :: ByteString
chunk = Builder -> ByteString
toLazyByteString Builder
curBuilder
in if ByteString -> Bool
BL.null ByteString
chunk then [PgSyntaxPrim] -> t
a []
else [PgSyntaxPrim] -> t
a [ Maybe PgEscapeType -> ByteString -> PgSyntaxPrim
PgSyntaxPrim Maybe PgEscapeType
escapeType ByteString
chunk ]
go :: (Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType Maybe PgEscapeType
nextType Builder
curBuilder Builder
nextBuilder [PgSyntaxPrim] -> c
a
| Maybe PgEscapeType
curType forall a. Eq a => a -> a -> Bool
== Maybe PgEscapeType
nextType = Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType (Builder
curBuilder forall a. Semigroup a => a -> a -> a
<> Builder
nextBuilder) [PgSyntaxPrim] -> c
a
| Bool
otherwise = Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
nextType forall a. Monoid a => a
mempty ([PgSyntaxPrim] -> c
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe PgEscapeType -> ByteString -> PgSyntaxPrim
PgSyntaxPrim Maybe PgEscapeType
curType (Builder -> ByteString
toLazyByteString Builder
curBuilder)forall a. a -> [a] -> [a]
:))
step :: PgSyntaxF
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
step (EmitByteString ByteString
bs Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next) Maybe PgEscapeType
curType Builder
curBuilder [PgSyntaxPrim] -> c
a =
forall {c} {t}.
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType forall a. Maybe a
Nothing Builder
curBuilder (ByteString -> Builder
byteString ByteString
bs) [PgSyntaxPrim] -> c
a
step (EmitBuilder Builder
bs Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next) Maybe PgEscapeType
curType Builder
curBuilder [PgSyntaxPrim] -> c
a =
forall {c} {t}.
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType forall a. Maybe a
Nothing Builder
curBuilder Builder
bs [PgSyntaxPrim] -> c
a
step (EscapeString ByteString
s Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next) Maybe PgEscapeType
curType Builder
curBuilder [PgSyntaxPrim] -> c
a =
forall {c} {t}.
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType (forall a. a -> Maybe a
Just PgEscapeType
PgEscapeString) Builder
curBuilder (ByteString -> Builder
byteString ByteString
s) [PgSyntaxPrim] -> c
a
step (EscapeBytea ByteString
s Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next) Maybe PgEscapeType
curType Builder
curBuilder [PgSyntaxPrim] -> c
a =
forall {c} {t}.
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType (forall a. a -> Maybe a
Just PgEscapeType
PgEscapeBytea) Builder
curBuilder (ByteString -> Builder
byteString ByteString
s) [PgSyntaxPrim] -> c
a
step (EscapeIdentifier ByteString
s Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next) Maybe PgEscapeType
curType Builder
curBuilder [PgSyntaxPrim] -> c
a =
forall {c} {t}.
(Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t)
-> Maybe PgEscapeType
-> Maybe PgEscapeType
-> Builder
-> Builder
-> ([PgSyntaxPrim] -> c)
-> t
go Maybe PgEscapeType -> Builder -> ([PgSyntaxPrim] -> c) -> t
next Maybe PgEscapeType
curType (forall a. a -> Maybe a
Just PgEscapeType
PgEscapeIdentifier) Builder
curBuilder (ByteString -> Builder
byteString ByteString
s) [PgSyntaxPrim] -> c
a
pgRenderSyntaxScript :: PgSyntax -> BL.ByteString
pgRenderSyntaxScript :: PgSyntax -> ByteString
pgRenderSyntaxScript (PgSyntax PgSyntaxM ()
mkQuery) =
Builder -> ByteString
toLazyByteString (forall (f :: * -> *) a.
F f a -> forall r. (a -> r) -> (f r -> r) -> r
runF PgSyntaxM ()
mkQuery forall {a} {p}. Monoid a => p -> a
finish PgSyntaxF Builder -> Builder
step)
where
finish :: p -> a
finish p
_ = forall a. Monoid a => a
mempty
step :: PgSyntaxF Builder -> Builder
step (EmitBuilder Builder
b Builder
next) = Builder
b forall a. Semigroup a => a -> a -> a
<> Builder
next
step (EmitByteString ByteString
b Builder
next) = ByteString -> Builder
byteString ByteString
b forall a. Semigroup a => a -> a -> a
<> Builder
next
step (EscapeString ByteString
b Builder
next) = ByteString -> Builder
escapePgString ByteString
b forall a. Semigroup a => a -> a -> a
<> Builder
next
step (EscapeBytea ByteString
b Builder
next) = forall {p} {a}. p -> a
escapePgBytea ByteString
b forall a. Semigroup a => a -> a -> a
<> Builder
next
step (EscapeIdentifier ByteString
b Builder
next) = ByteString -> Builder
escapePgIdentifier ByteString
b forall a. Semigroup a => a -> a -> a
<> Builder
next
escapePgString :: ByteString -> Builder
escapePgString ByteString
b = ByteString -> Builder
byteString ((Char -> ByteString) -> ByteString -> ByteString
B.concatMap (\Char
w -> if Char
w forall a. Eq a => a -> a -> Bool
== Char
'\'' then ByteString
"''" else Char -> ByteString
B.singleton Char
w) ByteString
b)
escapePgBytea :: p -> a
escapePgBytea p
_ = forall a. HasCallStack => String -> a
error String
"escapePgBytea: no connection"
escapePgIdentifier :: ByteString -> Builder
escapePgIdentifier ByteString
bs = Char -> Builder
char8 Char
'"' forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Char -> Builder
quoteIdentifierChar (ByteString -> String
B.unpack ByteString
bs) forall a. Semigroup a => a -> a -> a
<> Char -> Builder
char8 Char
'"'
where
quoteIdentifierChar :: Char -> Builder
quoteIdentifierChar Char
'"' = Char -> Builder
char8 Char
'"' forall a. Semigroup a => a -> a -> a
<> Char -> Builder
char8 Char
'"'
quoteIdentifierChar Char
c = Char -> Builder
char8 Char
c