module Database.Persist.Util
( nullable
, IsNullable(..)
, WhyNullable(..)
, deprecate
) where
import System.IO.Unsafe (unsafePerformIO)
import Data.Text
nullable :: [Text] -> IsNullable
nullable s
| "Maybe" `elem` s = Nullable ByMaybeAttr
| "nullable" `elem` s = Nullable ByNullableAttr
| "null" `elem` s = deprecate "Please replace null with Maybe" (Nullable ByMaybeAttr)
| otherwise = NotNullable
data IsNullable = Nullable !WhyNullable
| NotNullable
deriving (Eq, Show)
data WhyNullable = ByMaybeAttr
| ByNullableAttr
deriving (Eq, Show)
deprecate :: String -> a -> a
deprecate s x = unsafePerformIO $ do
putStrLn $ "DEPRECATED: " ++ s
return x