{-# LANGUAGE OverloadedStrings #-}
module Database.Selda.SQL.Print.Config (PPConfig (..), defPPConfig) where
import Data.Text (Text)
import qualified Data.Text as T
import Database.Selda.SqlType ( SqlTypeRep(..) )
import Database.Selda.Table.Type
( IndexMethod, ColAttr(..), AutoIncType(Weak, Strong) )
data PPConfig = PPConfig
{
PPConfig -> SqlTypeRep -> Text
ppType :: SqlTypeRep -> Text
, PPConfig -> SqlTypeRep -> [ColAttr] -> (SqlTypeRep -> Text) -> Text
ppTypeHook :: SqlTypeRep -> [ColAttr] -> (SqlTypeRep -> Text) -> Text
, PPConfig -> SqlTypeRep -> Text
ppTypePK :: SqlTypeRep -> Text
, PPConfig -> Int -> Text
ppPlaceholder :: Int -> Text
, PPConfig -> [ColAttr] -> Text
ppColAttrs :: [ColAttr] -> Text
, PPConfig -> SqlTypeRep -> [ColAttr] -> ([ColAttr] -> Text) -> Text
ppColAttrsHook :: SqlTypeRep -> [ColAttr] -> ([ColAttr] -> Text) -> Text
, PPConfig -> Text
ppAutoIncInsert :: Text
, PPConfig -> Maybe Int
ppMaxInsertParams :: Maybe Int
, PPConfig -> IndexMethod -> Text
ppIndexMethodHook :: IndexMethod -> Text
}
defPPConfig :: PPConfig
defPPConfig :: PPConfig
defPPConfig = PPConfig
{ ppType :: SqlTypeRep -> Text
ppType = SqlTypeRep -> Text
defType
, ppTypeHook :: SqlTypeRep -> [ColAttr] -> (SqlTypeRep -> Text) -> Text
ppTypeHook = \SqlTypeRep
ty [ColAttr]
_ SqlTypeRep -> Text
_ -> SqlTypeRep -> Text
defType SqlTypeRep
ty
, ppTypePK :: SqlTypeRep -> Text
ppTypePK = SqlTypeRep -> Text
defType
, ppPlaceholder :: Int -> Text
ppPlaceholder = Char -> Text -> Text
T.cons Char
'$' forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
, ppColAttrs :: [ColAttr] -> Text
ppColAttrs = [Text] -> Text
T.unwords forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map ColAttr -> Text
defColAttr
, ppColAttrsHook :: SqlTypeRep -> [ColAttr] -> ([ColAttr] -> Text) -> Text
ppColAttrsHook = \SqlTypeRep
_ [ColAttr]
ats [ColAttr] -> Text
_ -> [Text] -> Text
T.unwords forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map ColAttr -> Text
defColAttr [ColAttr]
ats
, ppAutoIncInsert :: Text
ppAutoIncInsert = Text
"NULL"
, ppMaxInsertParams :: Maybe Int
ppMaxInsertParams = forall a. Maybe a
Nothing
, ppIndexMethodHook :: IndexMethod -> Text
ppIndexMethodHook = forall a b. a -> b -> a
const Text
""
}
defType :: SqlTypeRep -> Text
defType :: SqlTypeRep -> Text
defType SqlTypeRep
TText = Text
"TEXT"
defType SqlTypeRep
TRowID = Text
"INTEGER"
defType SqlTypeRep
TInt32 = Text
"INT"
defType SqlTypeRep
TInt64 = Text
"BIGINT"
defType SqlTypeRep
TFloat = Text
"DOUBLE PRECISION"
defType SqlTypeRep
TBool = Text
"BOOLEAN"
defType SqlTypeRep
TDateTime = Text
"DATETIME"
defType SqlTypeRep
TDate = Text
"DATE"
defType SqlTypeRep
TTime = Text
"TIME"
defType SqlTypeRep
TBlob = Text
"BLOB"
defType SqlTypeRep
TUUID = Text
"BLOB"
defType SqlTypeRep
TJSON = Text
"BLOB"
defColAttr :: ColAttr -> Text
defColAttr :: ColAttr -> Text
defColAttr ColAttr
Primary = Text
""
defColAttr (AutoPrimary AutoIncType
Strong) = Text
"PRIMARY KEY AUTOINCREMENT"
defColAttr (AutoPrimary AutoIncType
Weak) = Text
"PRIMARY KEY"
defColAttr ColAttr
Required = Text
"NOT NULL"
defColAttr ColAttr
Optional = Text
"NULL"
defColAttr ColAttr
Unique = Text
"UNIQUE"
defColAttr (Indexed Maybe IndexMethod
_) = Text
""