module Database.Selda.Table.Type where
import Database.Selda.SqlType (SqlTypeRep)
import Database.Selda.SQL (SQL)
import Database.Selda.Types ( TableName, ColName )
import Database.Selda.Exp ( UntypedCol )
data Table a = Table
{
forall a. Table a -> TableName
tableName :: TableName
, forall a. Table a -> [ColInfo]
tableCols :: [ColInfo]
, forall a. Table a -> Bool
tableHasAutoPK :: Bool
, forall a. Table a -> [([Int], ColAttr)]
tableAttrs :: [([Int], ColAttr)]
}
data ColInfo = ColInfo
{ ColInfo -> ColName
colName :: ColName
, ColInfo -> SqlTypeRep
colType :: SqlTypeRep
, ColInfo -> [ColAttr]
colAttrs :: [ColAttr]
, ColInfo -> [(Table (), ColName)]
colFKs :: [(Table (), ColName)]
, ColInfo -> UntypedCol SQL
colExpr :: UntypedCol SQL
}
data AutoIncType = Weak | Strong
deriving (Int -> AutoIncType -> ShowS
[AutoIncType] -> ShowS
AutoIncType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoIncType] -> ShowS
$cshowList :: [AutoIncType] -> ShowS
show :: AutoIncType -> String
$cshow :: AutoIncType -> String
showsPrec :: Int -> AutoIncType -> ShowS
$cshowsPrec :: Int -> AutoIncType -> ShowS
Show, AutoIncType -> AutoIncType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoIncType -> AutoIncType -> Bool
$c/= :: AutoIncType -> AutoIncType -> Bool
== :: AutoIncType -> AutoIncType -> Bool
$c== :: AutoIncType -> AutoIncType -> Bool
Eq, Eq AutoIncType
AutoIncType -> AutoIncType -> Bool
AutoIncType -> AutoIncType -> Ordering
AutoIncType -> AutoIncType -> AutoIncType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AutoIncType -> AutoIncType -> AutoIncType
$cmin :: AutoIncType -> AutoIncType -> AutoIncType
max :: AutoIncType -> AutoIncType -> AutoIncType
$cmax :: AutoIncType -> AutoIncType -> AutoIncType
>= :: AutoIncType -> AutoIncType -> Bool
$c>= :: AutoIncType -> AutoIncType -> Bool
> :: AutoIncType -> AutoIncType -> Bool
$c> :: AutoIncType -> AutoIncType -> Bool
<= :: AutoIncType -> AutoIncType -> Bool
$c<= :: AutoIncType -> AutoIncType -> Bool
< :: AutoIncType -> AutoIncType -> Bool
$c< :: AutoIncType -> AutoIncType -> Bool
compare :: AutoIncType -> AutoIncType -> Ordering
$ccompare :: AutoIncType -> AutoIncType -> Ordering
Ord)
data ColAttr
= Primary
| AutoPrimary AutoIncType
| Required
| Optional
| Unique
| Indexed (Maybe IndexMethod)
deriving (Int -> ColAttr -> ShowS
[ColAttr] -> ShowS
ColAttr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColAttr] -> ShowS
$cshowList :: [ColAttr] -> ShowS
show :: ColAttr -> String
$cshow :: ColAttr -> String
showsPrec :: Int -> ColAttr -> ShowS
$cshowsPrec :: Int -> ColAttr -> ShowS
Show, ColAttr -> ColAttr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColAttr -> ColAttr -> Bool
$c/= :: ColAttr -> ColAttr -> Bool
== :: ColAttr -> ColAttr -> Bool
$c== :: ColAttr -> ColAttr -> Bool
Eq, Eq ColAttr
ColAttr -> ColAttr -> Bool
ColAttr -> ColAttr -> Ordering
ColAttr -> ColAttr -> ColAttr
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ColAttr -> ColAttr -> ColAttr
$cmin :: ColAttr -> ColAttr -> ColAttr
max :: ColAttr -> ColAttr -> ColAttr
$cmax :: ColAttr -> ColAttr -> ColAttr
>= :: ColAttr -> ColAttr -> Bool
$c>= :: ColAttr -> ColAttr -> Bool
> :: ColAttr -> ColAttr -> Bool
$c> :: ColAttr -> ColAttr -> Bool
<= :: ColAttr -> ColAttr -> Bool
$c<= :: ColAttr -> ColAttr -> Bool
< :: ColAttr -> ColAttr -> Bool
$c< :: ColAttr -> ColAttr -> Bool
compare :: ColAttr -> ColAttr -> Ordering
$ccompare :: ColAttr -> ColAttr -> Ordering
Ord)
isAutoPrimary :: ColAttr -> Bool
isAutoPrimary :: ColAttr -> Bool
isAutoPrimary (AutoPrimary AutoIncType
_) = Bool
True
isAutoPrimary ColAttr
_ = Bool
False
isPrimary :: ColAttr -> Bool
isPrimary :: ColAttr -> Bool
isPrimary ColAttr
Primary = Bool
True
isPrimary ColAttr
attr = ColAttr -> Bool
isAutoPrimary ColAttr
attr
isUnique :: ColAttr -> Bool
isUnique :: ColAttr -> Bool
isUnique ColAttr
Unique = Bool
True
isUnique (Indexed Maybe IndexMethod
_) = Bool
True
isUnique ColAttr
attr = ColAttr -> Bool
isPrimary ColAttr
attr
data IndexMethod
= BTreeIndex
| HashIndex
deriving (Int -> IndexMethod -> ShowS
[IndexMethod] -> ShowS
IndexMethod -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IndexMethod] -> ShowS
$cshowList :: [IndexMethod] -> ShowS
show :: IndexMethod -> String
$cshow :: IndexMethod -> String
showsPrec :: Int -> IndexMethod -> ShowS
$cshowsPrec :: Int -> IndexMethod -> ShowS
Show, IndexMethod -> IndexMethod -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndexMethod -> IndexMethod -> Bool
$c/= :: IndexMethod -> IndexMethod -> Bool
== :: IndexMethod -> IndexMethod -> Bool
$c== :: IndexMethod -> IndexMethod -> Bool
Eq, Eq IndexMethod
IndexMethod -> IndexMethod -> Bool
IndexMethod -> IndexMethod -> Ordering
IndexMethod -> IndexMethod -> IndexMethod
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IndexMethod -> IndexMethod -> IndexMethod
$cmin :: IndexMethod -> IndexMethod -> IndexMethod
max :: IndexMethod -> IndexMethod -> IndexMethod
$cmax :: IndexMethod -> IndexMethod -> IndexMethod
>= :: IndexMethod -> IndexMethod -> Bool
$c>= :: IndexMethod -> IndexMethod -> Bool
> :: IndexMethod -> IndexMethod -> Bool
$c> :: IndexMethod -> IndexMethod -> Bool
<= :: IndexMethod -> IndexMethod -> Bool
$c<= :: IndexMethod -> IndexMethod -> Bool
< :: IndexMethod -> IndexMethod -> Bool
$c< :: IndexMethod -> IndexMethod -> Bool
compare :: IndexMethod -> IndexMethod -> Ordering
$ccompare :: IndexMethod -> IndexMethod -> Ordering
Ord)