module Database.Selda.SQL.Print.Config (PPConfig (..), defPPConfig) where
import Data.Text (Text)
import qualified Data.Text as T
import Database.Selda.SqlType
import Database.Selda.Table
data PPConfig = PPConfig
{
ppType :: SqlTypeRep -> Text
, ppPlaceholder :: Int -> Text
, ppColAttrs :: [ColAttr] -> Text
, ppAutoIncInsert :: Text
, ppMaxInsertParams :: Maybe Int
}
defPPConfig :: PPConfig
defPPConfig = PPConfig
{ ppType = defType
, ppPlaceholder = T.cons '$' . T.pack . show
, ppColAttrs = T.unwords . map defColAttr
, ppAutoIncInsert = "NULL"
, ppMaxInsertParams = Nothing
}
defType :: SqlTypeRep -> Text
defType TText = "TEXT"
defType TRowID = "INTEGER"
defType TInt = "INT"
defType TFloat = "DOUBLE"
defType TBool = "INT"
defType TDateTime = "DATETIME"
defType TDate = "DATE"
defType TTime = "TIME"
defType TBlob = "BLOB"
defColAttr :: ColAttr -> Text
defColAttr Primary = "PRIMARY KEY"
defColAttr AutoIncrement = "AUTOINCREMENT"
defColAttr Required = "NOT NULL"
defColAttr Optional = "NULL"
defColAttr Unique = "UNIQUE"