{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE UndecidableInstances #-}
module Database.Beam.Backend.SQL.Builder
( SqlSyntaxBuilder(..)
, buildSepBy
, quoteSql
, renderSql ) where
import Database.Beam.Backend.Internal.Compat
import Database.Beam.Backend.SQL
import Control.Monad.IO.Class
import Data.ByteString (ByteString)
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Text.Encoding as TE
import qualified Data.Text as T
import Data.Text (Text)
import Data.Coerce
import Data.Hashable
import Data.Int
import Data.String
import qualified Control.Monad.Fail as Fail
import GHC.TypeLits
newtype SqlSyntaxBuilder
= SqlSyntaxBuilder { SqlSyntaxBuilder -> Builder
buildSql :: Builder }
instance Hashable SqlSyntaxBuilder where
hashWithSalt :: Int -> SqlSyntaxBuilder -> Int
hashWithSalt Int
salt (SqlSyntaxBuilder Builder
b) = Int -> ByteString -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Builder -> ByteString
toLazyByteString Builder
b)
instance Show SqlSyntaxBuilder where
showsPrec :: Int -> SqlSyntaxBuilder -> ShowS
showsPrec Int
prec (SqlSyntaxBuilder Builder
s) =
Bool -> ShowS -> ShowS
showParen (Int
prec Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"SqlSyntaxBuilder (" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ByteString -> ShowS
forall a. Show a => a -> ShowS
shows (Builder -> ByteString
toLazyByteString Builder
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
")"
instance Eq SqlSyntaxBuilder where
SqlSyntaxBuilder
a == :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> Bool
== SqlSyntaxBuilder
b = Builder -> ByteString
toLazyByteString (SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a) ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== Builder -> ByteString
toLazyByteString (SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b)
instance Semigroup SqlSyntaxBuilder where
SqlSyntaxBuilder Builder
a <> :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
<> SqlSyntaxBuilder Builder
b = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b)
instance Monoid SqlSyntaxBuilder where
mempty :: SqlSyntaxBuilder
mempty = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
forall a. Monoid a => a
mempty
mappend :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
mappend = SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. Semigroup a => a -> a -> a
(<>)
instance IsSql92Syntax SqlSyntaxBuilder where
type Sql92SelectSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92InsertSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92DeleteSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92UpdateSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
selectCmd :: Sql92SelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
selectCmd = Sql92SelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
insertCmd :: Sql92InsertSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
insertCmd = Sql92InsertSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
updateCmd :: Sql92UpdateSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
updateCmd = Sql92UpdateSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
deleteCmd :: Sql92DeleteSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
deleteCmd = Sql92DeleteSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
instance IsSql92SelectSyntax SqlSyntaxBuilder where
type Sql92SelectSelectTableSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectOrderingSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
selectStmt :: Sql92SelectSelectTableSyntax SqlSyntaxBuilder
-> [Sql92SelectOrderingSyntax SqlSyntaxBuilder]
-> Maybe Integer
-> Maybe Integer
-> SqlSyntaxBuilder
selectStmt Sql92SelectSelectTableSyntax SqlSyntaxBuilder
tableSrc [Sql92SelectOrderingSyntax SqlSyntaxBuilder]
ordering Maybe Integer
limit Maybe Integer
offset =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
SqlSyntaxBuilder -> Builder
buildSql Sql92SelectSelectTableSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
tableSrc Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
( case [Sql92SelectOrderingSyntax SqlSyntaxBuilder]
ordering of
[] -> Builder
forall a. Monoid a => a
mempty
[Sql92SelectOrderingSyntax SqlSyntaxBuilder]
_ -> ByteString -> Builder
byteString ByteString
" ORDER BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [Sql92SelectOrderingSyntax SqlSyntaxBuilder]
[SqlSyntaxBuilder]
ordering) ) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> (Integer -> Builder) -> Maybe Integer -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\Integer
l -> ByteString -> Builder
byteString ByteString
" LIMIT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Integer -> String
forall a. Show a => a -> String
show Integer
l))) Maybe Integer
limit Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> (Integer -> Builder) -> Maybe Integer -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\Integer
o -> ByteString -> Builder
byteString ByteString
" OFFSET " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Integer -> String
forall a. Show a => a -> String
show Integer
o))) Maybe Integer
offset
instance IsSql92GroupingSyntax SqlSyntaxBuilder where
type Sql92GroupingExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
groupByExpressions :: [Sql92GroupingExpressionSyntax SqlSyntaxBuilder]
-> SqlSyntaxBuilder
groupByExpressions [Sql92GroupingExpressionSyntax SqlSyntaxBuilder]
es =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [Sql92GroupingExpressionSyntax SqlSyntaxBuilder]
[SqlSyntaxBuilder]
es)
instance IsSql92SelectTableSyntax SqlSyntaxBuilder where
type Sql92SelectTableSelectSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectTableExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectTableProjectionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectTableFromSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectTableGroupingSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92SelectTableSetQuantifierSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
selectTableStmt :: Maybe (Sql92SelectTableSetQuantifierSyntax SqlSyntaxBuilder)
-> Sql92SelectTableProjectionSyntax SqlSyntaxBuilder
-> Maybe (Sql92SelectTableFromSyntax SqlSyntaxBuilder)
-> Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
-> Maybe (Sql92SelectTableGroupingSyntax SqlSyntaxBuilder)
-> Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
selectTableStmt Maybe (Sql92SelectTableSetQuantifierSyntax SqlSyntaxBuilder)
setQuantifier Sql92SelectTableProjectionSyntax SqlSyntaxBuilder
proj Maybe (Sql92SelectTableFromSyntax SqlSyntaxBuilder)
from Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
where_ Maybe (Sql92SelectTableGroupingSyntax SqlSyntaxBuilder)
grouping Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
having =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"SELECT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
setQuantifier' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
setQuantifier' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92SelectTableSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
setQuantifier Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
SqlSyntaxBuilder -> Builder
buildSql Sql92SelectTableProjectionSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
proj Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty ((ByteString -> Builder
byteString ByteString
" FROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder -> Builder)
-> (SqlSyntaxBuilder -> Builder) -> SqlSyntaxBuilder -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSyntaxBuilder -> Builder
buildSql) Maybe (Sql92SelectTableFromSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
from Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
w -> ByteString -> Builder
byteString ByteString
" WHERE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
w) Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
where_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
g -> ByteString -> Builder
byteString ByteString
" GROUP BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
g) Maybe (Sql92SelectTableGroupingSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
grouping Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
e -> ByteString -> Builder
byteString ByteString
" HAVING " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
e) Maybe (Sql92SelectTableExpressionSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
having
unionTables :: Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
unionTables = ByteString
-> Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
tableOp ByteString
"UNION"
intersectTables :: Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
intersectTables = ByteString
-> Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
tableOp ByteString
"INTERSECT"
exceptTable :: Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
exceptTable = ByteString
-> Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
tableOp ByteString
"EXCEPT"
tableOp :: ByteString -> Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
tableOp :: ByteString
-> Bool -> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
tableOp ByteString
op Bool
all SqlSyntaxBuilder
a SqlSyntaxBuilder
b =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> if Bool
all then ByteString -> Builder
byteString ByteString
" ALL " else Builder
forall a. Monoid a => a
mempty Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
" (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
instance IsSql92InsertSyntax SqlSyntaxBuilder where
type Sql92InsertValuesSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92InsertTableNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
insertStmt :: Sql92InsertTableNameSyntax SqlSyntaxBuilder
-> [Text]
-> Sql92InsertValuesSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder
insertStmt Sql92InsertTableNameSyntax SqlSyntaxBuilder
tblNm [Text]
fields Sql92InsertValuesSyntax SqlSyntaxBuilder
values =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"INSERT INTO " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92InsertTableNameSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
tblNm Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((Text -> Builder) -> [Text] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Builder
quoteSql [Text]
fields) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
SqlSyntaxBuilder -> Builder
buildSql Sql92InsertValuesSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
values
instance IsSql92InsertValuesSyntax SqlSyntaxBuilder where
type Sql92InsertValuesExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92InsertValuesSelectSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
insertSqlExpressions :: [[Sql92InsertValuesExpressionSyntax SqlSyntaxBuilder]]
-> SqlSyntaxBuilder
insertSqlExpressions [[Sql92InsertValuesExpressionSyntax SqlSyntaxBuilder]]
values =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"VALUES " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") (([SqlSyntaxBuilder] -> Builder)
-> [[SqlSyntaxBuilder]] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map [SqlSyntaxBuilder] -> Builder
mkValues [[Sql92InsertValuesExpressionSyntax SqlSyntaxBuilder]]
[[SqlSyntaxBuilder]]
values)
where mkValues :: [SqlSyntaxBuilder] -> Builder
mkValues [SqlSyntaxBuilder]
values' =
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
values') Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")"
insertFromSql :: Sql92InsertValuesSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
insertFromSql Sql92InsertValuesSelectSyntax SqlSyntaxBuilder
select = Sql92InsertValuesSelectSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
select
instance IsSql92UpdateSyntax SqlSyntaxBuilder where
type Sql92UpdateFieldNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92UpdateExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92UpdateTableNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
updateStmt :: Sql92UpdateTableNameSyntax SqlSyntaxBuilder
-> [(Sql92UpdateFieldNameSyntax SqlSyntaxBuilder,
Sql92UpdateExpressionSyntax SqlSyntaxBuilder)]
-> Maybe (Sql92UpdateExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
updateStmt Sql92UpdateTableNameSyntax SqlSyntaxBuilder
tblNm [(Sql92UpdateFieldNameSyntax SqlSyntaxBuilder,
Sql92UpdateExpressionSyntax SqlSyntaxBuilder)]
set Maybe (Sql92UpdateExpressionSyntax SqlSyntaxBuilder)
where_ =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"UPDATE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92UpdateTableNameSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
tblNm Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
(case [(Sql92UpdateFieldNameSyntax SqlSyntaxBuilder,
Sql92UpdateExpressionSyntax SqlSyntaxBuilder)]
set of
[] -> Builder
forall a. Monoid a => a
mempty
[(Sql92UpdateFieldNameSyntax SqlSyntaxBuilder,
Sql92UpdateExpressionSyntax SqlSyntaxBuilder)]
es -> ByteString -> Builder
byteString ByteString
" SET " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") (((SqlSyntaxBuilder, SqlSyntaxBuilder) -> Builder)
-> [(SqlSyntaxBuilder, SqlSyntaxBuilder)] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (\(SqlSyntaxBuilder
field, SqlSyntaxBuilder
expr) -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
field Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"=" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
expr) [(Sql92UpdateFieldNameSyntax SqlSyntaxBuilder,
Sql92UpdateExpressionSyntax SqlSyntaxBuilder)]
[(SqlSyntaxBuilder, SqlSyntaxBuilder)]
es)) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
where_ -> ByteString -> Builder
byteString ByteString
" WHERE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
where_) Maybe (Sql92UpdateExpressionSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
where_
instance IsSql92DeleteSyntax SqlSyntaxBuilder where
type Sql92DeleteExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92DeleteTableNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
deleteStmt :: Sql92DeleteTableNameSyntax SqlSyntaxBuilder
-> Maybe Text
-> Maybe (Sql92DeleteExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
deleteStmt Sql92DeleteTableNameSyntax SqlSyntaxBuilder
tblNm Maybe Text
alias Maybe (Sql92DeleteExpressionSyntax SqlSyntaxBuilder)
where_ =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"DELETE FROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92DeleteTableNameSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
tblNm Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> (Text -> Builder) -> Maybe Text -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\Text
alias_ -> ByteString -> Builder
byteString ByteString
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
quoteSql Text
alias_) Maybe Text
alias Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
where_ -> ByteString -> Builder
byteString ByteString
" WHERE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
where_) Maybe (Sql92DeleteExpressionSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
where_
deleteSupportsAlias :: Proxy SqlSyntaxBuilder -> Bool
deleteSupportsAlias Proxy SqlSyntaxBuilder
_ = Bool
True
instance IsSql92FieldNameSyntax SqlSyntaxBuilder where
qualifiedField :: Text -> Text -> SqlSyntaxBuilder
qualifiedField Text
a Text
b =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"`" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
stringUtf8 (Text -> String
T.unpack Text
a) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"`.`" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
String -> Builder
stringUtf8 (Text -> String
T.unpack Text
b) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"`"
unqualifiedField :: Text -> SqlSyntaxBuilder
unqualifiedField Text
a =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"`" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
stringUtf8 (Text -> String
T.unpack Text
a) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"`"
instance IsSql92QuantifierSyntax SqlSyntaxBuilder where
quantifyOverAll :: SqlSyntaxBuilder
quantifyOverAll = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"ALL"
quantifyOverAny :: SqlSyntaxBuilder
quantifyOverAny = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"ANY"
instance IsSql92ExtractFieldSyntax SqlSyntaxBuilder where
secondsField :: SqlSyntaxBuilder
secondsField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"SECOND")
minutesField :: SqlSyntaxBuilder
minutesField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"MINUTE")
hourField :: SqlSyntaxBuilder
hourField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"HOUR")
dayField :: SqlSyntaxBuilder
dayField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"DAY")
monthField :: SqlSyntaxBuilder
monthField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"MONTH")
yearField :: SqlSyntaxBuilder
yearField = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"YEAR")
instance IsSql92ExpressionSyntax SqlSyntaxBuilder where
type Sql92ExpressionValueSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92ExpressionSelectSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92ExpressionFieldNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92ExpressionCastTargetSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type SqlSyntaxBuilder = SqlSyntaxBuilder
rowE :: [SqlSyntaxBuilder] -> SqlSyntaxBuilder
rowE [SqlSyntaxBuilder]
vs = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql ([SqlSyntaxBuilder] -> [SqlSyntaxBuilder]
coerce [SqlSyntaxBuilder]
vs)) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")"
isNotNullE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isNotNullE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS NOT NULL"
isNullE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isNullE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS NULL"
isTrueE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isTrueE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS TRUE"
isFalseE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isFalseE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS FALSE"
isUnknownE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isUnknownE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS UNKNOWN"
isNotTrueE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isNotTrueE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS NOT TRUE"
isNotFalseE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isNotFalseE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS NOT FALSE"
isNotUnknownE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
isNotUnknownE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
"IS NOT UNKNOWN"
caseE :: [(SqlSyntaxBuilder, SqlSyntaxBuilder)]
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
caseE [(SqlSyntaxBuilder, SqlSyntaxBuilder)]
cases SqlSyntaxBuilder
else_ =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"CASE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
((SqlSyntaxBuilder, SqlSyntaxBuilder) -> Builder)
-> [(SqlSyntaxBuilder, SqlSyntaxBuilder)] -> Builder
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SqlSyntaxBuilder
cond, SqlSyntaxBuilder
res) -> ByteString -> Builder
byteString ByteString
"WHEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
cond Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
" THEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
res Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") [(SqlSyntaxBuilder, SqlSyntaxBuilder)]
cases Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
"ELSE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
else_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" END"
fieldE :: Sql92ExpressionFieldNameSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
fieldE = Sql92ExpressionFieldNameSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
nullIfE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
nullIfE SqlSyntaxBuilder
a SqlSyntaxBuilder
b = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"NULLIF" (SqlSyntaxBuilder -> SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"), (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
positionE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
positionE SqlSyntaxBuilder
needle SqlSyntaxBuilder
haystack =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$ ByteString -> Builder
byteString ByteString
"POSITION(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
needle Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") IN (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
haystack Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
extractE :: Sql92ExpressionExtractFieldSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
extractE Sql92ExpressionExtractFieldSyntax SqlSyntaxBuilder
what SqlSyntaxBuilder
from =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$ ByteString -> Builder
byteString ByteString
"EXTRACT(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92ExpressionExtractFieldSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
what Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" FROM (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
from Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"))"
absE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
absE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"ABS"
charLengthE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
charLengthE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"CHAR_LENGTH"
bitLengthE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
bitLengthE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"BIT_LENGTH"
octetLengthE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
octetLengthE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"OCTET_LENGTH"
lowerE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
lowerE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"LOWER"
upperE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
upperE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"UPPER"
trimE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
trimE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
"TRIM"
addE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
addE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"+"
likeE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
likeE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"LIKE"
subE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
subE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"-"
mulE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
mulE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"*"
divE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
divE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"/"
modE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
modE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"%"
overlapsE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
overlapsE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"OVERLAPS"
andE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
andE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"AND"
orE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
orE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"OR"
castE :: SqlSyntaxBuilder
-> Sql92ExpressionCastTargetSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder
castE SqlSyntaxBuilder
a Sql92ExpressionCastTargetSyntax SqlSyntaxBuilder
ty = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"CAST((" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92ExpressionCastTargetSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
ty Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
coalesceE :: [SqlSyntaxBuilder] -> SqlSyntaxBuilder
coalesceE [SqlSyntaxBuilder]
es = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"COALESCE(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (\SqlSyntaxBuilder
e -> ByteString -> Builder
byteStringByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
e Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")") [SqlSyntaxBuilder]
es) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")"
betweenE :: SqlSyntaxBuilder
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
betweenE SqlSyntaxBuilder
a SqlSyntaxBuilder
b SqlSyntaxBuilder
c = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") BETWEEN (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") AND (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
c Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
eqE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
eqE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
"="
neqE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
neqE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
"<>"
ltE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
ltE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
"<"
gtE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
gtE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
">"
leE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
leE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
"<="
geE :: Maybe (Sql92ExpressionQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
geE = ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
">="
negateE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
negateE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
"-"
notE :: SqlSyntaxBuilder -> SqlSyntaxBuilder
notE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
"NOT"
existsE :: Sql92ExpressionSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
existsE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
"EXISTS"
uniqueE :: Sql92ExpressionSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
uniqueE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
"UNIQUE"
subqueryE :: Sql92ExpressionSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
subqueryE Sql92ExpressionSelectSyntax SqlSyntaxBuilder
a = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$ ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92ExpressionSelectSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
valueE :: Sql92ExpressionValueSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
valueE = Sql92ExpressionValueSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
forall a. a -> a
id
currentTimestampE :: SqlSyntaxBuilder
currentTimestampE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"CURRENT_TIMESTAMP")
defaultE :: SqlSyntaxBuilder
defaultE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"DEFAULT")
inE :: SqlSyntaxBuilder -> [SqlSyntaxBuilder] -> SqlSyntaxBuilder
inE SqlSyntaxBuilder
a [SqlSyntaxBuilder]
es = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") IN (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
es))
instance IsSql99FunctionExpressionSyntax SqlSyntaxBuilder where
functionNameE :: Text -> SqlSyntaxBuilder
functionNameE Text
fn = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString (Text -> ByteString
TE.encodeUtf8 Text
fn))
functionCallE :: SqlSyntaxBuilder -> [SqlSyntaxBuilder] -> SqlSyntaxBuilder
functionCallE SqlSyntaxBuilder
function [SqlSyntaxBuilder]
args =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
function Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
args) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")"
instance IsSql99ExpressionSyntax SqlSyntaxBuilder where
distinctE :: Sql92ExpressionSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
distinctE = ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
"DISTINCT"
similarToE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
similarToE = ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
"SIMILAR TO"
instanceFieldE :: SqlSyntaxBuilder -> Text -> SqlSyntaxBuilder
instanceFieldE SqlSyntaxBuilder
e Text
fieldNm =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
e Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")." Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (Text -> ByteString
TE.encodeUtf8 Text
fieldNm)
refFieldE :: SqlSyntaxBuilder -> Text -> SqlSyntaxBuilder
refFieldE SqlSyntaxBuilder
e Text
fieldNm =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
e Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")->" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (Text -> ByteString
TE.encodeUtf8 Text
fieldNm)
instance IsSql2003ExpressionSyntax SqlSyntaxBuilder where
type Sql2003ExpressionWindowFrameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
overE :: SqlSyntaxBuilder
-> Sql2003ExpressionWindowFrameSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder
overE SqlSyntaxBuilder
expr Sql2003ExpressionWindowFrameSyntax SqlSyntaxBuilder
frame =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
expr Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql2003ExpressionWindowFrameSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
frame
rowNumberE :: SqlSyntaxBuilder
rowNumberE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"ROW_NUMBER()")
instance IsSql2003WindowFrameSyntax SqlSyntaxBuilder where
type Sql2003WindowFrameExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql2003WindowFrameOrderingSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql2003WindowFrameBoundsSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
frameSyntax :: Maybe [Sql2003WindowFrameExpressionSyntax SqlSyntaxBuilder]
-> Maybe [Sql2003WindowFrameOrderingSyntax SqlSyntaxBuilder]
-> Maybe (Sql2003WindowFrameBoundsSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
frameSyntax Maybe [Sql2003WindowFrameExpressionSyntax SqlSyntaxBuilder]
partition_ Maybe [Sql2003WindowFrameOrderingSyntax SqlSyntaxBuilder]
ordering_ Maybe (Sql2003WindowFrameBoundsSyntax SqlSyntaxBuilder)
bounds_ =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
" OVER (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> ([SqlSyntaxBuilder] -> Builder)
-> Maybe [SqlSyntaxBuilder]
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\[SqlSyntaxBuilder]
p -> ByteString -> Builder
byteString ByteString
"PARTITION BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
p)) Maybe [Sql2003WindowFrameExpressionSyntax SqlSyntaxBuilder]
Maybe [SqlSyntaxBuilder]
partition_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> ([SqlSyntaxBuilder] -> Builder)
-> Maybe [SqlSyntaxBuilder]
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\[SqlSyntaxBuilder]
o -> ByteString -> Builder
byteString ByteString
" ORDER BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
o)) Maybe [Sql2003WindowFrameOrderingSyntax SqlSyntaxBuilder]
Maybe [SqlSyntaxBuilder]
ordering_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
b -> ByteString -> Builder
byteString ByteString
" ROWS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b) Maybe (Sql2003WindowFrameBoundsSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
bounds_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")"
instance IsSql2003ExpressionElementaryOLAPOperationsSyntax SqlSyntaxBuilder where
filterAggE :: SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
filterAggE SqlSyntaxBuilder
agg_ SqlSyntaxBuilder
filter_ =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
agg_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" FILTER (WHERE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
filter_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
rankAggE :: SqlSyntaxBuilder
rankAggE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"RANK()"
instance IsSql2003ExpressionAdvancedOLAPOperationsSyntax SqlSyntaxBuilder where
denseRankAggE :: SqlSyntaxBuilder
denseRankAggE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"DENSE_RANK()"
percentRankAggE :: SqlSyntaxBuilder
percentRankAggE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"PERCENT_RANK()"
cumeDistAggE :: SqlSyntaxBuilder
cumeDistAggE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"CUME_DIST()"
data SqlWindowFrameBound = SqlWindowFrameUnbounded
| SqlWindowFrameBounded Int
deriving Int -> SqlWindowFrameBound -> ShowS
[SqlWindowFrameBound] -> ShowS
SqlWindowFrameBound -> String
(Int -> SqlWindowFrameBound -> ShowS)
-> (SqlWindowFrameBound -> String)
-> ([SqlWindowFrameBound] -> ShowS)
-> Show SqlWindowFrameBound
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqlWindowFrameBound] -> ShowS
$cshowList :: [SqlWindowFrameBound] -> ShowS
show :: SqlWindowFrameBound -> String
$cshow :: SqlWindowFrameBound -> String
showsPrec :: Int -> SqlWindowFrameBound -> ShowS
$cshowsPrec :: Int -> SqlWindowFrameBound -> ShowS
Show
instance IsSql2003WindowFrameBoundsSyntax SqlSyntaxBuilder where
type Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder = SqlWindowFrameBound
fromToBoundSyntax :: Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
-> Maybe (Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded Maybe (Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder)
Nothing = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"UNBOUNDED PRECEDING"
fromToBoundSyntax (SqlWindowFrameBounded 0) Maybe (Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder)
Nothing = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"CURRENT ROW"
fromToBoundSyntax (SqlWindowFrameBounded n) Maybe (Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder)
Nothing = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" PRECEDING")
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded (Just Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING"
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded (Just (SqlWindowFrameBounded 0)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW"
fromToBoundSyntax Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded (Just (SqlWindowFrameBounded n)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BETWEEN UNBOUNDED PRECEDING AND " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" FOLLOWING")
fromToBoundSyntax (SqlWindowFrameBounded 0) (Just Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING"
fromToBoundSyntax (SqlWindowFrameBounded 0) (Just (SqlWindowFrameBounded 0)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"BETWEEN CURRENT ROW AND CURRENT ROW"
fromToBoundSyntax (SqlWindowFrameBounded 0) (Just (SqlWindowFrameBounded n)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BETWEEN CURRENT ROW AND " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" FOLLOWING")
fromToBoundSyntax (SqlWindowFrameBounded n) (Just Sql2003WindowFrameBoundsBoundSyntax SqlSyntaxBuilder
SqlWindowFrameUnbounded) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BETWEEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" PRECEDING AND UNBOUNDED FOLLOWING")
fromToBoundSyntax (SqlWindowFrameBounded n) (Just (SqlWindowFrameBounded 0)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BETWEEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" PRECEDING AND CURRENT ROW")
fromToBoundSyntax (SqlWindowFrameBounded n1) (Just (SqlWindowFrameBounded n2)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BETWEEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n1) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" PRECEDING AND " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
n2) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" FOLLOWING")
instance IsSql2003WindowFrameBoundSyntax SqlWindowFrameBound where
unboundedSyntax :: SqlWindowFrameBound
unboundedSyntax = SqlWindowFrameBound
SqlWindowFrameUnbounded
nrowsBoundSyntax :: Int -> SqlWindowFrameBound
nrowsBoundSyntax = Int -> SqlWindowFrameBound
SqlWindowFrameBounded
instance IsSql92AggregationExpressionSyntax SqlSyntaxBuilder where
type Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
countAllE :: SqlSyntaxBuilder
countAllE = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"COUNT(*)")
countE :: Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
countE Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
q SqlSyntaxBuilder
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"COUNT(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
q' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
q' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
q Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
avgE :: Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
avgE Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
q SqlSyntaxBuilder
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"AVG(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
q' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
q' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
q Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
minE :: Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
minE Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
q SqlSyntaxBuilder
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"MIN(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
q' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
q' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
q Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
maxE :: Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
maxE Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
q SqlSyntaxBuilder
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"MAX(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
q' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
q' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
q Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
sumE :: Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
sumE Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
q SqlSyntaxBuilder
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"SUM(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
q' -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
q' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ") Maybe (Sql92AggregationSetQuantifierSyntax SqlSyntaxBuilder)
Maybe SqlSyntaxBuilder
q Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
instance IsSql92AggregationSetQuantifierSyntax SqlSyntaxBuilder where
setQuantifierAll :: SqlSyntaxBuilder
setQuantifierAll = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"ALL")
setQuantifierDistinct :: SqlSyntaxBuilder
setQuantifierDistinct = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"DISTINCT")
instance IsSql92ProjectionSyntax SqlSyntaxBuilder where
type Sql92ProjectionExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
projExprs :: [(Sql92ProjectionExpressionSyntax SqlSyntaxBuilder, Maybe Text)]
-> SqlSyntaxBuilder
projExprs [(Sql92ProjectionExpressionSyntax SqlSyntaxBuilder, Maybe Text)]
exprs =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ")
(((SqlSyntaxBuilder, Maybe Text) -> Builder)
-> [(SqlSyntaxBuilder, Maybe Text)] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (\(SqlSyntaxBuilder
expr, Maybe Text
nm) -> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
expr Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> (Text -> Builder) -> Maybe Text -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\Text
nm -> ByteString -> Builder
byteString ByteString
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
quoteSql Text
nm) Maybe Text
nm) [(Sql92ProjectionExpressionSyntax SqlSyntaxBuilder, Maybe Text)]
[(SqlSyntaxBuilder, Maybe Text)]
exprs)
instance IsSql92OrderingSyntax SqlSyntaxBuilder where
type Sql92OrderingExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
ascOrdering :: Sql92OrderingExpressionSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
ascOrdering Sql92OrderingExpressionSyntax SqlSyntaxBuilder
expr = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (SqlSyntaxBuilder -> Builder
buildSql Sql92OrderingExpressionSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
expr Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" ASC")
descOrdering :: Sql92OrderingExpressionSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
descOrdering Sql92OrderingExpressionSyntax SqlSyntaxBuilder
expr = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (SqlSyntaxBuilder -> Builder
buildSql Sql92OrderingExpressionSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
expr Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" DESC")
instance IsSql92TableSourceSyntax SqlSyntaxBuilder where
type Sql92TableSourceTableNameSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92TableSourceSelectSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92TableSourceExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
tableNamed :: Sql92TableSourceTableNameSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder
tableNamed = Sql92TableSourceTableNameSyntax SqlSyntaxBuilder
-> SqlSyntaxBuilder
forall a. a -> a
id
tableFromSubSelect :: Sql92TableSourceSelectSyntax SqlSyntaxBuilder -> SqlSyntaxBuilder
tableFromSubSelect Sql92TableSourceSelectSyntax SqlSyntaxBuilder
query = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql Sql92TableSourceSelectSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
query Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")")
tableFromValues :: [[Sql92TableSourceExpressionSyntax SqlSyntaxBuilder]]
-> SqlSyntaxBuilder
tableFromValues [[Sql92TableSourceExpressionSyntax SqlSyntaxBuilder]]
vss =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"VALUES " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ")
(([SqlSyntaxBuilder] -> Builder)
-> [[SqlSyntaxBuilder]] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (\[SqlSyntaxBuilder]
vs -> ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((SqlSyntaxBuilder -> Builder) -> [SqlSyntaxBuilder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map SqlSyntaxBuilder -> Builder
buildSql [SqlSyntaxBuilder]
vs) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
")") [[Sql92TableSourceExpressionSyntax SqlSyntaxBuilder]]
[[SqlSyntaxBuilder]]
vss)
instance IsSql92TableNameSyntax SqlSyntaxBuilder where
tableName :: Maybe Text -> Text -> SqlSyntaxBuilder
tableName Maybe Text
Nothing Text
t = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$ Text -> Builder
quoteSql Text
t
tableName (Just Text
s) Text
t = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$ Text -> Builder
quoteSql Text
s Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"." Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
quoteSql Text
t
instance IsSql92FromSyntax SqlSyntaxBuilder where
type Sql92FromTableSourceSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
type Sql92FromExpressionSyntax SqlSyntaxBuilder = SqlSyntaxBuilder
fromTable :: Sql92FromTableSourceSyntax SqlSyntaxBuilder
-> Maybe (Text, Maybe [Text]) -> SqlSyntaxBuilder
fromTable Sql92FromTableSourceSyntax SqlSyntaxBuilder
t Maybe (Text, Maybe [Text])
Nothing = Sql92FromTableSourceSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
t
fromTable Sql92FromTableSourceSyntax SqlSyntaxBuilder
t (Just (Text
nm, Maybe [Text]
colNms)) =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (SqlSyntaxBuilder -> Builder
buildSql Sql92FromTableSourceSyntax SqlSyntaxBuilder
SqlSyntaxBuilder
t Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
quoteSql Text
nm Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder -> ([Text] -> Builder) -> Maybe [Text] -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\[Text]
colNms' -> ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy (ByteString -> Builder
byteString ByteString
", ") ((Text -> Builder) -> [Text] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Builder
quoteSql [Text]
colNms') Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")") Maybe [Text]
colNms)
innerJoin :: SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe (Sql92FromExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
innerJoin = ByteString
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
join ByteString
"INNER JOIN"
leftJoin :: SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe (Sql92FromExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
leftJoin = ByteString
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
join ByteString
"LEFT JOIN"
rightJoin :: SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe (Sql92FromExpressionSyntax SqlSyntaxBuilder)
-> SqlSyntaxBuilder
rightJoin = ByteString
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
join ByteString
"RIGHT JOIN"
instance IsSql92DataTypeSyntax SqlSyntaxBuilder where
domainType :: Text -> SqlSyntaxBuilder
domainType Text
nm = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Text -> Builder
quoteSql Text
nm)
charType :: Maybe Word -> Maybe Text -> SqlSyntaxBuilder
charType Maybe Word
prec Maybe Text
charSet = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"CHAR" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> Builder
sqlOptCharSet Maybe Text
charSet)
varCharType :: Maybe Word -> Maybe Text -> SqlSyntaxBuilder
varCharType Maybe Word
prec Maybe Text
charSet = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"VARCHAR" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> Builder
sqlOptCharSet Maybe Text
charSet)
nationalCharType :: Maybe Word -> SqlSyntaxBuilder
nationalCharType Maybe Word
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"NATIONAL CHAR" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec)
nationalVarCharType :: Maybe Word -> SqlSyntaxBuilder
nationalVarCharType Maybe Word
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"NATIONAL CHARACTER VARYING" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec)
bitType :: Maybe Word -> SqlSyntaxBuilder
bitType Maybe Word
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BIT" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec)
varBitType :: Maybe Word -> SqlSyntaxBuilder
varBitType Maybe Word
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"BIT VARYING" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec)
numericType :: Maybe (Word, Maybe Word) -> SqlSyntaxBuilder
numericType Maybe (Word, Maybe Word)
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"NUMERIC" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> Builder
sqlOptNumericPrec Maybe (Word, Maybe Word)
prec)
decimalType :: Maybe (Word, Maybe Word) -> SqlSyntaxBuilder
decimalType Maybe (Word, Maybe Word)
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"DECIMAL" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> Builder
sqlOptNumericPrec Maybe (Word, Maybe Word)
prec)
intType :: SqlSyntaxBuilder
intType = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"INT"
smallIntType :: SqlSyntaxBuilder
smallIntType = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"SMALLINT"
floatType :: Maybe Word -> SqlSyntaxBuilder
floatType Maybe Word
prec = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"FLOAT" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec)
doubleType :: SqlSyntaxBuilder
doubleType = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"DOUBLE PRECISION"
realType :: SqlSyntaxBuilder
realType = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"REAL"
dateType :: SqlSyntaxBuilder
dateType = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder Builder
"DATE"
timeType :: Maybe Word -> Bool -> SqlSyntaxBuilder
timeType Maybe Word
prec Bool
withTz =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"TIME" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then Builder
" WITH TIME ZONE" else Builder
forall a. Monoid a => a
mempty)
timestampType :: Maybe Word -> Bool -> SqlSyntaxBuilder
timestampType Maybe Word
prec Bool
withTz =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder
"TIMESTAMP" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> Builder
sqlOptPrec Maybe Word
prec Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then Builder
" WITH TIME ZONE" else Builder
forall a. Monoid a => a
mempty)
sqlOptPrec :: Maybe Word -> Builder
sqlOptPrec :: Maybe Word -> Builder
sqlOptPrec Maybe Word
Nothing = Builder
forall a. Monoid a => a
mempty
sqlOptPrec (Just Word
x) = Builder
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
x)) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
")"
sqlOptCharSet :: Maybe T.Text -> Builder
sqlOptCharSet :: Maybe Text -> Builder
sqlOptCharSet Maybe Text
Nothing = Builder
forall a. Monoid a => a
mempty
sqlOptCharSet (Just Text
cs) = Builder
" CHARACTER SET " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (Text -> ByteString
TE.encodeUtf8 Text
cs)
sqlOptNumericPrec :: Maybe (Word, Maybe Word) -> Builder
sqlOptNumericPrec :: Maybe (Word, Maybe Word) -> Builder
sqlOptNumericPrec Maybe (Word, Maybe Word)
Nothing = Builder
forall a. Monoid a => a
mempty
sqlOptNumericPrec (Just (Word
prec, Maybe Word
Nothing)) = Maybe Word -> Builder
sqlOptPrec (Word -> Maybe Word
forall a. a -> Maybe a
Just Word
prec)
sqlOptNumericPrec (Just (Word
prec, Just Word
dec)) = Builder
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
prec) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> String -> Builder
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
dec) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
")"
instance HasSqlValueSyntax SqlSyntaxBuilder Int32 where
sqlValueSyntax :: Int32 -> SqlSyntaxBuilder
sqlValueSyntax Int32
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Int32 -> String
forall a. Show a => a -> String
show Int32
x))
instance HasSqlValueSyntax SqlSyntaxBuilder Bool where
sqlValueSyntax :: Bool -> SqlSyntaxBuilder
sqlValueSyntax Bool
True = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"TRUE")
sqlValueSyntax Bool
False = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"FALSE")
instance HasSqlValueSyntax SqlSyntaxBuilder Text where
sqlValueSyntax :: Text -> SqlSyntaxBuilder
sqlValueSyntax Text
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Text -> String
forall a. Show a => a -> String
show Text
x))
instance HasSqlValueSyntax SqlSyntaxBuilder SqlNull where
sqlValueSyntax :: SqlNull -> SqlSyntaxBuilder
sqlValueSyntax SqlNull
_ = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (ByteString -> Builder
byteString ByteString
"NULL")
instance TypeError (PreferExplicitSize Int Int32) => HasSqlValueSyntax SqlSyntaxBuilder Int where
sqlValueSyntax :: Int -> SqlSyntaxBuilder
sqlValueSyntax Int
x = Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (Int -> String
forall a. Show a => a -> String
show Int
x))
renderSql :: SqlSyntaxBuilder -> String
renderSql :: SqlSyntaxBuilder -> String
renderSql (SqlSyntaxBuilder Builder
b) = ByteString -> String
BL.unpack (Builder -> ByteString
toLazyByteString Builder
b)
buildSepBy :: Builder -> [Builder] -> Builder
buildSepBy :: Builder -> [Builder] -> Builder
buildSepBy Builder
_ [] = Builder
forall a. Monoid a => a
mempty
buildSepBy Builder
_ [Builder
x] = Builder
x
buildSepBy Builder
sep (Builder
x:[Builder]
xs) = Builder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
sep Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [Builder] -> Builder
buildSepBy Builder
sep [Builder]
xs
quoteSql :: Text -> Builder
quoteSql :: Text -> Builder
quoteSql Text
table =
ByteString -> Builder
byteString ByteString
"\"" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString (Text -> ByteString
TE.encodeUtf8 Text
table) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"\""
join :: ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
-> Maybe SqlSyntaxBuilder -> SqlSyntaxBuilder
join :: ByteString
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
join ByteString
type_ SqlSyntaxBuilder
a SqlSyntaxBuilder
b Maybe SqlSyntaxBuilder
on =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
type_ Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
case Maybe SqlSyntaxBuilder
on of
Maybe SqlSyntaxBuilder
Nothing -> Builder
forall a. Monoid a => a
mempty
Just SqlSyntaxBuilder
on -> ByteString -> Builder
byteString ByteString
" ON (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
on Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
sqlPostFixOp, sqlUnOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlUnOp ByteString
op SqlSyntaxBuilder
a =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
" (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
sqlPostFixOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlPostFixOp ByteString
op SqlSyntaxBuilder
a =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
op
sqlCompOp :: ByteString -> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder -> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp :: ByteString
-> Maybe SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlCompOp ByteString
op Maybe SqlSyntaxBuilder
quant SqlSyntaxBuilder
a SqlSyntaxBuilder
b =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
-> (SqlSyntaxBuilder -> Builder)
-> Maybe SqlSyntaxBuilder
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty (\SqlSyntaxBuilder
quant -> ByteString -> Builder
byteString ByteString
" " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
quant) Maybe SqlSyntaxBuilder
quant Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
" (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
sqlBinOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
-> SqlSyntaxBuilder
sqlBinOp :: ByteString
-> SqlSyntaxBuilder -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlBinOp ByteString
op SqlSyntaxBuilder
a SqlSyntaxBuilder
b =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
") " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
ByteString -> Builder
byteString ByteString
" (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
")"
sqlFuncOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp :: ByteString -> SqlSyntaxBuilder -> SqlSyntaxBuilder
sqlFuncOp ByteString
fun SqlSyntaxBuilder
a =
Builder -> SqlSyntaxBuilder
SqlSyntaxBuilder (Builder -> SqlSyntaxBuilder) -> Builder -> SqlSyntaxBuilder
forall a b. (a -> b) -> a -> b
$
ByteString -> Builder
byteString ByteString
fun Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteString ByteString
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlSyntaxBuilder -> Builder
buildSql SqlSyntaxBuilder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
byteStringByteString
")"
newtype SqlSyntaxM a = SqlSyntaxM (IO a)
deriving (Functor SqlSyntaxM
a -> SqlSyntaxM a
Functor SqlSyntaxM
-> (forall a. a -> SqlSyntaxM a)
-> (forall a b.
SqlSyntaxM (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b)
-> (forall a b c.
(a -> b -> c) -> SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM c)
-> (forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b)
-> (forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM a)
-> Applicative SqlSyntaxM
SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM a
SqlSyntaxM (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
(a -> b -> c) -> SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM c
forall a. a -> SqlSyntaxM a
forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM a
forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
forall a b. SqlSyntaxM (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
forall a b c.
(a -> b -> c) -> SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM a
$c<* :: forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM a
*> :: SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
$c*> :: forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
liftA2 :: (a -> b -> c) -> SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM c
$cliftA2 :: forall a b c.
(a -> b -> c) -> SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM c
<*> :: SqlSyntaxM (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
$c<*> :: forall a b. SqlSyntaxM (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
pure :: a -> SqlSyntaxM a
$cpure :: forall a. a -> SqlSyntaxM a
$cp1Applicative :: Functor SqlSyntaxM
Applicative, a -> SqlSyntaxM b -> SqlSyntaxM a
(a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
(forall a b. (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b)
-> (forall a b. a -> SqlSyntaxM b -> SqlSyntaxM a)
-> Functor SqlSyntaxM
forall a b. a -> SqlSyntaxM b -> SqlSyntaxM a
forall a b. (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SqlSyntaxM b -> SqlSyntaxM a
$c<$ :: forall a b. a -> SqlSyntaxM b -> SqlSyntaxM a
fmap :: (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
$cfmap :: forall a b. (a -> b) -> SqlSyntaxM a -> SqlSyntaxM b
Functor, Applicative SqlSyntaxM
a -> SqlSyntaxM a
Applicative SqlSyntaxM
-> (forall a b.
SqlSyntaxM a -> (a -> SqlSyntaxM b) -> SqlSyntaxM b)
-> (forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b)
-> (forall a. a -> SqlSyntaxM a)
-> Monad SqlSyntaxM
SqlSyntaxM a -> (a -> SqlSyntaxM b) -> SqlSyntaxM b
SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
forall a. a -> SqlSyntaxM a
forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
forall a b. SqlSyntaxM a -> (a -> SqlSyntaxM b) -> SqlSyntaxM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> SqlSyntaxM a
$creturn :: forall a. a -> SqlSyntaxM a
>> :: SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
$c>> :: forall a b. SqlSyntaxM a -> SqlSyntaxM b -> SqlSyntaxM b
>>= :: SqlSyntaxM a -> (a -> SqlSyntaxM b) -> SqlSyntaxM b
$c>>= :: forall a b. SqlSyntaxM a -> (a -> SqlSyntaxM b) -> SqlSyntaxM b
$cp1Monad :: Applicative SqlSyntaxM
Monad, Monad SqlSyntaxM
Monad SqlSyntaxM
-> (forall a. IO a -> SqlSyntaxM a) -> MonadIO SqlSyntaxM
IO a -> SqlSyntaxM a
forall a. IO a -> SqlSyntaxM a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> SqlSyntaxM a
$cliftIO :: forall a. IO a -> SqlSyntaxM a
$cp1MonadIO :: Monad SqlSyntaxM
MonadIO, Monad SqlSyntaxM
Monad SqlSyntaxM
-> (forall a. String -> SqlSyntaxM a) -> MonadFail SqlSyntaxM
String -> SqlSyntaxM a
forall a. String -> SqlSyntaxM a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> SqlSyntaxM a
$cfail :: forall a. String -> SqlSyntaxM a
$cp1MonadFail :: Monad SqlSyntaxM
Fail.MonadFail)