{-# LANGUAGE FlexibleInstances #-}
module Database.Relational.Internal.String (
StringSQL, stringSQL, showStringSQL,
rowStringSQL, rowPlaceHolderStringSQL,
rowConsStringSQL, listStringSQL,
boolSQL,
) where
import Language.SQL.Keyword (Keyword, word, wordShow, fold, (|*|), paren)
type StringSQL = Keyword
stringSQL :: String -> StringSQL
stringSQL = word
showStringSQL :: StringSQL -> String
showStringSQL = wordShow
rowStringSQL :: [StringSQL] -> StringSQL
rowStringSQL = d where
d [] = error "Record: no columns. empty row is not allowed in SQL."
d [c] = c
d cs = paren $ fold (|*|) cs
rowPlaceHolderStringSQL :: Int -> StringSQL
rowPlaceHolderStringSQL = rowStringSQL . (`replicate` stringSQL "?")
rowConsStringSQL :: [StringSQL] -> StringSQL
rowConsStringSQL = paren . fold (|*|)
listStringSQL :: [StringSQL] -> StringSQL
listStringSQL = paren . fold (|*|)
boolSQL :: Bool -> StringSQL
boolSQL =
stringSQL . d
where
d True = "(0=0)"
d False = "(0=1)"