module Database.Relational.Query.Table (
Table, unType, name, shortName, width, columns, index, table, toMaybe,
TableDerivable (..)
) where
import Data.Array (listArray)
import Database.Record (PersistableWidth)
import Database.Relational.Query.Internal.UntypedTable (Untyped (Untyped), name', width', columns', (!))
import Database.Relational.Query.Internal.SQL (StringSQL, stringSQL, )
newtype Table r = Table Untyped
unType :: Table t -> Untyped
unType (Table u) = u
name :: Table r -> String
name = name' . unType
shortName :: Table r -> String
shortName = tail . dropWhile (/= '.') . name
width :: Table r -> Int
width = width' . unType
columns :: Table r -> [StringSQL]
columns = columns' . unType
index :: Table r
-> Int
-> StringSQL
index = (!) . unType
toMaybe :: Table r -> Table (Maybe r)
toMaybe (Table t) = Table t
table :: String -> [String] -> Table r
table n f = Table $ Untyped n w fa where
w = length f
fa = listArray (0, w 1) $ map stringSQL f
class PersistableWidth r => TableDerivable r where
derivedTable :: Table r