{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-name-shadowing#-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE CPP #-}
module Database.Beam.Sqlite.Syntax
(
SqliteSyntax(..)
, SqliteCommandSyntax(..)
, SqliteSelectSyntax(..), SqliteInsertSyntax(..)
, SqliteUpdateSyntax(..), SqliteDeleteSyntax(..)
, SqliteOnConflictSyntax(..)
, SqliteInsertValuesSyntax(..)
, SqliteColumnSchemaSyntax(..)
, SqliteExpressionSyntax(..), SqliteValueSyntax(..)
, SqliteTableNameSyntax(..)
, SqliteFieldNameSyntax(..)
, SqliteAggregationSetQuantifierSyntax(..)
, fromSqliteExpression
, SqliteDataTypeSyntax(..)
, sqliteTextType, sqliteBlobType
, sqliteBigIntType, sqliteSerialType
, fromSqliteCommand, formatSqliteInsert, formatSqliteInsertOnConflict
, emit, emitValue, parens, commas, quotedIdentifier
, sqliteEscape, withPlaceholders
, sqliteRenderSyntaxScript
) where
import Database.Beam.Backend.Internal.Compat
import Database.Beam.Backend.SQL
import Database.Beam.Backend.SQL.AST (ExtractField(..))
import Database.Beam.Haskell.Syntax
import Database.Beam.Migrate.Checks (HasDataTypeCreatedCheck(..))
import Database.Beam.Migrate.SQL.Builder hiding (fromSqlConstraintAttributes)
import Database.Beam.Migrate.SQL.SQL92
import Database.Beam.Migrate.Serialization
import Database.Beam.Query hiding (ExtractField(..))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Coerce
import qualified Data.DList as DL
import Data.Hashable
import Data.Int
import Data.Maybe
import Data.Scientific
import Data.String
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Lazy as TL
import Data.Time
import Data.Word
#if !MIN_VERSION_base(4, 11, 0)
import Data.Semigroup
#endif
import GHC.TypeLits
import Database.SQLite.Simple (SQLData(..))
import GHC.Float
import GHC.Generics
data SqliteSyntax = SqliteSyntax ((SQLData -> Builder) -> Builder) (DL.DList SQLData)
newtype SqliteData = SqliteData SQLData
deriving SqliteData -> SqliteData -> Bool
(SqliteData -> SqliteData -> Bool)
-> (SqliteData -> SqliteData -> Bool) -> Eq SqliteData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqliteData -> SqliteData -> Bool
$c/= :: SqliteData -> SqliteData -> Bool
== :: SqliteData -> SqliteData -> Bool
$c== :: SqliteData -> SqliteData -> Bool
Eq
instance Show SqliteSyntax where
show :: SqliteSyntax -> String
show (SqliteSyntax (SQLData -> Builder) -> Builder
s DList SQLData
d) =
String
"SqliteSyntax (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ByteString -> String
forall a. Show a => a -> String
show (Builder -> ByteString
toLazyByteString (((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders (SQLData -> Builder) -> Builder
s)) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
") " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> DList SQLData -> String
forall a. Show a => a -> String
show DList SQLData
d
instance Sql92DisplaySyntax SqliteSyntax where
displaySyntax :: SqliteSyntax -> String
displaySyntax = ByteString -> String
BL.unpack (ByteString -> String)
-> (SqliteSyntax -> ByteString) -> SqliteSyntax -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> ByteString
sqliteRenderSyntaxScript
instance Semigroup SqliteSyntax where
<> :: SqliteSyntax -> SqliteSyntax -> SqliteSyntax
(<>) = SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Monoid a => a -> a -> a
mappend
instance Monoid SqliteSyntax where
mempty :: SqliteSyntax
mempty = ((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax (\SQLData -> Builder
_ -> Builder
forall a. Monoid a => a
mempty) DList SQLData
forall a. Monoid a => a
mempty
mappend :: SqliteSyntax -> SqliteSyntax -> SqliteSyntax
mappend (SqliteSyntax (SQLData -> Builder) -> Builder
ab DList SQLData
av) (SqliteSyntax (SQLData -> Builder) -> Builder
bb DList SQLData
bv) =
((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax (\SQLData -> Builder
v -> (SQLData -> Builder) -> Builder
ab SQLData -> Builder
v Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (SQLData -> Builder) -> Builder
bb SQLData -> Builder
v) (DList SQLData
av DList SQLData -> DList SQLData -> DList SQLData
forall a. Semigroup a => a -> a -> a
<> DList SQLData
bv)
instance Eq SqliteSyntax where
SqliteSyntax (SQLData -> Builder) -> Builder
ab DList SQLData
av == :: SqliteSyntax -> SqliteSyntax -> Bool
== SqliteSyntax (SQLData -> Builder) -> Builder
bb DList SQLData
bv =
Builder -> ByteString
toLazyByteString (((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders (SQLData -> Builder) -> Builder
ab) ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
==
Builder -> ByteString
toLazyByteString (((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders (SQLData -> Builder) -> Builder
bb) Bool -> Bool -> Bool
&&
DList SQLData
av DList SQLData -> DList SQLData -> Bool
forall a. Eq a => a -> a -> Bool
== DList SQLData
bv
instance Hashable SqliteSyntax where
hashWithSalt :: Int -> SqliteSyntax -> Int
hashWithSalt Int
salt (SqliteSyntax (SQLData -> Builder) -> Builder
s DList SQLData
d) =
Int -> (ByteString, [SqliteData]) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt ( Builder -> ByteString
toLazyByteString (((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders (SQLData -> Builder) -> Builder
s)
, (SQLData -> SqliteData) -> [SQLData] -> [SqliteData]
forall a b. (a -> b) -> [a] -> [b]
map SQLData -> SqliteData
SqliteData (DList SQLData -> [SQLData]
forall a. DList a -> [a]
DL.toList DList SQLData
d) )
instance Hashable SqliteData where
hashWithSalt :: Int -> SqliteData -> Int
hashWithSalt Int
salt (SqliteData (SQLInteger Int64
i)) = Int -> (Int, Int64) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
0 :: Int, Int64
i)
hashWithSalt Int
salt (SqliteData (SQLFloat Double
d)) = Int -> (Int, Double) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
1 :: Int, Double
d)
hashWithSalt Int
salt (SqliteData (SQLText Text
t)) = Int -> (Int, Text) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
2 :: Int, Text
t)
hashWithSalt Int
salt (SqliteData (SQLBlob ByteString
b)) = Int -> (Int, ByteString) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
3 :: Int, ByteString
b)
hashWithSalt Int
salt (SqliteData SQLData
SQLNull) = Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Int
4 :: Int)
withPlaceholders :: ((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders :: ((SQLData -> Builder) -> Builder) -> Builder
withPlaceholders (SQLData -> Builder) -> Builder
build = (SQLData -> Builder) -> Builder
build (\SQLData
_ -> Builder
"?")
emit :: ByteString -> SqliteSyntax
emit :: ByteString -> SqliteSyntax
emit ByteString
b = ((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax (\SQLData -> Builder
_ -> ByteString -> Builder
byteString ByteString
b) DList SQLData
forall a. Monoid a => a
mempty
emit' :: Show a => a -> SqliteSyntax
emit' :: a -> SqliteSyntax
emit' a
x = ((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax (\SQLData -> Builder
_ -> ByteString -> Builder
byteString (String -> ByteString
forall a. IsString a => String -> a
fromString (a -> String
forall a. Show a => a -> String
show a
x))) DList SQLData
forall a. Monoid a => a
mempty
quotedIdentifier :: T.Text -> SqliteSyntax
quotedIdentifier :: Text -> SqliteSyntax
quotedIdentifier Text
txt = ByteString -> SqliteSyntax
emit ByteString
"\"" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax (\SQLData -> Builder
_ -> String -> Builder
stringUtf8 (Text -> String
T.unpack (Text -> Text
sqliteEscape Text
txt))) DList SQLData
forall a. Monoid a => a
mempty SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
"\""
sqliteEscape :: T.Text -> T.Text
sqliteEscape :: Text -> Text
sqliteEscape = (Char -> Text) -> Text -> Text
T.concatMap (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'"' then Text
"\"\"" else Char -> Text
T.singleton Char
c)
emitValue :: SQLData -> SqliteSyntax
emitValue :: SQLData -> SqliteSyntax
emitValue SQLData
v = ((SQLData -> Builder) -> Builder) -> DList SQLData -> SqliteSyntax
SqliteSyntax ((SQLData -> Builder) -> SQLData -> Builder
forall a b. (a -> b) -> a -> b
$ SQLData
v) (SQLData -> DList SQLData
forall a. a -> DList a
DL.singleton SQLData
v)
sqliteRenderSyntaxScript :: SqliteSyntax -> BL.ByteString
sqliteRenderSyntaxScript :: SqliteSyntax -> ByteString
sqliteRenderSyntaxScript (SqliteSyntax (SQLData -> Builder) -> Builder
s DList SQLData
_) =
Builder -> ByteString
toLazyByteString (Builder -> ByteString)
-> ((SQLData -> Builder) -> Builder)
-> (SQLData -> Builder)
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SQLData -> Builder) -> Builder
s ((SQLData -> Builder) -> ByteString)
-> (SQLData -> Builder) -> ByteString
forall a b. (a -> b) -> a -> b
$ \case
SQLInteger Int64
i -> Int64 -> Builder
int64Dec Int64
i
SQLFloat Double
d -> Double -> Builder
doubleDec Double
d
SQLText Text
t -> Text -> Builder
TE.encodeUtf8Builder (Text -> Text
sqliteEscape Text
t)
SQLBlob ByteString
b -> Char -> Builder
char8 Char
'X' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
char8 Char
'\'' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
(Word8 -> Builder) -> [Word8] -> Builder
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Word8 -> Builder
word8Hex (ByteString -> [Word8]
B.unpack ByteString
b) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Char -> Builder
char8 Char
'\''
SQLData
SQLNull -> Builder
"NULL"
data SqliteCommandSyntax
= SqliteCommandSyntax SqliteSyntax
| SqliteCommandInsert SqliteInsertSyntax
fromSqliteCommand :: SqliteCommandSyntax -> SqliteSyntax
fromSqliteCommand :: SqliteCommandSyntax -> SqliteSyntax
fromSqliteCommand (SqliteCommandSyntax SqliteSyntax
s) = SqliteSyntax
s
fromSqliteCommand (SqliteCommandInsert (SqliteInsertSyntax SqliteTableNameSyntax
tbl [Text]
fields SqliteInsertValuesSyntax
values Maybe SqliteOnConflictSyntax
onConflict)) =
SqliteTableNameSyntax
-> [Text]
-> SqliteInsertValuesSyntax
-> Maybe SqliteOnConflictSyntax
-> SqliteSyntax
formatSqliteInsertOnConflict SqliteTableNameSyntax
tbl [Text]
fields SqliteInsertValuesSyntax
values Maybe SqliteOnConflictSyntax
onConflict
newtype SqliteSelectSyntax = SqliteSelectSyntax { SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect :: SqliteSyntax }
newtype SqliteOnConflictSyntax = SqliteOnConflictSyntax { SqliteOnConflictSyntax -> SqliteSyntax
fromSqliteOnConflict :: SqliteSyntax }
data SqliteInsertSyntax
= SqliteInsertSyntax
{ SqliteInsertSyntax -> SqliteTableNameSyntax
sqliteInsertTable :: !SqliteTableNameSyntax
, SqliteInsertSyntax -> [Text]
sqliteInsertFields :: [ T.Text ]
, SqliteInsertSyntax -> SqliteInsertValuesSyntax
sqliteInsertValues :: !SqliteInsertValuesSyntax
, SqliteInsertSyntax -> Maybe SqliteOnConflictSyntax
sqliteInsertOnConflict :: !(Maybe SqliteOnConflictSyntax)
}
newtype SqliteUpdateSyntax = SqliteUpdateSyntax { SqliteUpdateSyntax -> SqliteSyntax
fromSqliteUpdate :: SqliteSyntax }
newtype SqliteDeleteSyntax = SqliteDeleteSyntax { SqliteDeleteSyntax -> SqliteSyntax
fromSqliteDelete :: SqliteSyntax }
newtype SqliteSelectTableSyntax = SqliteSelectTableSyntax { SqliteSelectTableSyntax -> SqliteSyntax
fromSqliteSelectTable :: SqliteSyntax }
data SqliteExpressionSyntax
= SqliteExpressionSyntax SqliteSyntax
| SqliteExpressionDefault
deriving (Int -> SqliteExpressionSyntax -> ShowS
[SqliteExpressionSyntax] -> ShowS
SqliteExpressionSyntax -> String
(Int -> SqliteExpressionSyntax -> ShowS)
-> (SqliteExpressionSyntax -> String)
-> ([SqliteExpressionSyntax] -> ShowS)
-> Show SqliteExpressionSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqliteExpressionSyntax] -> ShowS
$cshowList :: [SqliteExpressionSyntax] -> ShowS
show :: SqliteExpressionSyntax -> String
$cshow :: SqliteExpressionSyntax -> String
showsPrec :: Int -> SqliteExpressionSyntax -> ShowS
$cshowsPrec :: Int -> SqliteExpressionSyntax -> ShowS
Show, SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool
(SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool)
-> (SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool)
-> Eq SqliteExpressionSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool
$c/= :: SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool
== :: SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool
$c== :: SqliteExpressionSyntax -> SqliteExpressionSyntax -> Bool
Eq, (forall x. SqliteExpressionSyntax -> Rep SqliteExpressionSyntax x)
-> (forall x.
Rep SqliteExpressionSyntax x -> SqliteExpressionSyntax)
-> Generic SqliteExpressionSyntax
forall x. Rep SqliteExpressionSyntax x -> SqliteExpressionSyntax
forall x. SqliteExpressionSyntax -> Rep SqliteExpressionSyntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SqliteExpressionSyntax x -> SqliteExpressionSyntax
$cfrom :: forall x. SqliteExpressionSyntax -> Rep SqliteExpressionSyntax x
Generic)
instance Hashable SqliteExpressionSyntax
newtype SqliteFromSyntax = SqliteFromSyntax { SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax :: SqliteSyntax }
newtype SqliteComparisonQuantifierSyntax = SqliteComparisonQuantifierSyntax { SqliteComparisonQuantifierSyntax -> SqliteSyntax
fromSqliteComparisonQuantifier :: SqliteSyntax }
newtype SqliteAggregationSetQuantifierSyntax = SqliteAggregationSetQuantifierSyntax { SqliteAggregationSetQuantifierSyntax -> SqliteSyntax
fromSqliteAggregationSetQuantifier :: SqliteSyntax }
newtype SqliteProjectionSyntax = SqliteProjectionSyntax { SqliteProjectionSyntax -> SqliteSyntax
fromSqliteProjection :: SqliteSyntax }
newtype SqliteGroupingSyntax = SqliteGroupingSyntax { SqliteGroupingSyntax -> SqliteSyntax
fromSqliteGrouping :: SqliteSyntax }
newtype SqliteOrderingSyntax = SqliteOrderingSyntax { SqliteOrderingSyntax -> SqliteSyntax
fromSqliteOrdering :: SqliteSyntax }
newtype SqliteValueSyntax = SqliteValueSyntax { SqliteValueSyntax -> SqliteSyntax
fromSqliteValue :: SqliteSyntax }
newtype SqliteTableSourceSyntax = SqliteTableSourceSyntax { SqliteTableSourceSyntax -> SqliteSyntax
fromSqliteTableSource :: SqliteSyntax }
newtype SqliteFieldNameSyntax = SqliteFieldNameSyntax { SqliteFieldNameSyntax -> SqliteSyntax
fromSqliteFieldNameSyntax :: SqliteSyntax }
data SqliteInsertValuesSyntax
= SqliteInsertExpressions [ [ SqliteExpressionSyntax ] ]
| SqliteInsertFromSql SqliteSelectSyntax
newtype SqliteCreateTableSyntax = SqliteCreateTableSyntax { SqliteCreateTableSyntax -> SqliteSyntax
fromSqliteCreateTable :: SqliteSyntax }
data SqliteTableOptionsSyntax = SqliteTableOptionsSyntax SqliteSyntax SqliteSyntax
data SqliteColumnSchemaSyntax
= SqliteColumnSchemaSyntax
{ SqliteColumnSchemaSyntax -> SqliteSyntax
fromSqliteColumnSchema :: SqliteSyntax
, SqliteColumnSchemaSyntax -> Bool
sqliteIsSerialColumn :: Bool }
deriving (Int -> SqliteColumnSchemaSyntax -> ShowS
[SqliteColumnSchemaSyntax] -> ShowS
SqliteColumnSchemaSyntax -> String
(Int -> SqliteColumnSchemaSyntax -> ShowS)
-> (SqliteColumnSchemaSyntax -> String)
-> ([SqliteColumnSchemaSyntax] -> ShowS)
-> Show SqliteColumnSchemaSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqliteColumnSchemaSyntax] -> ShowS
$cshowList :: [SqliteColumnSchemaSyntax] -> ShowS
show :: SqliteColumnSchemaSyntax -> String
$cshow :: SqliteColumnSchemaSyntax -> String
showsPrec :: Int -> SqliteColumnSchemaSyntax -> ShowS
$cshowsPrec :: Int -> SqliteColumnSchemaSyntax -> ShowS
Show, SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool
(SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool)
-> (SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool)
-> Eq SqliteColumnSchemaSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool
$c/= :: SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool
== :: SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool
$c== :: SqliteColumnSchemaSyntax -> SqliteColumnSchemaSyntax -> Bool
Eq, (forall x.
SqliteColumnSchemaSyntax -> Rep SqliteColumnSchemaSyntax x)
-> (forall x.
Rep SqliteColumnSchemaSyntax x -> SqliteColumnSchemaSyntax)
-> Generic SqliteColumnSchemaSyntax
forall x.
Rep SqliteColumnSchemaSyntax x -> SqliteColumnSchemaSyntax
forall x.
SqliteColumnSchemaSyntax -> Rep SqliteColumnSchemaSyntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SqliteColumnSchemaSyntax x -> SqliteColumnSchemaSyntax
$cfrom :: forall x.
SqliteColumnSchemaSyntax -> Rep SqliteColumnSchemaSyntax x
Generic)
instance Hashable SqliteColumnSchemaSyntax
instance Sql92DisplaySyntax SqliteColumnSchemaSyntax where
displaySyntax :: SqliteColumnSchemaSyntax -> String
displaySyntax = SqliteSyntax -> String
forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax (SqliteSyntax -> String)
-> (SqliteColumnSchemaSyntax -> SqliteSyntax)
-> SqliteColumnSchemaSyntax
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteColumnSchemaSyntax -> SqliteSyntax
fromSqliteColumnSchema
data SqliteDataTypeSyntax
= SqliteDataTypeSyntax
{ SqliteDataTypeSyntax -> SqliteSyntax
fromSqliteDataType :: SqliteSyntax
, SqliteDataTypeSyntax -> HsDataType
sqliteDataTypeToHs :: HsDataType
, SqliteDataTypeSyntax -> BeamSerializedDataType
sqliteDataTypeSerialized :: BeamSerializedDataType
, SqliteDataTypeSyntax -> Bool
sqliteDataTypeSerial :: Bool
} deriving (Int -> SqliteDataTypeSyntax -> ShowS
[SqliteDataTypeSyntax] -> ShowS
SqliteDataTypeSyntax -> String
(Int -> SqliteDataTypeSyntax -> ShowS)
-> (SqliteDataTypeSyntax -> String)
-> ([SqliteDataTypeSyntax] -> ShowS)
-> Show SqliteDataTypeSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqliteDataTypeSyntax] -> ShowS
$cshowList :: [SqliteDataTypeSyntax] -> ShowS
show :: SqliteDataTypeSyntax -> String
$cshow :: SqliteDataTypeSyntax -> String
showsPrec :: Int -> SqliteDataTypeSyntax -> ShowS
$cshowsPrec :: Int -> SqliteDataTypeSyntax -> ShowS
Show, SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool
(SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool)
-> (SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool)
-> Eq SqliteDataTypeSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool
$c/= :: SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool
== :: SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool
$c== :: SqliteDataTypeSyntax -> SqliteDataTypeSyntax -> Bool
Eq, (forall x. SqliteDataTypeSyntax -> Rep SqliteDataTypeSyntax x)
-> (forall x. Rep SqliteDataTypeSyntax x -> SqliteDataTypeSyntax)
-> Generic SqliteDataTypeSyntax
forall x. Rep SqliteDataTypeSyntax x -> SqliteDataTypeSyntax
forall x. SqliteDataTypeSyntax -> Rep SqliteDataTypeSyntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SqliteDataTypeSyntax x -> SqliteDataTypeSyntax
$cfrom :: forall x. SqliteDataTypeSyntax -> Rep SqliteDataTypeSyntax x
Generic)
instance Hashable SqliteDataTypeSyntax where
hashWithSalt :: Int -> SqliteDataTypeSyntax -> Int
hashWithSalt Int
salt (SqliteDataTypeSyntax SqliteSyntax
s HsDataType
_ BeamSerializedDataType
_ Bool
_) = Int -> SqliteSyntax -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt SqliteSyntax
s
instance Sql92DisplaySyntax SqliteDataTypeSyntax where
displaySyntax :: SqliteDataTypeSyntax -> String
displaySyntax = SqliteSyntax -> String
forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax (SqliteSyntax -> String)
-> (SqliteDataTypeSyntax -> SqliteSyntax)
-> SqliteDataTypeSyntax
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteDataTypeSyntax -> SqliteSyntax
fromSqliteDataType
data SqliteColumnConstraintDefinitionSyntax
= SqliteColumnConstraintDefinitionSyntax
{ SqliteColumnConstraintDefinitionSyntax -> SqliteSyntax
fromSqliteColumnConstraintDefinition :: SqliteSyntax
, SqliteColumnConstraintDefinitionSyntax
-> BeamSerializedConstraintDefinition
sqliteColumnConstraintDefinitionSerialized :: BeamSerializedConstraintDefinition
} deriving (Int -> SqliteColumnConstraintDefinitionSyntax -> ShowS
[SqliteColumnConstraintDefinitionSyntax] -> ShowS
SqliteColumnConstraintDefinitionSyntax -> String
(Int -> SqliteColumnConstraintDefinitionSyntax -> ShowS)
-> (SqliteColumnConstraintDefinitionSyntax -> String)
-> ([SqliteColumnConstraintDefinitionSyntax] -> ShowS)
-> Show SqliteColumnConstraintDefinitionSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqliteColumnConstraintDefinitionSyntax] -> ShowS
$cshowList :: [SqliteColumnConstraintDefinitionSyntax] -> ShowS
show :: SqliteColumnConstraintDefinitionSyntax -> String
$cshow :: SqliteColumnConstraintDefinitionSyntax -> String
showsPrec :: Int -> SqliteColumnConstraintDefinitionSyntax -> ShowS
$cshowsPrec :: Int -> SqliteColumnConstraintDefinitionSyntax -> ShowS
Show, SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool
(SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool)
-> (SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool)
-> Eq SqliteColumnConstraintDefinitionSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool
$c/= :: SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool
== :: SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool
$c== :: SqliteColumnConstraintDefinitionSyntax
-> SqliteColumnConstraintDefinitionSyntax -> Bool
Eq)
instance Hashable SqliteColumnConstraintDefinitionSyntax where
hashWithSalt :: Int -> SqliteColumnConstraintDefinitionSyntax -> Int
hashWithSalt Int
salt (SqliteColumnConstraintDefinitionSyntax SqliteSyntax
s BeamSerializedConstraintDefinition
_) = Int -> SqliteSyntax -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt SqliteSyntax
s
instance Sql92DisplaySyntax SqliteColumnConstraintDefinitionSyntax where
displaySyntax :: SqliteColumnConstraintDefinitionSyntax -> String
displaySyntax = SqliteSyntax -> String
forall syntax. Sql92DisplaySyntax syntax => syntax -> String
displaySyntax (SqliteSyntax -> String)
-> (SqliteColumnConstraintDefinitionSyntax -> SqliteSyntax)
-> SqliteColumnConstraintDefinitionSyntax
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteColumnConstraintDefinitionSyntax -> SqliteSyntax
fromSqliteColumnConstraintDefinition
data SqliteColumnConstraintSyntax
= SqliteColumnConstraintSyntax
{ SqliteColumnConstraintSyntax
-> SqlConstraintAttributesBuilder -> SqliteSyntax
fromSqliteColumnConstraint :: SqlConstraintAttributesBuilder -> SqliteSyntax
, SqliteColumnConstraintSyntax -> BeamSerializedConstraint
sqliteColumnConstraintSerialized :: BeamSerializedConstraint }
data SqliteTableConstraintSyntax
= SqliteTableConstraintSyntax
{ SqliteTableConstraintSyntax -> SqliteSyntax
fromSqliteTableConstraint :: SqliteSyntax
, SqliteTableConstraintSyntax -> Maybe [Text]
sqliteTableConstraintPrimaryKey :: Maybe [ T.Text ] }
data SqliteMatchTypeSyntax
= SqliteMatchTypeSyntax
{ SqliteMatchTypeSyntax -> SqliteSyntax
fromSqliteMatchType :: SqliteSyntax
, SqliteMatchTypeSyntax -> BeamSerializedMatchType
sqliteMatchTypeSerialized :: BeamSerializedMatchType }
data SqliteReferentialActionSyntax
= SqliteReferentialActionSyntax
{ SqliteReferentialActionSyntax -> SqliteSyntax
fromSqliteReferentialAction :: SqliteSyntax
, SqliteReferentialActionSyntax -> BeamSerializedReferentialAction
sqliteReferentialActionSerialized :: BeamSerializedReferentialAction }
newtype SqliteAlterTableSyntax = SqliteAlterTableSyntax { SqliteAlterTableSyntax -> SqliteSyntax
fromSqliteAlterTable :: SqliteSyntax }
newtype SqliteAlterTableActionSyntax = SqliteAlterTableActionSyntax { SqliteAlterTableActionSyntax -> Maybe SqliteSyntax
fromSqliteAlterTableAction :: Maybe SqliteSyntax }
newtype SqliteAlterColumnActionSyntax = SqliteAlterColumnActionSyntax { SqliteAlterColumnActionSyntax -> Maybe SqliteSyntax
fromSqliteAlterColumnAction :: Maybe SqliteSyntax }
newtype SqliteDropTableSyntax = SqliteDropTableSyntax { SqliteDropTableSyntax -> SqliteSyntax
fromSqliteDropTable :: SqliteSyntax }
newtype SqliteTableNameSyntax = SqliteTableNameSyntax { SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName :: SqliteSyntax }
fromSqliteExpression :: SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression :: SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression (SqliteExpressionSyntax SqliteSyntax
s) = SqliteSyntax
s
fromSqliteExpression SqliteExpressionSyntax
SqliteExpressionDefault = ByteString -> SqliteSyntax
emit ByteString
"NULL /* DEFAULT */"
sqliteExpressionSerialized :: SqliteExpressionSyntax -> BeamSerializedExpression
sqliteExpressionSerialized :: SqliteExpressionSyntax -> BeamSerializedExpression
sqliteExpressionSerialized = Text -> BeamSerializedExpression
BeamSerializedExpression (Text -> BeamSerializedExpression)
-> (SqliteExpressionSyntax -> Text)
-> SqliteExpressionSyntax
-> BeamSerializedExpression
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
TE.decodeUtf8 (ByteString -> Text)
-> (SqliteExpressionSyntax -> ByteString)
-> SqliteExpressionSyntax
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BL.toStrict (ByteString -> ByteString)
-> (SqliteExpressionSyntax -> ByteString)
-> SqliteExpressionSyntax
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
SqliteSyntax -> ByteString
sqliteRenderSyntaxScript (SqliteSyntax -> ByteString)
-> (SqliteExpressionSyntax -> SqliteSyntax)
-> SqliteExpressionSyntax
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression
formatSqliteInsert :: SqliteTableNameSyntax -> [ T.Text ] -> SqliteInsertValuesSyntax -> SqliteSyntax
formatSqliteInsert :: SqliteTableNameSyntax
-> [Text] -> SqliteInsertValuesSyntax -> SqliteSyntax
formatSqliteInsert SqliteTableNameSyntax
tblNm [Text]
fields SqliteInsertValuesSyntax
values =
SqliteTableNameSyntax
-> [Text]
-> SqliteInsertValuesSyntax
-> Maybe SqliteOnConflictSyntax
-> SqliteSyntax
formatSqliteInsertOnConflict SqliteTableNameSyntax
tblNm [Text]
fields SqliteInsertValuesSyntax
values Maybe SqliteOnConflictSyntax
forall a. Maybe a
Nothing
formatSqliteInsertOnConflict :: SqliteTableNameSyntax -> [ T.Text ] -> SqliteInsertValuesSyntax -> Maybe SqliteOnConflictSyntax -> SqliteSyntax
formatSqliteInsertOnConflict :: SqliteTableNameSyntax
-> [Text]
-> SqliteInsertValuesSyntax
-> Maybe SqliteOnConflictSyntax
-> SqliteSyntax
formatSqliteInsertOnConflict SqliteTableNameSyntax
tblNm [Text]
fields SqliteInsertValuesSyntax
values Maybe SqliteOnConflictSyntax
onConflict = [SqliteSyntax] -> SqliteSyntax
forall a. Monoid a => [a] -> a
mconcat
[ ByteString -> SqliteSyntax
emit ByteString
"INSERT INTO "
, SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName SqliteTableNameSyntax
tblNm
, if [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
fields
then SqliteSyntax
forall a. Monoid a => a
mempty
else SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((Text -> SqliteSyntax) -> [Text] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SqliteSyntax
quotedIdentifier [Text]
fields))
, ByteString -> SqliteSyntax
emit ByteString
" "
, case SqliteInsertValuesSyntax
values of
SqliteInsertFromSql (SqliteSelectSyntax SqliteSyntax
select) -> SqliteSyntax
select
SqliteInsertExpressions [[]] -> ByteString -> SqliteSyntax
emit ByteString
"DEFAULT VALUES"
SqliteInsertExpressions [[SqliteExpressionSyntax]]
es ->
ByteString -> SqliteSyntax
emit ByteString
"VALUES " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> [SqliteSyntax] -> SqliteSyntax
commas (([SqliteExpressionSyntax] -> SqliteSyntax)
-> [[SqliteExpressionSyntax]] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map (\[SqliteExpressionSyntax]
row -> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
row)) ) [[SqliteExpressionSyntax]]
es)
, SqliteSyntax
-> (SqliteOnConflictSyntax -> SqliteSyntax)
-> Maybe SqliteOnConflictSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty ((ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) (SqliteSyntax -> SqliteSyntax)
-> (SqliteOnConflictSyntax -> SqliteSyntax)
-> SqliteOnConflictSyntax
-> SqliteSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteOnConflictSyntax -> SqliteSyntax
fromSqliteOnConflict) Maybe SqliteOnConflictSyntax
onConflict
]
instance IsSql92Syntax SqliteCommandSyntax where
type Sql92SelectSyntax SqliteCommandSyntax = SqliteSelectSyntax
type Sql92InsertSyntax SqliteCommandSyntax = SqliteInsertSyntax
type Sql92UpdateSyntax SqliteCommandSyntax = SqliteUpdateSyntax
type Sql92DeleteSyntax SqliteCommandSyntax = SqliteDeleteSyntax
selectCmd :: Sql92SelectSyntax SqliteCommandSyntax -> SqliteCommandSyntax
selectCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteSelectSyntax -> SqliteSyntax)
-> SqliteSelectSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect
insertCmd :: Sql92InsertSyntax SqliteCommandSyntax -> SqliteCommandSyntax
insertCmd = Sql92InsertSyntax SqliteCommandSyntax -> SqliteCommandSyntax
SqliteInsertSyntax -> SqliteCommandSyntax
SqliteCommandInsert
updateCmd :: Sql92UpdateSyntax SqliteCommandSyntax -> SqliteCommandSyntax
updateCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteUpdateSyntax -> SqliteSyntax)
-> SqliteUpdateSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteUpdateSyntax -> SqliteSyntax
fromSqliteUpdate
deleteCmd :: Sql92DeleteSyntax SqliteCommandSyntax -> SqliteCommandSyntax
deleteCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteDeleteSyntax -> SqliteSyntax)
-> SqliteDeleteSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteDeleteSyntax -> SqliteSyntax
fromSqliteDelete
instance IsSql92DdlCommandSyntax SqliteCommandSyntax where
type Sql92DdlCommandCreateTableSyntax SqliteCommandSyntax = SqliteCreateTableSyntax
type Sql92DdlCommandAlterTableSyntax SqliteCommandSyntax = SqliteAlterTableSyntax
type Sql92DdlCommandDropTableSyntax SqliteCommandSyntax = SqliteDropTableSyntax
createTableCmd :: Sql92DdlCommandCreateTableSyntax SqliteCommandSyntax
-> SqliteCommandSyntax
createTableCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteCreateTableSyntax -> SqliteSyntax)
-> SqliteCreateTableSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteCreateTableSyntax -> SqliteSyntax
fromSqliteCreateTable
alterTableCmd :: Sql92DdlCommandAlterTableSyntax SqliteCommandSyntax
-> SqliteCommandSyntax
alterTableCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteAlterTableSyntax -> SqliteSyntax)
-> SqliteAlterTableSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteAlterTableSyntax -> SqliteSyntax
fromSqliteAlterTable
dropTableCmd :: Sql92DdlCommandDropTableSyntax SqliteCommandSyntax
-> SqliteCommandSyntax
dropTableCmd = SqliteSyntax -> SqliteCommandSyntax
SqliteCommandSyntax (SqliteSyntax -> SqliteCommandSyntax)
-> (SqliteDropTableSyntax -> SqliteSyntax)
-> SqliteDropTableSyntax
-> SqliteCommandSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteDropTableSyntax -> SqliteSyntax
fromSqliteDropTable
instance IsSql92TableNameSyntax SqliteTableNameSyntax where
tableName :: Maybe Text -> Text -> SqliteTableNameSyntax
tableName Maybe Text
Nothing Text
tbl = SqliteSyntax -> SqliteTableNameSyntax
SqliteTableNameSyntax (Text -> SqliteSyntax
quotedIdentifier Text
tbl)
tableName (Just Text
sch) Text
tbl = SqliteSyntax -> SqliteTableNameSyntax
SqliteTableNameSyntax (Text -> SqliteSyntax
quotedIdentifier Text
sch SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
"." SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
tbl)
instance IsSql92DropTableSyntax SqliteDropTableSyntax where
type Sql92DropTableTableNameSyntax SqliteDropTableSyntax = SqliteTableNameSyntax
dropTableSyntax :: Sql92DropTableTableNameSyntax SqliteDropTableSyntax
-> SqliteDropTableSyntax
dropTableSyntax Sql92DropTableTableNameSyntax SqliteDropTableSyntax
nm = SqliteSyntax -> SqliteDropTableSyntax
SqliteDropTableSyntax (ByteString -> SqliteSyntax
emit ByteString
"DROP TABLE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName Sql92DropTableTableNameSyntax SqliteDropTableSyntax
SqliteTableNameSyntax
nm)
instance IsSql92AlterTableSyntax SqliteAlterTableSyntax where
type Sql92AlterTableAlterTableActionSyntax SqliteAlterTableSyntax = SqliteAlterTableActionSyntax
type Sql92AlterTableTableNameSyntax SqliteAlterTableSyntax = SqliteTableNameSyntax
alterTableSyntax :: Sql92AlterTableTableNameSyntax SqliteAlterTableSyntax
-> Sql92AlterTableAlterTableActionSyntax SqliteAlterTableSyntax
-> SqliteAlterTableSyntax
alterTableSyntax Sql92AlterTableTableNameSyntax SqliteAlterTableSyntax
nm Sql92AlterTableAlterTableActionSyntax SqliteAlterTableSyntax
action =
SqliteSyntax -> SqliteAlterTableSyntax
SqliteAlterTableSyntax (SqliteSyntax -> SqliteAlterTableSyntax)
-> SqliteSyntax -> SqliteAlterTableSyntax
forall a b. (a -> b) -> a -> b
$
case SqliteAlterTableActionSyntax -> Maybe SqliteSyntax
fromSqliteAlterTableAction Sql92AlterTableAlterTableActionSyntax SqliteAlterTableSyntax
SqliteAlterTableActionSyntax
action of
Just SqliteSyntax
alterTable ->
ByteString -> SqliteSyntax
emit ByteString
"ALTER TABLE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName Sql92AlterTableTableNameSyntax SqliteAlterTableSyntax
SqliteTableNameSyntax
nm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax
alterTable
Maybe SqliteSyntax
Nothing ->
ByteString -> SqliteSyntax
emit ByteString
"SELECT 1"
instance IsSql92AlterTableActionSyntax SqliteAlterTableActionSyntax where
type Sql92AlterTableAlterColumnActionSyntax SqliteAlterTableActionSyntax = SqliteAlterColumnActionSyntax
type Sql92AlterTableColumnSchemaSyntax SqliteAlterTableActionSyntax = SqliteColumnSchemaSyntax
alterColumnSyntax :: Text
-> Sql92AlterTableAlterColumnActionSyntax
SqliteAlterTableActionSyntax
-> SqliteAlterTableActionSyntax
alterColumnSyntax Text
columnNm Sql92AlterTableAlterColumnActionSyntax SqliteAlterTableActionSyntax
columnAction =
Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
SqliteAlterTableActionSyntax (Maybe SqliteSyntax -> SqliteAlterTableActionSyntax)
-> Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
forall a b. (a -> b) -> a -> b
$
case SqliteAlterColumnActionSyntax -> Maybe SqliteSyntax
fromSqliteAlterColumnAction Sql92AlterTableAlterColumnActionSyntax SqliteAlterTableActionSyntax
SqliteAlterColumnActionSyntax
columnAction of
Maybe SqliteSyntax
Nothing -> Maybe SqliteSyntax
forall a. Maybe a
Nothing
Just SqliteSyntax
columnAction ->
SqliteSyntax -> Maybe SqliteSyntax
forall a. a -> Maybe a
Just (ByteString -> SqliteSyntax
emit ByteString
"ALTER COLUMN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
columnNm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax
columnAction)
addColumnSyntax :: Text
-> Sql92AlterTableColumnSchemaSyntax SqliteAlterTableActionSyntax
-> SqliteAlterTableActionSyntax
addColumnSyntax Text
columnNm Sql92AlterTableColumnSchemaSyntax SqliteAlterTableActionSyntax
schema =
Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
SqliteAlterTableActionSyntax (Maybe SqliteSyntax -> SqliteAlterTableActionSyntax)
-> (SqliteSyntax -> Maybe SqliteSyntax)
-> SqliteSyntax
-> SqliteAlterTableActionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> Maybe SqliteSyntax
forall a. a -> Maybe a
Just (SqliteSyntax -> SqliteAlterTableActionSyntax)
-> SqliteSyntax -> SqliteAlterTableActionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"ADD COLUMN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
columnNm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteColumnSchemaSyntax -> SqliteSyntax
fromSqliteColumnSchema Sql92AlterTableColumnSchemaSyntax SqliteAlterTableActionSyntax
SqliteColumnSchemaSyntax
schema
dropColumnSyntax :: Text -> SqliteAlterTableActionSyntax
dropColumnSyntax Text
_ = Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
SqliteAlterTableActionSyntax Maybe SqliteSyntax
forall a. Maybe a
Nothing
renameTableToSyntax :: Text -> SqliteAlterTableActionSyntax
renameTableToSyntax Text
newNm =
Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
SqliteAlterTableActionSyntax (Maybe SqliteSyntax -> SqliteAlterTableActionSyntax)
-> (SqliteSyntax -> Maybe SqliteSyntax)
-> SqliteSyntax
-> SqliteAlterTableActionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> Maybe SqliteSyntax
forall a. a -> Maybe a
Just (SqliteSyntax -> SqliteAlterTableActionSyntax)
-> SqliteSyntax -> SqliteAlterTableActionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"RENAME TO " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
newNm
renameColumnToSyntax :: Text -> Text -> SqliteAlterTableActionSyntax
renameColumnToSyntax Text
oldNm Text
newNm =
Maybe SqliteSyntax -> SqliteAlterTableActionSyntax
SqliteAlterTableActionSyntax (Maybe SqliteSyntax -> SqliteAlterTableActionSyntax)
-> (SqliteSyntax -> Maybe SqliteSyntax)
-> SqliteSyntax
-> SqliteAlterTableActionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> Maybe SqliteSyntax
forall a. a -> Maybe a
Just (SqliteSyntax -> SqliteAlterTableActionSyntax)
-> SqliteSyntax -> SqliteAlterTableActionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"RENAME COLUMN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
oldNm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
" TO " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
newNm
instance IsSql92AlterColumnActionSyntax SqliteAlterColumnActionSyntax where
setNotNullSyntax :: SqliteAlterColumnActionSyntax
setNotNullSyntax = Maybe SqliteSyntax -> SqliteAlterColumnActionSyntax
SqliteAlterColumnActionSyntax Maybe SqliteSyntax
forall a. Maybe a
Nothing
setNullSyntax :: SqliteAlterColumnActionSyntax
setNullSyntax = Maybe SqliteSyntax -> SqliteAlterColumnActionSyntax
SqliteAlterColumnActionSyntax Maybe SqliteSyntax
forall a. Maybe a
Nothing
instance IsSql92ColumnSchemaSyntax SqliteColumnSchemaSyntax where
type Sql92ColumnSchemaColumnTypeSyntax SqliteColumnSchemaSyntax = SqliteDataTypeSyntax
type Sql92ColumnSchemaExpressionSyntax SqliteColumnSchemaSyntax = SqliteExpressionSyntax
type Sql92ColumnSchemaColumnConstraintDefinitionSyntax SqliteColumnSchemaSyntax = SqliteColumnConstraintDefinitionSyntax
columnSchemaSyntax :: Sql92ColumnSchemaColumnTypeSyntax SqliteColumnSchemaSyntax
-> Maybe
(Sql92ColumnSchemaExpressionSyntax SqliteColumnSchemaSyntax)
-> [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
SqliteColumnSchemaSyntax]
-> Maybe Text
-> SqliteColumnSchemaSyntax
columnSchemaSyntax Sql92ColumnSchemaColumnTypeSyntax SqliteColumnSchemaSyntax
ty Maybe (Sql92ColumnSchemaExpressionSyntax SqliteColumnSchemaSyntax)
defVal [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
SqliteColumnSchemaSyntax]
constraints Maybe Text
collation =
SqliteSyntax -> Bool -> SqliteColumnSchemaSyntax
SqliteColumnSchemaSyntax
(SqliteDataTypeSyntax -> SqliteSyntax
fromSqliteDataType Sql92ColumnSchemaColumnTypeSyntax SqliteColumnSchemaSyntax
SqliteDataTypeSyntax
ty SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteExpressionSyntax -> SqliteSyntax)
-> Maybe SqliteExpressionSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteExpressionSyntax
defVal -> ByteString -> SqliteSyntax
emit ByteString
" DEFAULT " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
defVal)) Maybe (Sql92ColumnSchemaExpressionSyntax SqliteColumnSchemaSyntax)
Maybe SqliteExpressionSyntax
defVal SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
(SqliteColumnConstraintDefinitionSyntax -> SqliteSyntax)
-> [SqliteColumnConstraintDefinitionSyntax] -> SqliteSyntax
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\SqliteColumnConstraintDefinitionSyntax
constraint -> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteColumnConstraintDefinitionSyntax -> SqliteSyntax
fromSqliteColumnConstraintDefinition SqliteColumnConstraintDefinitionSyntax
constraint SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ") [Sql92ColumnSchemaColumnConstraintDefinitionSyntax
SqliteColumnSchemaSyntax]
[SqliteColumnConstraintDefinitionSyntax]
constraints SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (Text -> SqliteSyntax) -> Maybe Text -> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\Text
c -> ByteString -> SqliteSyntax
emit ByteString
" COLLATE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
c) Maybe Text
collation)
(if SqliteDataTypeSyntax -> Bool
sqliteDataTypeSerial Sql92ColumnSchemaColumnTypeSyntax SqliteColumnSchemaSyntax
SqliteDataTypeSyntax
ty then Bool
True else Bool
False)
instance IsSql92ColumnConstraintDefinitionSyntax SqliteColumnConstraintDefinitionSyntax where
type Sql92ColumnConstraintDefinitionConstraintSyntax SqliteColumnConstraintDefinitionSyntax = SqliteColumnConstraintSyntax
type Sql92ColumnConstraintDefinitionAttributesSyntax SqliteColumnConstraintDefinitionSyntax = SqlConstraintAttributesBuilder
constraintDefinitionSyntax :: Maybe Text
-> Sql92ColumnConstraintDefinitionConstraintSyntax
SqliteColumnConstraintDefinitionSyntax
-> Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
SqliteColumnConstraintDefinitionSyntax)
-> SqliteColumnConstraintDefinitionSyntax
constraintDefinitionSyntax Maybe Text
nm Sql92ColumnConstraintDefinitionConstraintSyntax
SqliteColumnConstraintDefinitionSyntax
def Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
SqliteColumnConstraintDefinitionSyntax)
attrs =
SqliteSyntax
-> BeamSerializedConstraintDefinition
-> SqliteColumnConstraintDefinitionSyntax
SqliteColumnConstraintDefinitionSyntax
(SqliteSyntax
-> (Text -> SqliteSyntax) -> Maybe Text -> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\Text
nm' -> ByteString -> SqliteSyntax
emit ByteString
"CONSTRAINT " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
nm') Maybe Text
nm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteColumnConstraintSyntax
-> SqlConstraintAttributesBuilder -> SqliteSyntax
fromSqliteColumnConstraint Sql92ColumnConstraintDefinitionConstraintSyntax
SqliteColumnConstraintDefinitionSyntax
SqliteColumnConstraintSyntax
def (SqlConstraintAttributesBuilder
-> Maybe SqlConstraintAttributesBuilder
-> SqlConstraintAttributesBuilder
forall a. a -> Maybe a -> a
fromMaybe SqlConstraintAttributesBuilder
forall a. Monoid a => a
mempty Maybe SqlConstraintAttributesBuilder
Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
SqliteColumnConstraintDefinitionSyntax)
attrs))
(Maybe Text
-> Sql92ColumnConstraintDefinitionConstraintSyntax
BeamSerializedConstraintDefinition
-> Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
BeamSerializedConstraintDefinition)
-> BeamSerializedConstraintDefinition
forall constraint.
IsSql92ColumnConstraintDefinitionSyntax constraint =>
Maybe Text
-> Sql92ColumnConstraintDefinitionConstraintSyntax constraint
-> Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax constraint)
-> constraint
constraintDefinitionSyntax Maybe Text
nm (SqliteColumnConstraintSyntax -> BeamSerializedConstraint
sqliteColumnConstraintSerialized Sql92ColumnConstraintDefinitionConstraintSyntax
SqliteColumnConstraintDefinitionSyntax
SqliteColumnConstraintSyntax
def)
((SqlConstraintAttributesBuilder
-> BeamSerializedConstraintAttributes)
-> Maybe SqlConstraintAttributesBuilder
-> Maybe BeamSerializedConstraintAttributes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqlConstraintAttributesBuilder
-> BeamSerializedConstraintAttributes
sqlConstraintAttributesSerialized Maybe SqlConstraintAttributesBuilder
Maybe
(Sql92ColumnConstraintDefinitionAttributesSyntax
SqliteColumnConstraintDefinitionSyntax)
attrs))
instance Sql92SerializableConstraintDefinitionSyntax SqliteColumnConstraintDefinitionSyntax where
serializeConstraint :: SqliteColumnConstraintDefinitionSyntax -> Value
serializeConstraint = BeamSerializedConstraintDefinition -> Value
fromBeamSerializedConstraintDefinition (BeamSerializedConstraintDefinition -> Value)
-> (SqliteColumnConstraintDefinitionSyntax
-> BeamSerializedConstraintDefinition)
-> SqliteColumnConstraintDefinitionSyntax
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteColumnConstraintDefinitionSyntax
-> BeamSerializedConstraintDefinition
sqliteColumnConstraintDefinitionSerialized
instance IsSql92ColumnConstraintSyntax SqliteColumnConstraintSyntax where
type Sql92ColumnConstraintMatchTypeSyntax SqliteColumnConstraintSyntax = SqliteMatchTypeSyntax
type Sql92ColumnConstraintReferentialActionSyntax SqliteColumnConstraintSyntax = SqliteReferentialActionSyntax
type Sql92ColumnConstraintExpressionSyntax SqliteColumnConstraintSyntax = SqliteExpressionSyntax
notNullConstraintSyntax :: SqliteColumnConstraintSyntax
notNullConstraintSyntax = (SqlConstraintAttributesBuilder -> SqliteSyntax)
-> BeamSerializedConstraint -> SqliteColumnConstraintSyntax
SqliteColumnConstraintSyntax (\SqlConstraintAttributesBuilder
_ -> ByteString -> SqliteSyntax
emit ByteString
"NOT NULL") BeamSerializedConstraint
forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
notNullConstraintSyntax
uniqueColumnConstraintSyntax :: SqliteColumnConstraintSyntax
uniqueColumnConstraintSyntax = (SqlConstraintAttributesBuilder -> SqliteSyntax)
-> BeamSerializedConstraint -> SqliteColumnConstraintSyntax
SqliteColumnConstraintSyntax (\SqlConstraintAttributesBuilder
_ -> ByteString -> SqliteSyntax
emit ByteString
"UNIQUE") BeamSerializedConstraint
forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
uniqueColumnConstraintSyntax
primaryKeyColumnConstraintSyntax :: SqliteColumnConstraintSyntax
primaryKeyColumnConstraintSyntax = (SqlConstraintAttributesBuilder -> SqliteSyntax)
-> BeamSerializedConstraint -> SqliteColumnConstraintSyntax
SqliteColumnConstraintSyntax (\SqlConstraintAttributesBuilder
_ -> ByteString -> SqliteSyntax
emit ByteString
"PRIMARY KEY") BeamSerializedConstraint
forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
constraint
primaryKeyColumnConstraintSyntax
checkColumnConstraintSyntax :: Sql92ColumnConstraintExpressionSyntax SqliteColumnConstraintSyntax
-> SqliteColumnConstraintSyntax
checkColumnConstraintSyntax Sql92ColumnConstraintExpressionSyntax SqliteColumnConstraintSyntax
expr =
(SqlConstraintAttributesBuilder -> SqliteSyntax)
-> BeamSerializedConstraint -> SqliteColumnConstraintSyntax
SqliteColumnConstraintSyntax (\SqlConstraintAttributesBuilder
_ -> ByteString -> SqliteSyntax
emit ByteString
"CHECK " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression Sql92ColumnConstraintExpressionSyntax SqliteColumnConstraintSyntax
SqliteExpressionSyntax
expr))
(Sql92ColumnConstraintExpressionSyntax BeamSerializedConstraint
-> BeamSerializedConstraint
forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
Sql92ColumnConstraintExpressionSyntax constraint -> constraint
checkColumnConstraintSyntax (SqliteExpressionSyntax -> BeamSerializedExpression
sqliteExpressionSerialized Sql92ColumnConstraintExpressionSyntax SqliteColumnConstraintSyntax
SqliteExpressionSyntax
expr))
referencesConstraintSyntax :: Text
-> [Text]
-> Maybe
(Sql92ColumnConstraintMatchTypeSyntax SqliteColumnConstraintSyntax)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
-> SqliteColumnConstraintSyntax
referencesConstraintSyntax Text
tbl [Text]
fields Maybe
(Sql92ColumnConstraintMatchTypeSyntax SqliteColumnConstraintSyntax)
matchType Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
onUpdate Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
onDelete =
(SqlConstraintAttributesBuilder -> SqliteSyntax)
-> BeamSerializedConstraint -> SqliteColumnConstraintSyntax
SqliteColumnConstraintSyntax SqlConstraintAttributesBuilder -> SqliteSyntax
sqliteConstraint
(Text
-> [Text]
-> Maybe
(Sql92ColumnConstraintMatchTypeSyntax BeamSerializedConstraint)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
BeamSerializedConstraint)
-> Maybe
(Sql92ColumnConstraintReferentialActionSyntax
BeamSerializedConstraint)
-> BeamSerializedConstraint
forall constraint.
IsSql92ColumnConstraintSyntax constraint =>
Text
-> [Text]
-> Maybe (Sql92ColumnConstraintMatchTypeSyntax constraint)
-> Maybe (Sql92ColumnConstraintReferentialActionSyntax constraint)
-> Maybe (Sql92ColumnConstraintReferentialActionSyntax constraint)
-> constraint
referencesConstraintSyntax Text
tbl [Text]
fields ((SqliteMatchTypeSyntax -> BeamSerializedMatchType)
-> Maybe SqliteMatchTypeSyntax -> Maybe BeamSerializedMatchType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqliteMatchTypeSyntax -> BeamSerializedMatchType
sqliteMatchTypeSerialized Maybe
(Sql92ColumnConstraintMatchTypeSyntax SqliteColumnConstraintSyntax)
Maybe SqliteMatchTypeSyntax
matchType)
((SqliteReferentialActionSyntax -> BeamSerializedReferentialAction)
-> Maybe SqliteReferentialActionSyntax
-> Maybe BeamSerializedReferentialAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqliteReferentialActionSyntax -> BeamSerializedReferentialAction
sqliteReferentialActionSerialized Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
Maybe SqliteReferentialActionSyntax
onUpdate)
((SqliteReferentialActionSyntax -> BeamSerializedReferentialAction)
-> Maybe SqliteReferentialActionSyntax
-> Maybe BeamSerializedReferentialAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqliteReferentialActionSyntax -> BeamSerializedReferentialAction
sqliteReferentialActionSerialized Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
Maybe SqliteReferentialActionSyntax
onDelete))
where
sqliteConstraint :: SqlConstraintAttributesBuilder -> SqliteSyntax
sqliteConstraint (SqlConstraintAttributesBuilder Maybe ConstraintAttributeTiming
atTime Maybe Bool
deferrable) =
ByteString -> SqliteSyntax
emit ByteString
"REFERENCES " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
tbl SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((Text -> SqliteSyntax) -> [Text] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SqliteSyntax
quotedIdentifier [Text]
fields)) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteMatchTypeSyntax -> SqliteSyntax)
-> Maybe SqliteMatchTypeSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteMatchTypeSyntax
matchType' -> ByteString -> SqliteSyntax
emit ByteString
" MATCH " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteMatchTypeSyntax -> SqliteSyntax
fromSqliteMatchType SqliteMatchTypeSyntax
matchType') Maybe
(Sql92ColumnConstraintMatchTypeSyntax SqliteColumnConstraintSyntax)
Maybe SqliteMatchTypeSyntax
matchType SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteReferentialActionSyntax -> SqliteSyntax)
-> Maybe SqliteReferentialActionSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteReferentialActionSyntax
onUpdate' -> ByteString -> SqliteSyntax
emit ByteString
" ON UPDATE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteReferentialActionSyntax -> SqliteSyntax
fromSqliteReferentialAction SqliteReferentialActionSyntax
onUpdate') Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
Maybe SqliteReferentialActionSyntax
onUpdate SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteReferentialActionSyntax -> SqliteSyntax)
-> Maybe SqliteReferentialActionSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteReferentialActionSyntax
onDelete' -> ByteString -> SqliteSyntax
emit ByteString
" ON DELETE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteReferentialActionSyntax -> SqliteSyntax
fromSqliteReferentialAction SqliteReferentialActionSyntax
onDelete') Maybe
(Sql92ColumnConstraintReferentialActionSyntax
SqliteColumnConstraintSyntax)
Maybe SqliteReferentialActionSyntax
onDelete SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
case (Maybe Bool
deferrable, Maybe ConstraintAttributeTiming
atTime) of
(Maybe Bool
_, Just ConstraintAttributeTiming
atTime) ->
let deferrable' :: Bool
deferrable' = Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False Maybe Bool
deferrable
in (if Bool
deferrable' then ByteString -> SqliteSyntax
emit ByteString
" DEFERRABLE " else ByteString -> SqliteSyntax
emit ByteString
" NOT DEFERRABLE ") SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
case ConstraintAttributeTiming
atTime of
ConstraintAttributeTiming
InitiallyDeferred -> ByteString -> SqliteSyntax
emit ByteString
"INITIALLY DEFERRED"
ConstraintAttributeTiming
InitiallyImmediate -> ByteString -> SqliteSyntax
emit ByteString
"INITIALLY IMMEDIATE"
(Just Bool
deferrable', Maybe ConstraintAttributeTiming
_) ->
if Bool
deferrable' then ByteString -> SqliteSyntax
emit ByteString
" DEFERRABLE" else ByteString -> SqliteSyntax
emit ByteString
" NOT DEFERRABLE"
(Maybe Bool, Maybe ConstraintAttributeTiming)
_ -> SqliteSyntax
forall a. Monoid a => a
mempty
instance IsSql92MatchTypeSyntax SqliteMatchTypeSyntax where
fullMatchSyntax :: SqliteMatchTypeSyntax
fullMatchSyntax = SqliteSyntax -> BeamSerializedMatchType -> SqliteMatchTypeSyntax
SqliteMatchTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"FULL") BeamSerializedMatchType
forall match. IsSql92MatchTypeSyntax match => match
fullMatchSyntax
partialMatchSyntax :: SqliteMatchTypeSyntax
partialMatchSyntax = SqliteSyntax -> BeamSerializedMatchType -> SqliteMatchTypeSyntax
SqliteMatchTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"PARTIAL") BeamSerializedMatchType
forall match. IsSql92MatchTypeSyntax match => match
partialMatchSyntax
instance IsSql92ReferentialActionSyntax SqliteReferentialActionSyntax where
referentialActionCascadeSyntax :: SqliteReferentialActionSyntax
referentialActionCascadeSyntax = SqliteSyntax
-> BeamSerializedReferentialAction -> SqliteReferentialActionSyntax
SqliteReferentialActionSyntax (ByteString -> SqliteSyntax
emit ByteString
"CASCADE") BeamSerializedReferentialAction
forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionCascadeSyntax
referentialActionSetNullSyntax :: SqliteReferentialActionSyntax
referentialActionSetNullSyntax = SqliteSyntax
-> BeamSerializedReferentialAction -> SqliteReferentialActionSyntax
SqliteReferentialActionSyntax (ByteString -> SqliteSyntax
emit ByteString
"SET NULL") BeamSerializedReferentialAction
forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionSetNullSyntax
referentialActionSetDefaultSyntax :: SqliteReferentialActionSyntax
referentialActionSetDefaultSyntax = SqliteSyntax
-> BeamSerializedReferentialAction -> SqliteReferentialActionSyntax
SqliteReferentialActionSyntax (ByteString -> SqliteSyntax
emit ByteString
"SET DEFAULT") BeamSerializedReferentialAction
forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionSetDefaultSyntax
referentialActionNoActionSyntax :: SqliteReferentialActionSyntax
referentialActionNoActionSyntax = SqliteSyntax
-> BeamSerializedReferentialAction -> SqliteReferentialActionSyntax
SqliteReferentialActionSyntax (ByteString -> SqliteSyntax
emit ByteString
"NO ACTION") BeamSerializedReferentialAction
forall refAction.
IsSql92ReferentialActionSyntax refAction =>
refAction
referentialActionNoActionSyntax
instance IsSql92TableConstraintSyntax SqliteTableConstraintSyntax where
primaryKeyConstraintSyntax :: [Text] -> SqliteTableConstraintSyntax
primaryKeyConstraintSyntax [Text]
fields =
SqliteSyntax -> Maybe [Text] -> SqliteTableConstraintSyntax
SqliteTableConstraintSyntax
(ByteString -> SqliteSyntax
emit ByteString
"PRIMARY KEY" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((Text -> SqliteSyntax) -> [Text] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SqliteSyntax
quotedIdentifier [Text]
fields)))
([Text] -> Maybe [Text]
forall a. a -> Maybe a
Just [Text]
fields)
instance IsSql92CreateTableSyntax SqliteCreateTableSyntax where
type Sql92CreateTableColumnSchemaSyntax SqliteCreateTableSyntax = SqliteColumnSchemaSyntax
type Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax = SqliteTableConstraintSyntax
type Sql92CreateTableOptionsSyntax SqliteCreateTableSyntax = SqliteTableOptionsSyntax
type Sql92CreateTableTableNameSyntax SqliteCreateTableSyntax = SqliteTableNameSyntax
createTableSyntax :: Maybe (Sql92CreateTableOptionsSyntax SqliteCreateTableSyntax)
-> Sql92CreateTableTableNameSyntax SqliteCreateTableSyntax
-> [(Text,
Sql92CreateTableColumnSchemaSyntax SqliteCreateTableSyntax)]
-> [Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax]
-> SqliteCreateTableSyntax
createTableSyntax Maybe (Sql92CreateTableOptionsSyntax SqliteCreateTableSyntax)
_ Sql92CreateTableTableNameSyntax SqliteCreateTableSyntax
nm [(Text,
Sql92CreateTableColumnSchemaSyntax SqliteCreateTableSyntax)]
fields [Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax]
constraints =
let fieldDefs :: [SqliteSyntax]
fieldDefs = ((Text, SqliteColumnSchemaSyntax) -> SqliteSyntax)
-> [(Text, SqliteColumnSchemaSyntax)] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map (Text, SqliteColumnSchemaSyntax) -> SqliteSyntax
mkFieldDef [(Text,
Sql92CreateTableColumnSchemaSyntax SqliteCreateTableSyntax)]
[(Text, SqliteColumnSchemaSyntax)]
fields
constraintDefs :: [SqliteSyntax]
constraintDefs = (SqliteTableConstraintSyntax -> SqliteSyntax)
-> [SqliteTableConstraintSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteTableConstraintSyntax -> SqliteSyntax
fromSqliteTableConstraint [Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax]
[SqliteTableConstraintSyntax]
constraints
noPkConstraintDefs :: [SqliteSyntax]
noPkConstraintDefs = (SqliteTableConstraintSyntax -> SqliteSyntax)
-> [SqliteTableConstraintSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteTableConstraintSyntax -> SqliteSyntax
fromSqliteTableConstraint ((SqliteTableConstraintSyntax -> Bool)
-> [SqliteTableConstraintSyntax] -> [SqliteTableConstraintSyntax]
forall a. (a -> Bool) -> [a] -> [a]
filter (Maybe [Text] -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe [Text] -> Bool)
-> (SqliteTableConstraintSyntax -> Maybe [Text])
-> SqliteTableConstraintSyntax
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteTableConstraintSyntax -> Maybe [Text]
sqliteTableConstraintPrimaryKey) [Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax]
[SqliteTableConstraintSyntax]
constraints)
constraintPks :: [[Text]]
constraintPks = (SqliteTableConstraintSyntax -> Maybe [Text])
-> [SqliteTableConstraintSyntax] -> [[Text]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe SqliteTableConstraintSyntax -> Maybe [Text]
sqliteTableConstraintPrimaryKey [Sql92CreateTableTableConstraintSyntax SqliteCreateTableSyntax]
[SqliteTableConstraintSyntax]
constraints
fieldPrimaryKey :: [Text]
fieldPrimaryKey = ((Text, SqliteColumnSchemaSyntax) -> Text)
-> [(Text, SqliteColumnSchemaSyntax)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, SqliteColumnSchemaSyntax) -> Text
forall a b. (a, b) -> a
fst (((Text, SqliteColumnSchemaSyntax) -> Bool)
-> [(Text, SqliteColumnSchemaSyntax)]
-> [(Text, SqliteColumnSchemaSyntax)]
forall a. (a -> Bool) -> [a] -> [a]
filter (SqliteColumnSchemaSyntax -> Bool
sqliteIsSerialColumn (SqliteColumnSchemaSyntax -> Bool)
-> ((Text, SqliteColumnSchemaSyntax) -> SqliteColumnSchemaSyntax)
-> (Text, SqliteColumnSchemaSyntax)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, SqliteColumnSchemaSyntax) -> SqliteColumnSchemaSyntax
forall a b. (a, b) -> b
snd) [(Text,
Sql92CreateTableColumnSchemaSyntax SqliteCreateTableSyntax)]
[(Text, SqliteColumnSchemaSyntax)]
fields)
mkFieldDef :: (Text, SqliteColumnSchemaSyntax) -> SqliteSyntax
mkFieldDef (Text
fieldNm, SqliteColumnSchemaSyntax
fieldTy) =
Text -> SqliteSyntax
quotedIdentifier Text
fieldNm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteColumnSchemaSyntax -> SqliteSyntax
fromSqliteColumnSchema SqliteColumnSchemaSyntax
fieldTy
createWithConstraints :: [SqliteSyntax] -> SqliteCreateTableSyntax
createWithConstraints [SqliteSyntax]
constraintDefs' =
SqliteSyntax -> SqliteCreateTableSyntax
SqliteCreateTableSyntax (SqliteSyntax -> SqliteCreateTableSyntax)
-> SqliteSyntax -> SqliteCreateTableSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"CREATE TABLE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName Sql92CreateTableTableNameSyntax SqliteCreateTableSyntax
SqliteTableNameSyntax
nm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ([SqliteSyntax]
fieldDefs [SqliteSyntax] -> [SqliteSyntax] -> [SqliteSyntax]
forall a. Semigroup a => a -> a -> a
<> [SqliteSyntax]
constraintDefs'))
normalCreateTable :: SqliteCreateTableSyntax
normalCreateTable = [SqliteSyntax] -> SqliteCreateTableSyntax
createWithConstraints [SqliteSyntax]
constraintDefs
createTableNoPkConstraint :: SqliteCreateTableSyntax
createTableNoPkConstraint = [SqliteSyntax] -> SqliteCreateTableSyntax
createWithConstraints [SqliteSyntax]
noPkConstraintDefs
in case [Text]
fieldPrimaryKey of
[] -> SqliteCreateTableSyntax
normalCreateTable
[Text
field] ->
case [[Text]]
constraintPks of
[] -> String -> SqliteCreateTableSyntax
forall a. HasCallStack => String -> a
error String
"A column claims to have a primary key, but there is no key on this table"
[[Text
fieldPk]]
| Text
field Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
fieldPk -> String -> SqliteCreateTableSyntax
forall a. HasCallStack => String -> a
error String
"Two columns claim to be a primary key on this table"
| Bool
otherwise -> SqliteCreateTableSyntax
createTableNoPkConstraint
[[Text]]
_ -> String -> SqliteCreateTableSyntax
forall a. HasCallStack => String -> a
error String
"There are multiple primary key constraints on this table"
[Text]
_ -> String -> SqliteCreateTableSyntax
forall a. HasCallStack => String -> a
error String
"More than one column claims to be a primary key on this table"
instance IsSql92DataTypeSyntax SqliteDataTypeSyntax where
domainType :: Text -> SqliteDataTypeSyntax
domainType Text
nm = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (Text -> SqliteSyntax
quotedIdentifier Text
nm) (Text -> HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => Text -> dataType
domainType Text
nm) (Text -> BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => Text -> dataType
domainType Text
nm) Bool
False
charType :: Maybe Word -> Maybe Text -> SqliteDataTypeSyntax
charType Maybe Word
prec Maybe Text
charSet = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"CHAR" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> SqliteSyntax
sqliteOptCharSet Maybe Text
charSet)
(Maybe Word -> Maybe Text -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
charType Maybe Word
prec Maybe Text
charSet)
(Maybe Word -> Maybe Text -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
charType Maybe Word
prec Maybe Text
charSet)
Bool
False
varCharType :: Maybe Word -> Maybe Text -> SqliteDataTypeSyntax
varCharType Maybe Word
prec Maybe Text
charSet = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"VARCHAR" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> SqliteSyntax
sqliteOptCharSet Maybe Text
charSet)
(Maybe Word -> Maybe Text -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
varCharType Maybe Word
prec Maybe Text
charSet)
(Maybe Word -> Maybe Text -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Maybe Text -> dataType
varCharType Maybe Word
prec Maybe Text
charSet)
Bool
False
nationalCharType :: Maybe Word -> SqliteDataTypeSyntax
nationalCharType Maybe Word
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"NATIONAL CHAR" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec)
(Maybe Word -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalCharType Maybe Word
prec)
(Maybe Word -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalCharType Maybe Word
prec)
Bool
False
nationalVarCharType :: Maybe Word -> SqliteDataTypeSyntax
nationalVarCharType Maybe Word
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"NATIONAL CHARACTER VARYING" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec)
(Maybe Word -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalVarCharType Maybe Word
prec)
(Maybe Word -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
nationalVarCharType Maybe Word
prec)
Bool
False
bitType :: Maybe Word -> SqliteDataTypeSyntax
bitType Maybe Word
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"BIT" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec) (Maybe Word -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
bitType Maybe Word
prec) (Maybe Word -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
bitType Maybe Word
prec) Bool
False
varBitType :: Maybe Word -> SqliteDataTypeSyntax
varBitType Maybe Word
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"BIT VARYING" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec) (Maybe Word -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
varBitType Maybe Word
prec) (Maybe Word -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
varBitType Maybe Word
prec) Bool
False
numericType :: Maybe (Word, Maybe Word) -> SqliteDataTypeSyntax
numericType Maybe (Word, Maybe Word)
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"NUMERIC" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> SqliteSyntax
sqliteOptNumericPrec Maybe (Word, Maybe Word)
prec) (Maybe (Word, Maybe Word) -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
numericType Maybe (Word, Maybe Word)
prec) (Maybe (Word, Maybe Word) -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
numericType Maybe (Word, Maybe Word)
prec) Bool
False
decimalType :: Maybe (Word, Maybe Word) -> SqliteDataTypeSyntax
decimalType Maybe (Word, Maybe Word)
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"DECIMAL" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe (Word, Maybe Word) -> SqliteSyntax
sqliteOptNumericPrec Maybe (Word, Maybe Word)
prec) (Maybe (Word, Maybe Word) -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
decimalType Maybe (Word, Maybe Word)
prec) (Maybe (Word, Maybe Word) -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe (Word, Maybe Word) -> dataType
decimalType Maybe (Word, Maybe Word)
prec) Bool
False
intType :: SqliteDataTypeSyntax
intType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"INTEGER") HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
intType BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
intType Bool
False
smallIntType :: SqliteDataTypeSyntax
smallIntType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"SMALLINT") HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
smallIntType BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
smallIntType Bool
False
floatType :: Maybe Word -> SqliteDataTypeSyntax
floatType Maybe Word
prec = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"FLOAT" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec) (Maybe Word -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
floatType Maybe Word
prec) (Maybe Word -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> dataType
floatType Maybe Word
prec) Bool
False
doubleType :: SqliteDataTypeSyntax
doubleType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"DOUBLE PRECISION") HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
doubleType BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
doubleType Bool
False
realType :: SqliteDataTypeSyntax
realType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"REAL") HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
realType BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
realType Bool
False
dateType :: SqliteDataTypeSyntax
dateType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"DATE") HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
dateType BeamSerializedDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
dateType Bool
False
timeType :: Maybe Word -> Bool -> SqliteDataTypeSyntax
timeType Maybe Word
prec Bool
withTz = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"TIME" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then ByteString -> SqliteSyntax
emit ByteString
" WITH TIME ZONE" else SqliteSyntax
forall a. Monoid a => a
mempty)
(Maybe Word -> Bool -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timeType Maybe Word
prec Bool
withTz) (Maybe Word -> Bool -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timeType Maybe Word
prec Bool
withTz) Bool
False
timestampType :: Maybe Word -> Bool -> SqliteDataTypeSyntax
timestampType Maybe Word
prec Bool
withTz = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"TIMESTAMP" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
prec SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> if Bool
withTz then ByteString -> SqliteSyntax
emit ByteString
" WITH TIME ZONE" else SqliteSyntax
forall a. Monoid a => a
mempty)
(Maybe Word -> Bool -> HsDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timestampType Maybe Word
prec Bool
withTz) (Maybe Word -> Bool -> BeamSerializedDataType
forall dataType.
IsSql92DataTypeSyntax dataType =>
Maybe Word -> Bool -> dataType
timestampType Maybe Word
prec Bool
withTz) Bool
False
instance IsSql99DataTypeSyntax SqliteDataTypeSyntax where
characterLargeObjectType :: SqliteDataTypeSyntax
characterLargeObjectType = SqliteDataTypeSyntax
sqliteTextType
binaryLargeObjectType :: SqliteDataTypeSyntax
binaryLargeObjectType = SqliteDataTypeSyntax
sqliteBlobType
booleanType :: SqliteDataTypeSyntax
booleanType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"BOOLEAN") HsDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
booleanType BeamSerializedDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
booleanType Bool
False
arrayType :: SqliteDataTypeSyntax -> Int -> SqliteDataTypeSyntax
arrayType SqliteDataTypeSyntax
_ Int
_ = String -> SqliteDataTypeSyntax
forall a. HasCallStack => String -> a
error String
"SQLite does not support arrayType"
rowType :: [(Text, SqliteDataTypeSyntax)] -> SqliteDataTypeSyntax
rowType [(Text, SqliteDataTypeSyntax)]
_ = String -> SqliteDataTypeSyntax
forall a. HasCallStack => String -> a
error String
"SQLite does not support rowType"
instance IsSql2008BigIntDataTypeSyntax SqliteDataTypeSyntax where
bigIntType :: SqliteDataTypeSyntax
bigIntType = SqliteDataTypeSyntax
sqliteBigIntType
sqliteTextType, sqliteBlobType, sqliteBigIntType :: SqliteDataTypeSyntax
sqliteTextType :: SqliteDataTypeSyntax
sqliteTextType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"TEXT")
(HsExpr -> HsType -> BeamSerializedDataType -> HsDataType
HsDataType (Text -> Text -> HsExpr
hsVarFrom Text
"sqliteText" Text
"Database.Beam.Sqlite")
(Type () -> HsImports -> HsType
HsType (String -> Type ()
tyConNamed String
"Text")
(Text -> [ImportSpec ()] -> HsImports
importSome Text
"Data.Text" [Text -> ImportSpec ()
importTyNamed Text
"Text"]))
BeamSerializedDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
characterLargeObjectType)
BeamSerializedDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
characterLargeObjectType
Bool
False
sqliteBlobType :: SqliteDataTypeSyntax
sqliteBlobType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"BLOB")
(HsExpr -> HsType -> BeamSerializedDataType -> HsDataType
HsDataType (Text -> Text -> HsExpr
hsVarFrom Text
"sqliteBlob" Text
"Database.Beam.Sqlite")
(Type () -> HsImports -> HsType
HsType (String -> Type ()
tyConNamed String
"ByteString")
(Text -> [ImportSpec ()] -> HsImports
importSome Text
"Data.ByteString" [Text -> ImportSpec ()
importTyNamed Text
"ByteString"]))
BeamSerializedDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
binaryLargeObjectType)
BeamSerializedDataType
forall dataType. IsSql99DataTypeSyntax dataType => dataType
binaryLargeObjectType
Bool
False
sqliteBigIntType :: SqliteDataTypeSyntax
sqliteBigIntType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"BIGINT")
(HsExpr -> HsType -> BeamSerializedDataType -> HsDataType
HsDataType (Text -> Text -> HsExpr
hsVarFrom Text
"sqliteBigInt" Text
"Database.Beam.Sqlite")
(Type () -> HsImports -> HsType
HsType (String -> Type ()
tyConNamed String
"Int64")
(Text -> [ImportSpec ()] -> HsImports
importSome Text
"Data.Int" [Text -> ImportSpec ()
importTyNamed Text
"Int64"]))
BeamSerializedDataType
forall dataType. IsSql2008BigIntDataTypeSyntax dataType => dataType
bigIntType)
BeamSerializedDataType
forall dataType. IsSql2008BigIntDataTypeSyntax dataType => dataType
bigIntType
Bool
False
instance Sql92SerializableDataTypeSyntax SqliteDataTypeSyntax where
serializeDataType :: SqliteDataTypeSyntax -> Value
serializeDataType = BeamSerializedDataType -> Value
fromBeamSerializedDataType (BeamSerializedDataType -> Value)
-> (SqliteDataTypeSyntax -> BeamSerializedDataType)
-> SqliteDataTypeSyntax
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteDataTypeSyntax -> BeamSerializedDataType
sqliteDataTypeSerialized
sqliteOptPrec :: Maybe Word -> SqliteSyntax
sqliteOptPrec :: Maybe Word -> SqliteSyntax
sqliteOptPrec Maybe Word
Nothing = SqliteSyntax
forall a. Monoid a => a
mempty
sqliteOptPrec (Just Word
x) = SqliteSyntax -> SqliteSyntax
parens (ByteString -> SqliteSyntax
emit (String -> ByteString
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
x)))
sqliteOptNumericPrec :: Maybe (Word, Maybe Word) -> SqliteSyntax
sqliteOptNumericPrec :: Maybe (Word, Maybe Word) -> SqliteSyntax
sqliteOptNumericPrec Maybe (Word, Maybe Word)
Nothing = SqliteSyntax
forall a. Monoid a => a
mempty
sqliteOptNumericPrec (Just (Word
prec, Maybe Word
Nothing)) = Maybe Word -> SqliteSyntax
sqliteOptPrec (Word -> Maybe Word
forall a. a -> Maybe a
Just Word
prec)
sqliteOptNumericPrec (Just (Word
prec, Just Word
dec)) = SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax) -> SqliteSyntax -> SqliteSyntax
forall a b. (a -> b) -> a -> b
$ ByteString -> SqliteSyntax
emit (String -> ByteString
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
prec)) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
", " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit (String -> ByteString
forall a. IsString a => String -> a
fromString (Word -> String
forall a. Show a => a -> String
show Word
dec))
sqliteOptCharSet :: Maybe T.Text -> SqliteSyntax
sqliteOptCharSet :: Maybe Text -> SqliteSyntax
sqliteOptCharSet Maybe Text
Nothing = SqliteSyntax
forall a. Monoid a => a
mempty
sqliteOptCharSet (Just Text
cs) = ByteString -> SqliteSyntax
emit ByteString
" CHARACTER SET " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit (Text -> ByteString
TE.encodeUtf8 Text
cs)
instance IsSql92SelectSyntax SqliteSelectSyntax where
type Sql92SelectSelectTableSyntax SqliteSelectSyntax = SqliteSelectTableSyntax
type Sql92SelectOrderingSyntax SqliteSelectSyntax = SqliteOrderingSyntax
selectStmt :: Sql92SelectSelectTableSyntax SqliteSelectSyntax
-> [Sql92SelectOrderingSyntax SqliteSelectSyntax]
-> Maybe Integer
-> Maybe Integer
-> SqliteSelectSyntax
selectStmt Sql92SelectSelectTableSyntax SqliteSelectSyntax
tbl [Sql92SelectOrderingSyntax SqliteSelectSyntax]
ordering Maybe Integer
limit Maybe Integer
offset =
SqliteSyntax -> SqliteSelectSyntax
SqliteSelectSyntax (SqliteSyntax -> SqliteSelectSyntax)
-> SqliteSyntax -> SqliteSelectSyntax
forall a b. (a -> b) -> a -> b
$
SqliteSelectTableSyntax -> SqliteSyntax
fromSqliteSelectTable Sql92SelectSelectTableSyntax SqliteSelectSyntax
SqliteSelectTableSyntax
tbl SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
(case [Sql92SelectOrderingSyntax SqliteSelectSyntax]
ordering of
[] -> SqliteSyntax
forall a. Monoid a => a
mempty
[Sql92SelectOrderingSyntax SqliteSelectSyntax]
_ -> ByteString -> SqliteSyntax
emit ByteString
" ORDER BY " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> [SqliteSyntax] -> SqliteSyntax
commas ([SqliteOrderingSyntax] -> [SqliteSyntax]
coerce [Sql92SelectOrderingSyntax SqliteSelectSyntax]
[SqliteOrderingSyntax]
ordering)) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
case (Maybe Integer
limit, Maybe Integer
offset) of
(Maybe Integer
Nothing, Maybe Integer
Nothing) -> SqliteSyntax
forall a. Monoid a => a
mempty
(Just Integer
limit, Maybe Integer
Nothing) -> ByteString -> SqliteSyntax
emit ByteString
" LIMIT " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Integer -> SqliteSyntax
forall a. Show a => a -> SqliteSyntax
emit' Integer
limit
(Maybe Integer
Nothing, Just Integer
offset) -> ByteString -> SqliteSyntax
emit ByteString
" LIMIT -1 OFFSET " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Integer -> SqliteSyntax
forall a. Show a => a -> SqliteSyntax
emit' Integer
offset
(Just Integer
limit, Just Integer
offset) -> ByteString -> SqliteSyntax
emit ByteString
" LIMIT " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Integer -> SqliteSyntax
forall a. Show a => a -> SqliteSyntax
emit' Integer
limit SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
" OFFSET " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Integer -> SqliteSyntax
forall a. Show a => a -> SqliteSyntax
emit' Integer
offset
instance IsSql92SelectTableSyntax SqliteSelectTableSyntax where
type Sql92SelectTableSelectSyntax SqliteSelectTableSyntax = SqliteSelectSyntax
type Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax = SqliteExpressionSyntax
type Sql92SelectTableProjectionSyntax SqliteSelectTableSyntax = SqliteProjectionSyntax
type Sql92SelectTableFromSyntax SqliteSelectTableSyntax = SqliteFromSyntax
type Sql92SelectTableGroupingSyntax SqliteSelectTableSyntax = SqliteGroupingSyntax
type Sql92SelectTableSetQuantifierSyntax SqliteSelectTableSyntax = SqliteAggregationSetQuantifierSyntax
selectTableStmt :: Maybe (Sql92SelectTableSetQuantifierSyntax SqliteSelectTableSyntax)
-> Sql92SelectTableProjectionSyntax SqliteSelectTableSyntax
-> Maybe (Sql92SelectTableFromSyntax SqliteSelectTableSyntax)
-> Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
-> Maybe (Sql92SelectTableGroupingSyntax SqliteSelectTableSyntax)
-> Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
-> SqliteSelectTableSyntax
selectTableStmt Maybe (Sql92SelectTableSetQuantifierSyntax SqliteSelectTableSyntax)
setQuantifier Sql92SelectTableProjectionSyntax SqliteSelectTableSyntax
proj Maybe (Sql92SelectTableFromSyntax SqliteSelectTableSyntax)
from Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
where_ Maybe (Sql92SelectTableGroupingSyntax SqliteSelectTableSyntax)
grouping Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
having =
SqliteSyntax -> SqliteSelectTableSyntax
SqliteSelectTableSyntax (SqliteSyntax -> SqliteSelectTableSyntax)
-> SqliteSyntax -> SqliteSelectTableSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"SELECT " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteSyntax -> SqliteSyntax)
-> Maybe SqliteSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ") (SqliteAggregationSetQuantifierSyntax -> SqliteSyntax
fromSqliteAggregationSetQuantifier (SqliteAggregationSetQuantifierSyntax -> SqliteSyntax)
-> Maybe SqliteAggregationSetQuantifierSyntax -> Maybe SqliteSyntax
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Sql92SelectTableSetQuantifierSyntax SqliteSelectTableSyntax)
Maybe SqliteAggregationSetQuantifierSyntax
setQuantifier) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteProjectionSyntax -> SqliteSyntax
fromSqliteProjection Sql92SelectTableProjectionSyntax SqliteSelectTableSyntax
SqliteProjectionSyntax
proj SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteSyntax -> SqliteSyntax)
-> Maybe SqliteSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (ByteString -> SqliteSyntax
emit ByteString
" FROM " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) (SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax (SqliteFromSyntax -> SqliteSyntax)
-> Maybe SqliteFromSyntax -> Maybe SqliteSyntax
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Sql92SelectTableFromSyntax SqliteSelectTableSyntax)
Maybe SqliteFromSyntax
from) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteSyntax -> SqliteSyntax)
-> Maybe SqliteSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (ByteString -> SqliteSyntax
emit ByteString
" WHERE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression (SqliteExpressionSyntax -> SqliteSyntax)
-> Maybe SqliteExpressionSyntax -> Maybe SqliteSyntax
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
Maybe SqliteExpressionSyntax
where_) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteSyntax -> SqliteSyntax)
-> Maybe SqliteSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (ByteString -> SqliteSyntax
emit ByteString
" GROUP BY " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) (SqliteGroupingSyntax -> SqliteSyntax
fromSqliteGrouping (SqliteGroupingSyntax -> SqliteSyntax)
-> Maybe SqliteGroupingSyntax -> Maybe SqliteSyntax
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Sql92SelectTableGroupingSyntax SqliteSelectTableSyntax)
Maybe SqliteGroupingSyntax
grouping) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteSyntax -> SqliteSyntax)
-> Maybe SqliteSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (ByteString -> SqliteSyntax
emit ByteString
" HAVING " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression (SqliteExpressionSyntax -> SqliteSyntax)
-> Maybe SqliteExpressionSyntax -> Maybe SqliteSyntax
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Sql92SelectTableExpressionSyntax SqliteSelectTableSyntax)
Maybe SqliteExpressionSyntax
having)
unionTables :: Bool
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
unionTables Bool
all = ByteString
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
tableOp (if Bool
all then ByteString
"UNION ALL" else ByteString
"UNION")
intersectTables :: Bool
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
intersectTables Bool
all = ByteString
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
tableOp (if Bool
all then ByteString
"INTERSECT ALL" else ByteString
"INTERSECT")
exceptTable :: Bool
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
exceptTable Bool
all = ByteString
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
tableOp (if Bool
all then ByteString
"EXCEPT ALL" else ByteString
"EXCEPT")
tableOp :: ByteString -> SqliteSelectTableSyntax -> SqliteSelectTableSyntax -> SqliteSelectTableSyntax
tableOp :: ByteString
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
-> SqliteSelectTableSyntax
tableOp ByteString
op SqliteSelectTableSyntax
a SqliteSelectTableSyntax
b =
SqliteSyntax -> SqliteSelectTableSyntax
SqliteSelectTableSyntax (SqliteSyntax -> SqliteSelectTableSyntax)
-> SqliteSyntax -> SqliteSelectTableSyntax
forall a b. (a -> b) -> a -> b
$
SqliteSelectTableSyntax -> SqliteSyntax
fromSqliteSelectTable SqliteSelectTableSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
spaces (ByteString -> SqliteSyntax
emit ByteString
op) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSelectTableSyntax -> SqliteSyntax
fromSqliteSelectTable SqliteSelectTableSyntax
b
instance IsSql92FromSyntax SqliteFromSyntax where
type Sql92FromExpressionSyntax SqliteFromSyntax = SqliteExpressionSyntax
type Sql92FromTableSourceSyntax SqliteFromSyntax = SqliteTableSourceSyntax
fromTable :: Sql92FromTableSourceSyntax SqliteFromSyntax
-> Maybe (Text, Maybe [Text]) -> SqliteFromSyntax
fromTable Sql92FromTableSourceSyntax SqliteFromSyntax
tableSrc Maybe (Text, Maybe [Text])
Nothing = SqliteSyntax -> SqliteFromSyntax
SqliteFromSyntax (SqliteTableSourceSyntax -> SqliteSyntax
fromSqliteTableSource Sql92FromTableSourceSyntax SqliteFromSyntax
SqliteTableSourceSyntax
tableSrc)
fromTable Sql92FromTableSourceSyntax SqliteFromSyntax
tableSrc (Just (Text
nm, Maybe [Text]
colNms)) =
SqliteSyntax -> SqliteFromSyntax
SqliteFromSyntax (SqliteTableSourceSyntax -> SqliteSyntax
fromSqliteTableSource Sql92FromTableSourceSyntax SqliteFromSyntax
SqliteTableSourceSyntax
tableSrc SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" AS " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
nm SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> ([Text] -> SqliteSyntax) -> Maybe [Text] -> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\[Text]
colNms' -> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((Text -> SqliteSyntax) -> [Text] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SqliteSyntax
quotedIdentifier [Text]
colNms'))) Maybe [Text]
colNms)
innerJoin :: SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe (Sql92FromExpressionSyntax SqliteFromSyntax)
-> SqliteFromSyntax
innerJoin = ByteString
-> SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe SqliteExpressionSyntax
-> SqliteFromSyntax
_join ByteString
"INNER JOIN"
leftJoin :: SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe (Sql92FromExpressionSyntax SqliteFromSyntax)
-> SqliteFromSyntax
leftJoin = ByteString
-> SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe SqliteExpressionSyntax
-> SqliteFromSyntax
_join ByteString
"LEFT JOIN"
rightJoin :: SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe (Sql92FromExpressionSyntax SqliteFromSyntax)
-> SqliteFromSyntax
rightJoin = ByteString
-> SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe SqliteExpressionSyntax
-> SqliteFromSyntax
_join ByteString
"RIGHT JOIN"
_join :: ByteString -> SqliteFromSyntax -> SqliteFromSyntax -> Maybe SqliteExpressionSyntax -> SqliteFromSyntax
_join :: ByteString
-> SqliteFromSyntax
-> SqliteFromSyntax
-> Maybe SqliteExpressionSyntax
-> SqliteFromSyntax
_join ByteString
joinType SqliteFromSyntax
a SqliteFromSyntax
b Maybe SqliteExpressionSyntax
Nothing =
SqliteSyntax -> SqliteFromSyntax
SqliteFromSyntax (SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax SqliteFromSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
spaces (ByteString -> SqliteSyntax
emit ByteString
joinType) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax SqliteFromSyntax
b)
_join ByteString
joinType SqliteFromSyntax
a SqliteFromSyntax
b (Just SqliteExpressionSyntax
on) =
SqliteSyntax -> SqliteFromSyntax
SqliteFromSyntax (SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax SqliteFromSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
spaces (ByteString -> SqliteSyntax
emit ByteString
joinType) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteFromSyntax -> SqliteSyntax
fromSqliteFromSyntax SqliteFromSyntax
b SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ON " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
on)
instance IsSql92ProjectionSyntax SqliteProjectionSyntax where
type Sql92ProjectionExpressionSyntax SqliteProjectionSyntax = SqliteExpressionSyntax
projExprs :: [(Sql92ProjectionExpressionSyntax SqliteProjectionSyntax,
Maybe Text)]
-> SqliteProjectionSyntax
projExprs [(Sql92ProjectionExpressionSyntax SqliteProjectionSyntax,
Maybe Text)]
exprs =
SqliteSyntax -> SqliteProjectionSyntax
SqliteProjectionSyntax (SqliteSyntax -> SqliteProjectionSyntax)
-> SqliteSyntax -> SqliteProjectionSyntax
forall a b. (a -> b) -> a -> b
$
[SqliteSyntax] -> SqliteSyntax
commas (((SqliteExpressionSyntax, Maybe Text) -> SqliteSyntax)
-> [(SqliteExpressionSyntax, Maybe Text)] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map (\(SqliteExpressionSyntax
expr, Maybe Text
nm) -> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
expr SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (Text -> SqliteSyntax) -> Maybe Text -> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\Text
nm -> ByteString -> SqliteSyntax
emit ByteString
" AS " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
nm) Maybe Text
nm) [(Sql92ProjectionExpressionSyntax SqliteProjectionSyntax,
Maybe Text)]
[(SqliteExpressionSyntax, Maybe Text)]
exprs)
instance IsSql92FieldNameSyntax SqliteFieldNameSyntax where
qualifiedField :: Text -> Text -> SqliteFieldNameSyntax
qualifiedField Text
a Text
b =
SqliteSyntax -> SqliteFieldNameSyntax
SqliteFieldNameSyntax (SqliteSyntax -> SqliteFieldNameSyntax)
-> SqliteSyntax -> SqliteFieldNameSyntax
forall a b. (a -> b) -> a -> b
$
Text -> SqliteSyntax
quotedIdentifier Text
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
"." SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> Text -> SqliteSyntax
quotedIdentifier Text
b
unqualifiedField :: Text -> SqliteFieldNameSyntax
unqualifiedField Text
a =
SqliteSyntax -> SqliteFieldNameSyntax
SqliteFieldNameSyntax (SqliteSyntax -> SqliteFieldNameSyntax)
-> SqliteSyntax -> SqliteFieldNameSyntax
forall a b. (a -> b) -> a -> b
$
Text -> SqliteSyntax
quotedIdentifier Text
a
instance IsSql92TableSourceSyntax SqliteTableSourceSyntax where
type Sql92TableSourceTableNameSyntax SqliteTableSourceSyntax = SqliteTableNameSyntax
type Sql92TableSourceSelectSyntax SqliteTableSourceSyntax = SqliteSelectSyntax
type Sql92TableSourceExpressionSyntax SqliteTableSourceSyntax = SqliteExpressionSyntax
tableNamed :: Sql92TableSourceTableNameSyntax SqliteTableSourceSyntax
-> SqliteTableSourceSyntax
tableNamed = SqliteSyntax -> SqliteTableSourceSyntax
SqliteTableSourceSyntax (SqliteSyntax -> SqliteTableSourceSyntax)
-> (SqliteTableNameSyntax -> SqliteSyntax)
-> SqliteTableNameSyntax
-> SqliteTableSourceSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName
tableFromSubSelect :: Sql92TableSourceSelectSyntax SqliteTableSourceSyntax
-> SqliteTableSourceSyntax
tableFromSubSelect Sql92TableSourceSelectSyntax SqliteTableSourceSyntax
s =
SqliteSyntax -> SqliteTableSourceSyntax
SqliteTableSourceSyntax (SqliteSyntax -> SqliteSyntax
parens (SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect Sql92TableSourceSelectSyntax SqliteTableSourceSyntax
SqliteSelectSyntax
s))
tableFromValues :: [[Sql92TableSourceExpressionSyntax SqliteTableSourceSyntax]]
-> SqliteTableSourceSyntax
tableFromValues [[Sql92TableSourceExpressionSyntax SqliteTableSourceSyntax]]
vss = SqliteSyntax -> SqliteTableSourceSyntax
SqliteTableSourceSyntax (SqliteSyntax -> SqliteTableSourceSyntax)
-> (SqliteSyntax -> SqliteSyntax)
-> SqliteSyntax
-> SqliteTableSourceSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteTableSourceSyntax)
-> SqliteSyntax -> SqliteTableSourceSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"VALUES " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
[SqliteSyntax] -> SqliteSyntax
commas (([SqliteExpressionSyntax] -> SqliteSyntax)
-> [[SqliteExpressionSyntax]] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map (\[SqliteExpressionSyntax]
vs -> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
vs))) [[Sql92TableSourceExpressionSyntax SqliteTableSourceSyntax]]
[[SqliteExpressionSyntax]]
vss)
instance IsSql92GroupingSyntax SqliteGroupingSyntax where
type Sql92GroupingExpressionSyntax SqliteGroupingSyntax = SqliteExpressionSyntax
groupByExpressions :: [Sql92GroupingExpressionSyntax SqliteGroupingSyntax]
-> SqliteGroupingSyntax
groupByExpressions [Sql92GroupingExpressionSyntax SqliteGroupingSyntax]
es =
SqliteSyntax -> SqliteGroupingSyntax
SqliteGroupingSyntax (SqliteSyntax -> SqliteGroupingSyntax)
-> SqliteSyntax -> SqliteGroupingSyntax
forall a b. (a -> b) -> a -> b
$
[SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [Sql92GroupingExpressionSyntax SqliteGroupingSyntax]
[SqliteExpressionSyntax]
es)
instance IsSql92OrderingSyntax SqliteOrderingSyntax where
type Sql92OrderingExpressionSyntax SqliteOrderingSyntax = SqliteExpressionSyntax
ascOrdering :: Sql92OrderingExpressionSyntax SqliteOrderingSyntax
-> SqliteOrderingSyntax
ascOrdering Sql92OrderingExpressionSyntax SqliteOrderingSyntax
e = SqliteSyntax -> SqliteOrderingSyntax
SqliteOrderingSyntax (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression Sql92OrderingExpressionSyntax SqliteOrderingSyntax
SqliteExpressionSyntax
e SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ASC")
descOrdering :: Sql92OrderingExpressionSyntax SqliteOrderingSyntax
-> SqliteOrderingSyntax
descOrdering Sql92OrderingExpressionSyntax SqliteOrderingSyntax
e = SqliteSyntax -> SqliteOrderingSyntax
SqliteOrderingSyntax (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression Sql92OrderingExpressionSyntax SqliteOrderingSyntax
SqliteExpressionSyntax
e SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" DESC")
instance HasSqlValueSyntax SqliteValueSyntax Int8 where
sqlValueSyntax :: Int8 -> SqliteValueSyntax
sqlValueSyntax Int8
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Int8 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
i)))
instance HasSqlValueSyntax SqliteValueSyntax Int16 where
sqlValueSyntax :: Int16 -> SqliteValueSyntax
sqlValueSyntax Int16
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Int16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
i)))
instance HasSqlValueSyntax SqliteValueSyntax Int32 where
sqlValueSyntax :: Int32 -> SqliteValueSyntax
sqlValueSyntax Int32
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Int32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
i)))
instance HasSqlValueSyntax SqliteValueSyntax Int64 where
sqlValueSyntax :: Int64 -> SqliteValueSyntax
sqlValueSyntax Int64
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Int64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
i)))
instance HasSqlValueSyntax SqliteValueSyntax Word8 where
sqlValueSyntax :: Word8 -> SqliteValueSyntax
sqlValueSyntax Word8
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Word8 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)))
instance HasSqlValueSyntax SqliteValueSyntax Word16 where
sqlValueSyntax :: Word16 -> SqliteValueSyntax
sqlValueSyntax Word16
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Word16 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
i)))
instance HasSqlValueSyntax SqliteValueSyntax Word32 where
sqlValueSyntax :: Word32 -> SqliteValueSyntax
sqlValueSyntax Word32
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
i)))
instance HasSqlValueSyntax SqliteValueSyntax Word64 where
sqlValueSyntax :: Word64 -> SqliteValueSyntax
sqlValueSyntax Word64
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
i)))
instance HasSqlValueSyntax SqliteValueSyntax Scientific where
sqlValueSyntax :: Scientific -> SqliteValueSyntax
sqlValueSyntax Scientific
s = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (String -> Text
forall a. IsString a => String -> a
fromString (Scientific -> String
forall a. Show a => a -> String
show Scientific
s))))
instance HasSqlValueSyntax SqliteValueSyntax Float where
sqlValueSyntax :: Float -> SqliteValueSyntax
sqlValueSyntax Float
f = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Double -> SQLData
SQLFloat (Float -> Double
float2Double Float
f)))
instance HasSqlValueSyntax SqliteValueSyntax Double where
sqlValueSyntax :: Double -> SqliteValueSyntax
sqlValueSyntax Double
f = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Double -> SQLData
SQLFloat Double
f))
instance HasSqlValueSyntax SqliteValueSyntax Bool where
sqlValueSyntax :: Bool -> SqliteValueSyntax
sqlValueSyntax = Int32 -> SqliteValueSyntax
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax (Int32 -> SqliteValueSyntax)
-> (Bool -> Int32) -> Bool -> SqliteValueSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Bool
b -> if Bool
b then Int32
1 else Int32
0 :: Int32)
instance HasSqlValueSyntax SqliteValueSyntax SqlNull where
sqlValueSyntax :: SqlNull -> SqliteValueSyntax
sqlValueSyntax SqlNull
_ = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (ByteString -> SqliteSyntax
emit ByteString
"NULL")
instance HasSqlValueSyntax SqliteValueSyntax String where
sqlValueSyntax :: String -> SqliteValueSyntax
sqlValueSyntax String
s = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (String -> Text
forall a. IsString a => String -> a
fromString String
s)))
instance HasSqlValueSyntax SqliteValueSyntax T.Text where
sqlValueSyntax :: Text -> SqliteValueSyntax
sqlValueSyntax Text
s = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText Text
s))
instance HasSqlValueSyntax SqliteValueSyntax TL.Text where
sqlValueSyntax :: Text -> SqliteValueSyntax
sqlValueSyntax Text
s = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (Text -> Text
TL.toStrict Text
s)))
instance HasSqlValueSyntax SqliteValueSyntax x =>
HasSqlValueSyntax SqliteValueSyntax (Maybe x) where
sqlValueSyntax :: Maybe x -> SqliteValueSyntax
sqlValueSyntax (Just x
x) = x -> SqliteValueSyntax
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax x
x
sqlValueSyntax Maybe x
Nothing = SqlNull -> SqliteValueSyntax
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax SqlNull
SqlNull
instance TypeError (PreferExplicitSize Int Int32) => HasSqlValueSyntax SqliteValueSyntax Int where
sqlValueSyntax :: Int -> SqliteValueSyntax
sqlValueSyntax Int
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i)))
instance TypeError (PreferExplicitSize Word Word32) => HasSqlValueSyntax SqliteValueSyntax Word where
sqlValueSyntax :: Word -> SqliteValueSyntax
sqlValueSyntax Word
i = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Int64 -> SQLData
SQLInteger (Word -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
i)))
instance IsCustomSqlSyntax SqliteExpressionSyntax where
newtype CustomSqlSyntax SqliteExpressionSyntax =
SqliteCustomExpressionSyntax { CustomSqlSyntax SqliteExpressionSyntax -> SqliteSyntax
fromSqliteCustomExpression :: SqliteSyntax }
deriving (Semigroup (CustomSqlSyntax SqliteExpressionSyntax)
CustomSqlSyntax SqliteExpressionSyntax
Semigroup (CustomSqlSyntax SqliteExpressionSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax
-> (CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax)
-> ([CustomSqlSyntax SqliteExpressionSyntax]
-> CustomSqlSyntax SqliteExpressionSyntax)
-> Monoid (CustomSqlSyntax SqliteExpressionSyntax)
[CustomSqlSyntax SqliteExpressionSyntax]
-> CustomSqlSyntax SqliteExpressionSyntax
CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [CustomSqlSyntax SqliteExpressionSyntax]
-> CustomSqlSyntax SqliteExpressionSyntax
$cmconcat :: [CustomSqlSyntax SqliteExpressionSyntax]
-> CustomSqlSyntax SqliteExpressionSyntax
mappend :: CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
$cmappend :: CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
mempty :: CustomSqlSyntax SqliteExpressionSyntax
$cmempty :: CustomSqlSyntax SqliteExpressionSyntax
$cp1Monoid :: Semigroup (CustomSqlSyntax SqliteExpressionSyntax)
Monoid, b
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
NonEmpty (CustomSqlSyntax SqliteExpressionSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax
CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
(CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax)
-> (NonEmpty (CustomSqlSyntax SqliteExpressionSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax)
-> (forall b.
Integral b =>
b
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax)
-> Semigroup (CustomSqlSyntax SqliteExpressionSyntax)
forall b.
Integral b =>
b
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
$cstimes :: forall b.
Integral b =>
b
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
sconcat :: NonEmpty (CustomSqlSyntax SqliteExpressionSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax
$csconcat :: NonEmpty (CustomSqlSyntax SqliteExpressionSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax
<> :: CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
$c<> :: CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
Semigroup)
customExprSyntax :: CustomSqlSyntax SqliteExpressionSyntax -> SqliteExpressionSyntax
customExprSyntax = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> (CustomSqlSyntax SqliteExpressionSyntax -> SqliteSyntax)
-> CustomSqlSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CustomSqlSyntax SqliteExpressionSyntax -> SqliteSyntax
fromSqliteCustomExpression
renderSyntax :: SqliteExpressionSyntax -> CustomSqlSyntax SqliteExpressionSyntax
renderSyntax = SqliteSyntax -> CustomSqlSyntax SqliteExpressionSyntax
SqliteCustomExpressionSyntax (SqliteSyntax -> CustomSqlSyntax SqliteExpressionSyntax)
-> (SqliteExpressionSyntax -> SqliteSyntax)
-> SqliteExpressionSyntax
-> CustomSqlSyntax SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression
instance IsString (CustomSqlSyntax SqliteExpressionSyntax) where
fromString :: String -> CustomSqlSyntax SqliteExpressionSyntax
fromString = SqliteSyntax -> CustomSqlSyntax SqliteExpressionSyntax
SqliteCustomExpressionSyntax (SqliteSyntax -> CustomSqlSyntax SqliteExpressionSyntax)
-> (String -> SqliteSyntax)
-> String
-> CustomSqlSyntax SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> SqliteSyntax
emit (ByteString -> SqliteSyntax)
-> (String -> ByteString) -> String -> SqliteSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
forall a. IsString a => String -> a
fromString
instance IsSql92QuantifierSyntax SqliteComparisonQuantifierSyntax where
quantifyOverAll :: SqliteComparisonQuantifierSyntax
quantifyOverAll = SqliteSyntax -> SqliteComparisonQuantifierSyntax
SqliteComparisonQuantifierSyntax (ByteString -> SqliteSyntax
emit ByteString
"ALL")
quantifyOverAny :: SqliteComparisonQuantifierSyntax
quantifyOverAny = SqliteSyntax -> SqliteComparisonQuantifierSyntax
SqliteComparisonQuantifierSyntax (ByteString -> SqliteSyntax
emit ByteString
"ANY")
instance IsSql92ExpressionSyntax SqliteExpressionSyntax where
type Sql92ExpressionValueSyntax SqliteExpressionSyntax = SqliteValueSyntax
type Sql92ExpressionSelectSyntax SqliteExpressionSyntax = SqliteSelectSyntax
type Sql92ExpressionFieldNameSyntax SqliteExpressionSyntax = SqliteFieldNameSyntax
type Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax = SqliteComparisonQuantifierSyntax
type Sql92ExpressionCastTargetSyntax SqliteExpressionSyntax = SqliteDataTypeSyntax
type SqliteExpressionSyntax = ExtractField
addE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
addE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"+"; subE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
subE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"-"; mulE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
mulE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"*"; divE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
divE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"/"
modE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
modE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"%"; orE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
orE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"OR"; andE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
andE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"AND"; likeE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
likeE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"LIKE"
overlapsE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
overlapsE = ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
"OVERLAPS"
eqE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
eqE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
"="; neqE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
neqE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
"<>"; ltE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
ltE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
"<"; gtE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
gtE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
">"
leE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
leE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
"<="; geE :: Maybe (Sql92ExpressionQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
geE = ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
">="
negateE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
negateE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
unOp ByteString
"-"; notE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
notE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
unOp ByteString
"NOT"
isNotNullE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isNotNullE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NOT NULL"; isNullE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isNullE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NULL"
isTrueE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isTrueE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS 1"; isNotTrueE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isNotTrueE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NOT 1"
isFalseE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isFalseE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS 0"; isNotFalseE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isNotFalseE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NOT 0"
isUnknownE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isUnknownE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NULL"; isNotUnknownE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
isNotUnknownE = ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
"IS NOT NULL"
existsE :: Sql92ExpressionSelectSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
existsE Sql92ExpressionSelectSyntax SqliteExpressionSyntax
select = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"EXISTS " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect Sql92ExpressionSelectSyntax SqliteExpressionSyntax
SqliteSelectSyntax
select))
uniqueE :: Sql92ExpressionSelectSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
uniqueE Sql92ExpressionSelectSyntax SqliteExpressionSyntax
select = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"UNIQUE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect Sql92ExpressionSelectSyntax SqliteExpressionSyntax
SqliteSelectSyntax
select))
betweenE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
betweenE SqliteExpressionSyntax
a SqliteExpressionSyntax
b SqliteExpressionSyntax
c = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
" BETWEEN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
b) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
" AND " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
c))
valueE :: Sql92ExpressionValueSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
valueE = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> (SqliteValueSyntax -> SqliteSyntax)
-> SqliteValueSyntax
-> SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteValueSyntax -> SqliteSyntax
fromSqliteValue
rowE :: [SqliteExpressionSyntax] -> SqliteExpressionSyntax
rowE [SqliteExpressionSyntax]
vs = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
vs)))
fieldE :: Sql92ExpressionFieldNameSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
fieldE = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> (SqliteFieldNameSyntax -> SqliteSyntax)
-> SqliteFieldNameSyntax
-> SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteFieldNameSyntax -> SqliteSyntax
fromSqliteFieldNameSyntax
subqueryE :: Sql92ExpressionSelectSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
subqueryE = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> (SqliteSelectSyntax -> SqliteSyntax)
-> SqliteSelectSyntax
-> SqliteExpressionSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax)
-> (SqliteSelectSyntax -> SqliteSyntax)
-> SqliteSelectSyntax
-> SqliteSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqliteSelectSyntax -> SqliteSyntax
fromSqliteSelect
positionE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
positionE SqliteExpressionSyntax
needle SqliteExpressionSyntax
haystack =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"POSITION" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
needle) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" IN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
haystack))
nullIfE :: SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
nullIfE SqliteExpressionSyntax
a SqliteExpressionSyntax
b =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"NULLIF" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
", " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
b)
absE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
absE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"ABS" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x))
bitLengthE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
bitLengthE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"8 * LENGTH" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (ByteString -> SqliteSyntax
emit ByteString
"CAST" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" AS BLOB")))
charLengthE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
charLengthE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"LENGTH" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x))
octetLengthE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
octetLengthE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"LENGTH" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (ByteString -> SqliteSyntax
emit ByteString
"CAST" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" AS BLOB")))
lowerE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
lowerE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"LOWER" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x))
upperE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
upperE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"UPPER" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x))
trimE :: SqliteExpressionSyntax -> SqliteExpressionSyntax
trimE SqliteExpressionSyntax
x = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"TRIM" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x))
coalesceE :: [SqliteExpressionSyntax] -> SqliteExpressionSyntax
coalesceE [SqliteExpressionSyntax]
es = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"COALESCE" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
es)))
extractE :: Sql92ExpressionExtractFieldSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
extractE = ExtractField -> SqliteExpressionSyntax -> SqliteExpressionSyntax
Sql92ExpressionExtractFieldSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
sqliteExtract
castE :: SqliteExpressionSyntax
-> Sql92ExpressionCastTargetSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
castE SqliteExpressionSyntax
e Sql92ExpressionCastTargetSyntax SqliteExpressionSyntax
t = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"CAST" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
e) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" AS " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteDataTypeSyntax -> SqliteSyntax
fromSqliteDataType Sql92ExpressionCastTargetSyntax SqliteExpressionSyntax
SqliteDataTypeSyntax
t))
caseE :: [(SqliteExpressionSyntax, SqliteExpressionSyntax)]
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
caseE [(SqliteExpressionSyntax, SqliteExpressionSyntax)]
cases SqliteExpressionSyntax
else_ =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"CASE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
((SqliteExpressionSyntax, SqliteExpressionSyntax) -> SqliteSyntax)
-> [(SqliteExpressionSyntax, SqliteExpressionSyntax)]
-> SqliteSyntax
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SqliteExpressionSyntax
cond, SqliteExpressionSyntax
res) -> ByteString -> SqliteSyntax
emit ByteString
"WHEN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
cond SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" THEN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
res SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ") [(SqliteExpressionSyntax, SqliteExpressionSyntax)]
cases SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
"ELSE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
else_ SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" END"
currentTimestampE :: SqliteExpressionSyntax
currentTimestampE = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"CURRENT_TIMESTAMP")
defaultE :: SqliteExpressionSyntax
defaultE = SqliteExpressionSyntax
SqliteExpressionDefault
inE :: SqliteExpressionSyntax
-> [SqliteExpressionSyntax] -> SqliteExpressionSyntax
inE SqliteExpressionSyntax
e [SqliteExpressionSyntax]
es = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
e) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" IN " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
es)))
instance IsSql99ConcatExpressionSyntax SqliteExpressionSyntax where
concatE :: [SqliteExpressionSyntax] -> SqliteExpressionSyntax
concatE [] = Sql92ExpressionValueSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (Text -> SqliteValueSyntax
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax (Text
"" :: T.Text))
concatE (SqliteExpressionSyntax
x:[SqliteExpressionSyntax]
xs) =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$ SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax -> SqliteSyntax) -> SqliteSyntax -> SqliteSyntax
forall a b. (a -> b) -> a -> b
$
(SqliteSyntax -> SqliteExpressionSyntax -> SqliteSyntax)
-> SqliteSyntax -> [SqliteExpressionSyntax] -> SqliteSyntax
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\SqliteSyntax
a SqliteExpressionSyntax
b -> SqliteSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" || " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
b)) (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
x) [SqliteExpressionSyntax]
xs
instance IsSql99FunctionExpressionSyntax SqliteExpressionSyntax where
functionCallE :: SqliteExpressionSyntax
-> [SqliteExpressionSyntax] -> SqliteExpressionSyntax
functionCallE SqliteExpressionSyntax
fn [SqliteExpressionSyntax]
args =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
fn SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens ([SqliteSyntax] -> SqliteSyntax
commas ((SqliteExpressionSyntax -> SqliteSyntax)
-> [SqliteExpressionSyntax] -> [SqliteSyntax]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression [SqliteExpressionSyntax]
args))
functionNameE :: Text -> SqliteExpressionSyntax
functionNameE Text
nm = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit (Text -> ByteString
TE.encodeUtf8 Text
nm))
binOp :: ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax -> SqliteExpressionSyntax
binOp :: ByteString
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
binOp ByteString
op SqliteExpressionSyntax
a SqliteExpressionSyntax
b =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
op SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
b)
compOp :: ByteString -> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp :: ByteString
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
compOp ByteString
op Maybe SqliteComparisonQuantifierSyntax
quantifier SqliteExpressionSyntax
a SqliteExpressionSyntax
b =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
ByteString -> SqliteSyntax
emit ByteString
op SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteComparisonQuantifierSyntax -> SqliteSyntax)
-> Maybe SqliteComparisonQuantifierSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteComparisonQuantifierSyntax
q -> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteComparisonQuantifierSyntax -> SqliteSyntax
fromSqliteComparisonQuantifier SqliteComparisonQuantifierSyntax
q SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ") Maybe SqliteComparisonQuantifierSyntax
quantifier SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
b)
unOp, postFix :: ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
unOp :: ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
unOp ByteString
op SqliteExpressionSyntax
a =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
op SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a))
postFix :: ByteString -> SqliteExpressionSyntax -> SqliteExpressionSyntax
postFix ByteString
op SqliteExpressionSyntax
a =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteSyntax
parens (SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
a) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
op)
instance IsSql92AggregationExpressionSyntax SqliteExpressionSyntax where
type Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax = SqliteAggregationSetQuantifierSyntax
countAllE :: SqliteExpressionSyntax
countAllE = SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"COUNT(*)")
countE :: Maybe (Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
countE = ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
"COUNT"
sumE :: Maybe (Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
sumE = ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
"SUM"
avgE :: Maybe (Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
avgE = ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
"AVG"
minE :: Maybe (Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
minE = ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
"MIN"
maxE :: Maybe (Sql92AggregationSetQuantifierSyntax SqliteExpressionSyntax)
-> SqliteExpressionSyntax -> SqliteExpressionSyntax
maxE = ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
"MAX"
unAgg :: ByteString -> Maybe SqliteAggregationSetQuantifierSyntax -> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg :: ByteString
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteExpressionSyntax
-> SqliteExpressionSyntax
unAgg ByteString
fn Maybe SqliteAggregationSetQuantifierSyntax
q SqliteExpressionSyntax
e =
SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (SqliteSyntax -> SqliteExpressionSyntax)
-> SqliteSyntax -> SqliteExpressionSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
fn SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax -> SqliteSyntax
parens (SqliteSyntax
-> (SqliteAggregationSetQuantifierSyntax -> SqliteSyntax)
-> Maybe SqliteAggregationSetQuantifierSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteAggregationSetQuantifierSyntax
q -> SqliteAggregationSetQuantifierSyntax -> SqliteSyntax
fromSqliteAggregationSetQuantifier SqliteAggregationSetQuantifierSyntax
q SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" ") Maybe SqliteAggregationSetQuantifierSyntax
q SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
e)
instance IsSql92AggregationSetQuantifierSyntax SqliteAggregationSetQuantifierSyntax where
setQuantifierDistinct :: SqliteAggregationSetQuantifierSyntax
setQuantifierDistinct = SqliteSyntax -> SqliteAggregationSetQuantifierSyntax
SqliteAggregationSetQuantifierSyntax (ByteString -> SqliteSyntax
emit ByteString
"DISTINCT")
setQuantifierAll :: SqliteAggregationSetQuantifierSyntax
setQuantifierAll = SqliteSyntax -> SqliteAggregationSetQuantifierSyntax
SqliteAggregationSetQuantifierSyntax (ByteString -> SqliteSyntax
emit ByteString
"ALL")
instance IsSql92InsertSyntax SqliteInsertSyntax where
type Sql92InsertTableNameSyntax SqliteInsertSyntax = SqliteTableNameSyntax
type Sql92InsertValuesSyntax SqliteInsertSyntax = SqliteInsertValuesSyntax
insertStmt :: Sql92InsertTableNameSyntax SqliteInsertSyntax
-> [Text]
-> Sql92InsertValuesSyntax SqliteInsertSyntax
-> SqliteInsertSyntax
insertStmt Sql92InsertTableNameSyntax SqliteInsertSyntax
table [Text]
fields Sql92InsertValuesSyntax SqliteInsertSyntax
values = SqliteTableNameSyntax
-> [Text]
-> SqliteInsertValuesSyntax
-> Maybe SqliteOnConflictSyntax
-> SqliteInsertSyntax
SqliteInsertSyntax Sql92InsertTableNameSyntax SqliteInsertSyntax
SqliteTableNameSyntax
table [Text]
fields Sql92InsertValuesSyntax SqliteInsertSyntax
SqliteInsertValuesSyntax
values Maybe SqliteOnConflictSyntax
forall a. Maybe a
Nothing
instance IsSql92InsertValuesSyntax SqliteInsertValuesSyntax where
type Sql92InsertValuesExpressionSyntax SqliteInsertValuesSyntax = SqliteExpressionSyntax
type Sql92InsertValuesSelectSyntax SqliteInsertValuesSyntax = SqliteSelectSyntax
insertSqlExpressions :: [[Sql92InsertValuesExpressionSyntax SqliteInsertValuesSyntax]]
-> SqliteInsertValuesSyntax
insertSqlExpressions = [[Sql92InsertValuesExpressionSyntax SqliteInsertValuesSyntax]]
-> SqliteInsertValuesSyntax
[[SqliteExpressionSyntax]] -> SqliteInsertValuesSyntax
SqliteInsertExpressions
insertFromSql :: Sql92InsertValuesSelectSyntax SqliteInsertValuesSyntax
-> SqliteInsertValuesSyntax
insertFromSql = Sql92InsertValuesSelectSyntax SqliteInsertValuesSyntax
-> SqliteInsertValuesSyntax
SqliteSelectSyntax -> SqliteInsertValuesSyntax
SqliteInsertFromSql
instance IsSql92UpdateSyntax SqliteUpdateSyntax where
type Sql92UpdateTableNameSyntax SqliteUpdateSyntax = SqliteTableNameSyntax
type Sql92UpdateFieldNameSyntax SqliteUpdateSyntax = SqliteFieldNameSyntax
type Sql92UpdateExpressionSyntax SqliteUpdateSyntax = SqliteExpressionSyntax
updateStmt :: Sql92UpdateTableNameSyntax SqliteUpdateSyntax
-> [(Sql92UpdateFieldNameSyntax SqliteUpdateSyntax,
Sql92UpdateExpressionSyntax SqliteUpdateSyntax)]
-> Maybe (Sql92UpdateExpressionSyntax SqliteUpdateSyntax)
-> SqliteUpdateSyntax
updateStmt Sql92UpdateTableNameSyntax SqliteUpdateSyntax
tbl [(Sql92UpdateFieldNameSyntax SqliteUpdateSyntax,
Sql92UpdateExpressionSyntax SqliteUpdateSyntax)]
fields Maybe (Sql92UpdateExpressionSyntax SqliteUpdateSyntax)
where_ =
SqliteSyntax -> SqliteUpdateSyntax
SqliteUpdateSyntax (SqliteSyntax -> SqliteUpdateSyntax)
-> SqliteSyntax -> SqliteUpdateSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"UPDATE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName Sql92UpdateTableNameSyntax SqliteUpdateSyntax
SqliteTableNameSyntax
tbl SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
(case [(Sql92UpdateFieldNameSyntax SqliteUpdateSyntax,
Sql92UpdateExpressionSyntax SqliteUpdateSyntax)]
fields of
[] -> SqliteSyntax
forall a. Monoid a => a
mempty
[(Sql92UpdateFieldNameSyntax SqliteUpdateSyntax,
Sql92UpdateExpressionSyntax SqliteUpdateSyntax)]
_ -> ByteString -> SqliteSyntax
emit ByteString
" SET " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
[SqliteSyntax] -> SqliteSyntax
commas (((SqliteFieldNameSyntax, SqliteExpressionSyntax) -> SqliteSyntax)
-> [(SqliteFieldNameSyntax, SqliteExpressionSyntax)]
-> [SqliteSyntax]
forall a b. (a -> b) -> [a] -> [b]
map (\(SqliteFieldNameSyntax
field, SqliteExpressionSyntax
val) -> SqliteFieldNameSyntax -> SqliteSyntax
fromSqliteFieldNameSyntax SqliteFieldNameSyntax
field SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
"=" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
val) [(Sql92UpdateFieldNameSyntax SqliteUpdateSyntax,
Sql92UpdateExpressionSyntax SqliteUpdateSyntax)]
[(SqliteFieldNameSyntax, SqliteExpressionSyntax)]
fields)) SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteExpressionSyntax -> SqliteSyntax)
-> Maybe SqliteExpressionSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteExpressionSyntax
where_ -> ByteString -> SqliteSyntax
emit ByteString
" WHERE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
where_) Maybe (Sql92UpdateExpressionSyntax SqliteUpdateSyntax)
Maybe SqliteExpressionSyntax
where_
instance IsSql92DeleteSyntax SqliteDeleteSyntax where
type Sql92DeleteTableNameSyntax SqliteDeleteSyntax = SqliteTableNameSyntax
type Sql92DeleteExpressionSyntax SqliteDeleteSyntax = SqliteExpressionSyntax
deleteStmt :: Sql92DeleteTableNameSyntax SqliteDeleteSyntax
-> Maybe Text
-> Maybe (Sql92DeleteExpressionSyntax SqliteDeleteSyntax)
-> SqliteDeleteSyntax
deleteStmt Sql92DeleteTableNameSyntax SqliteDeleteSyntax
tbl Maybe Text
Nothing Maybe (Sql92DeleteExpressionSyntax SqliteDeleteSyntax)
where_ =
SqliteSyntax -> SqliteDeleteSyntax
SqliteDeleteSyntax (SqliteSyntax -> SqliteDeleteSyntax)
-> SqliteSyntax -> SqliteDeleteSyntax
forall a b. (a -> b) -> a -> b
$
ByteString -> SqliteSyntax
emit ByteString
"DELETE FROM " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteTableNameSyntax -> SqliteSyntax
fromSqliteTableName Sql92DeleteTableNameSyntax SqliteDeleteSyntax
SqliteTableNameSyntax
tbl SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>
SqliteSyntax
-> (SqliteExpressionSyntax -> SqliteSyntax)
-> Maybe SqliteExpressionSyntax
-> SqliteSyntax
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SqliteSyntax
forall a. Monoid a => a
mempty (\SqliteExpressionSyntax
where_ -> ByteString -> SqliteSyntax
emit ByteString
" WHERE " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteExpressionSyntax -> SqliteSyntax
fromSqliteExpression SqliteExpressionSyntax
where_) Maybe (Sql92DeleteExpressionSyntax SqliteDeleteSyntax)
Maybe SqliteExpressionSyntax
where_
deleteStmt Sql92DeleteTableNameSyntax SqliteDeleteSyntax
_ (Just Text
_) Maybe (Sql92DeleteExpressionSyntax SqliteDeleteSyntax)
_ =
String -> SqliteDeleteSyntax
forall a. HasCallStack => String -> a
error String
"beam-sqlite: invariant failed: DELETE must not have a table alias"
spaces, parens :: SqliteSyntax -> SqliteSyntax
spaces :: SqliteSyntax -> SqliteSyntax
spaces SqliteSyntax
a = ByteString -> SqliteSyntax
emit ByteString
" " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
" "
parens :: SqliteSyntax -> SqliteSyntax
parens SqliteSyntax
a = ByteString -> SqliteSyntax
emit ByteString
"(" SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> SqliteSyntax
a SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> ByteString -> SqliteSyntax
emit ByteString
")"
commas :: [SqliteSyntax] -> SqliteSyntax
commas :: [SqliteSyntax] -> SqliteSyntax
commas [] = SqliteSyntax
forall a. Monoid a => a
mempty
commas [SqliteSyntax
x] = SqliteSyntax
x
commas (SqliteSyntax
x:[SqliteSyntax]
xs) = SqliteSyntax
x SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<> (SqliteSyntax -> SqliteSyntax) -> [SqliteSyntax] -> SqliteSyntax
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (ByteString -> SqliteSyntax
emit ByteString
", " SqliteSyntax -> SqliteSyntax -> SqliteSyntax
forall a. Semigroup a => a -> a -> a
<>) [SqliteSyntax]
xs
strftimeSyntax :: SqliteExpressionSyntax -> SqliteExpressionSyntax -> [ SqliteExpressionSyntax ] -> SqliteExpressionSyntax
strftimeSyntax :: SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> [SqliteExpressionSyntax]
-> SqliteExpressionSyntax
strftimeSyntax SqliteExpressionSyntax
fmt SqliteExpressionSyntax
ts [SqliteExpressionSyntax]
mods =
SqliteExpressionSyntax
-> [SqliteExpressionSyntax] -> SqliteExpressionSyntax
forall expr.
IsSql99FunctionExpressionSyntax expr =>
expr -> [expr] -> expr
functionCallE (SqliteSyntax -> SqliteExpressionSyntax
SqliteExpressionSyntax (ByteString -> SqliteSyntax
emit ByteString
"strftime"))
(SqliteExpressionSyntax
fmtSqliteExpressionSyntax
-> [SqliteExpressionSyntax] -> [SqliteExpressionSyntax]
forall a. a -> [a] -> [a]
:SqliteExpressionSyntax
tsSqliteExpressionSyntax
-> [SqliteExpressionSyntax] -> [SqliteExpressionSyntax]
forall a. a -> [a] -> [a]
:[SqliteExpressionSyntax]
mods)
sqliteExtract :: ExtractField -> SqliteExpressionSyntax -> SqliteExpressionSyntax
ExtractField
field SqliteExpressionSyntax
from =
case ExtractField
field of
ExtractField
ExtractFieldTimeZoneHour -> String -> SqliteExpressionSyntax
forall a. HasCallStack => String -> a
error String
"sqliteExtract: TODO ExtractFieldTimeZoneHour"
ExtractField
ExtractFieldTimeZoneMinute -> String -> SqliteExpressionSyntax
forall a. HasCallStack => String -> a
error String
"sqliteExtract: TODO ExtractFieldTimeZoneMinute"
ExtractField
ExtractFieldDateTimeYear -> String -> SqliteExpressionSyntax
extractStrftime String
"%Y"
ExtractField
ExtractFieldDateTimeMonth -> String -> SqliteExpressionSyntax
extractStrftime String
"%m"
ExtractField
ExtractFieldDateTimeDay -> String -> SqliteExpressionSyntax
extractStrftime String
"%d"
ExtractField
ExtractFieldDateTimeHour -> String -> SqliteExpressionSyntax
extractStrftime String
"%H"
ExtractField
ExtractFieldDateTimeMinute -> String -> SqliteExpressionSyntax
extractStrftime String
"%M"
ExtractField
ExtractFieldDateTimeSecond -> String -> SqliteExpressionSyntax
extractStrftime String
"%S"
where
extractStrftime :: String -> SqliteExpressionSyntax
extractStrftime :: String -> SqliteExpressionSyntax
extractStrftime String
fmt = SqliteExpressionSyntax
-> SqliteExpressionSyntax
-> [SqliteExpressionSyntax]
-> SqliteExpressionSyntax
strftimeSyntax (Sql92ExpressionValueSyntax SqliteExpressionSyntax
-> SqliteExpressionSyntax
forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (String -> SqliteValueSyntax
forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax String
fmt)) SqliteExpressionSyntax
from []
sqliteSerialType :: SqliteDataTypeSyntax
sqliteSerialType :: SqliteDataTypeSyntax
sqliteSerialType = SqliteSyntax
-> HsDataType
-> BeamSerializedDataType
-> Bool
-> SqliteDataTypeSyntax
SqliteDataTypeSyntax (ByteString -> SqliteSyntax
emit ByteString
"INTEGER PRIMARY KEY AUTOINCREMENT")
HsDataType
forall dataType. IsSql92DataTypeSyntax dataType => dataType
intType
(Value -> BeamSerializedDataType
BeamSerializedDataType (Text -> Value -> Value
beamSerializeJSON Text
"sqlite" Value
"serial"))
Bool
True
instance HasSqlValueSyntax SqliteValueSyntax ByteString where
sqlValueSyntax :: ByteString -> SqliteValueSyntax
sqlValueSyntax ByteString
bs = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (ByteString -> SQLData
SQLBlob ByteString
bs))
instance HasSqlValueSyntax SqliteValueSyntax UTCTime where
sqlValueSyntax :: UTCTime -> SqliteValueSyntax
sqlValueSyntax UTCTime
tm = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (String -> Text
forall a. IsString a => String -> a
fromString String
tmStr)))
where tmStr :: String
tmStr = TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (String -> Maybe String
forall a. a -> Maybe a
Just String
"%H:%M:%S%Q")) UTCTime
tm
instance HasSqlValueSyntax SqliteValueSyntax LocalTime where
sqlValueSyntax :: LocalTime -> SqliteValueSyntax
sqlValueSyntax LocalTime
tm = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (String -> Text
forall a. IsString a => String -> a
fromString String
tmStr)))
where tmStr :: String
tmStr = TimeLocale -> String -> LocalTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (String -> Maybe String
forall a. a -> Maybe a
Just String
"%H:%M:%S%Q")) LocalTime
tm
instance HasSqlValueSyntax SqliteValueSyntax Day where
sqlValueSyntax :: Day -> SqliteValueSyntax
sqlValueSyntax Day
tm = SqliteSyntax -> SqliteValueSyntax
SqliteValueSyntax (SQLData -> SqliteSyntax
emitValue (Text -> SQLData
SQLText (String -> Text
forall a. IsString a => String -> a
fromString String
tmStr)))
where tmStr :: String
tmStr = TimeLocale -> String -> Day -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat Maybe String
forall a. Maybe a
Nothing) Day
tm
instance HasDataTypeCreatedCheck SqliteDataTypeSyntax where
dataTypeHasBeenCreated :: SqliteDataTypeSyntax
-> (forall preCondition. Typeable preCondition => [preCondition])
-> Bool
dataTypeHasBeenCreated SqliteDataTypeSyntax
_ forall preCondition. Typeable preCondition => [preCondition]
_ = Bool
True