-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | In-memory storage with multiple keys using lenses and traversals -- -- In-memory storage with multiple keys using lenses and traversals -- -- For a quick tour, see https://github.com/ekmett/tables#examples @package tables @version 0.1 -- | This module provides tables with multiple indices that support a -- simple API based on the lenses and traversals from the lens -- package. module Data.Table -- | Every Table has a Primary key and may have -- Candidate, Supplemental or Inverted keys, plus -- their variants. data Table t EmptyTable :: Table t Table :: Tab t (AnIndex t) -> Table t -- | This class describes how to index a user-defined data type. class Ord (PKT t) => Tabular (t :: *) where type family PKT t data family Tab t m data family Key (k :: *) t :: * -> * autoTab _ = Nothing fetch :: Tabular t => Key k t a -> t -> a primary :: Tabular t => Key Primary t (PKT t) primarily :: Tabular t => Key Primary t a -> (a ~ PKT t => r) -> r mkTab :: (Tabular t, Applicative h) => (forall k a. IsKeyType k a => Key k t a -> h (i k a)) -> h (Tab t i) ixTab :: Tabular t => Tab t i -> Key k t a -> i k a forTab :: (Tabular t, Applicative h) => Tab t i -> (forall k a. IsKeyType k a => Key k t a -> i k a -> h (j k a)) -> h (Tab t j) autoTab :: Tabular t => t -> Maybe (Tab t (AnIndex t) -> t) -- | Construct an empty relation empty :: Table t -- | Construct a relation with a single row singleton :: Tabular t => t -> Table t -- | Convert a list to and from a Table. -- -- The real isomorphism laws hold if the original list makes no use of -- the auto-increment functionality of the table, has no duplicates and -- is sorted according to the primary key. -- -- However, -- --
-- from table . table ≡ id ---- -- always holds. table :: Tabular t => Iso' [t] (Table t) -- | Build up a table from a list fromList :: Tabular t => [t] -> Table t -- | Check to see if the relation is empty null :: Table t -> Bool -- | Retrieve a row count. count :: Table t -> Int class With q t | q -> t where deleteWith p cmp a t = set (with p cmp a) empty t with :: (With q t, Ord a) => q a -> (forall x. Ord x => x -> x -> Bool) -> a -> Lens' (Table t) (Table t) deleteWith :: (With q t, Ord a) => q a -> (forall x. Ord x => x -> x -> Bool) -> a -> Table t -> Table t -- | Search inverted indices class Withal q s t | q -> s t where deleteWithAny p as t = set (withAny p as) empty t deleteWithAll p as t = set (withAll p as) empty t withAny :: Withal q s t => q -> s -> Lens' (Table t) (Table t) withAll :: Withal q s t => q -> s -> Lens' (Table t) (Table t) deleteWithAny :: Withal q s t => q -> s -> Table t -> Table t deleteWithAll :: Withal q s t => q -> s -> Table t -> Table t class Group f q t i | q -> t i group :: (Group f q t i, Ord i) => q -> IndexedLensLike' i f (Table t) (Table t) -- | Insert a row into a relation, removing collisions. insert :: Tabular t => t -> Table t -> Table t -- | Delete this row from the database. This will remove any row that -- collides with the specified row on any primary or candidate key. delete :: t -> Table t -> Table t -- | Traverse all of the rows in a table, potentially changing table types -- completely. rows :: Tabular t => Traversal (Table s) (Table t) s t -- | Traverse all of the rows in a table without changing any types rows' :: Traversal' (Table t) t data Auto a Auto :: !Int -> a -> Auto a autoKey :: Lens' (Auto a) Int -- | Generate a row with an auto-incremented key auto :: a -> Auto a -- | This lets you define autoKey to increment to 1 greater than the -- existing maximum key in a table. -- -- In order to support this you need a numeric primary key, and the -- ability to update the primary key in a record, indicated by a lens to -- the field. -- -- To enable auto-increment for a table with primary key -- primaryKeyField, set: -- --
-- autoKey = autoIncrement primaryKeyField --autoIncrement :: (Tabular t, PKT t ~ Int) => ALens' t Int -> t -> Maybe (Tab t (AnIndex t) -> t) class IsKeyType k a keyType :: IsKeyType k a => Key k t a -> KeyType k a -- | Value-level key types data KeyType t a Primary :: KeyType Primary a Candidate :: KeyType Candidate a CandidateInt :: KeyType CandidateInt Int CandidateHash :: KeyType CandidateHash a Supplemental :: KeyType Supplemental a SupplementalInt :: KeyType SupplementalInt Int SupplementalHash :: KeyType SupplementalHash a Inverted :: KeyType Inverted (Set a) InvertedInt :: KeyType InvertedInt IntSet InvertedHash :: KeyType InvertedHash (HashSet a) -- | Type level key types data Primary data Candidate data CandidateInt data CandidateHash data Supplemental data SupplementalInt data SupplementalHash data Inverted data InvertedInt data InvertedHash -- | This is used to store a single index. data AnIndex t k a PrimaryMap :: Map (PKT t) t -> AnIndex t Primary a CandidateIntMap :: IntMap t -> AnIndex t CandidateInt Int CandidateHashMap :: HashMap a t -> AnIndex t CandidateHash a CandidateMap :: Map a t -> AnIndex t Candidate a InvertedIntMap :: IntMap [t] -> AnIndex t InvertedInt IntSet InvertedHashMap :: HashMap a [t] -> AnIndex t InvertedHash (HashSet a) InvertedMap :: Map a [t] -> AnIndex t Inverted (Set a) SupplementalIntMap :: IntMap [t] -> AnIndex t SupplementalInt Int SupplementalHashMap :: HashMap a [t] -> AnIndex t SupplementalHash a SupplementalMap :: Map a [t] -> AnIndex t Supplemental a instance Typeable1 Table instance Typeable1 Auto instance Typeable1 Value instance Eq a => Eq (Auto a) instance Ord a => Ord (Auto a) instance Show a => Show (Auto a) instance Read a => Read (Auto a) instance Functor Auto instance Foldable Auto instance Traversable Auto instance Data a => Data (Auto a) instance Eq a => Eq (Value a) instance Ord a => Ord (Value a) instance Show a => Show (Value a) instance Read a => Read (Value a) instance Functor Value instance Foldable Value instance Traversable Value instance Data a => Data (Value a) instance Ord a => Tabular (Value a) instance (Profunctor p, Functor f, p ~ q) => HasValue p q f (Value a) (Value b) a b instance ComonadApply Value instance Comonad Value instance MonadFix Value instance Monad Value instance Applicative Value instance Wrapped a b (Value a) (Value b) instance Functor f => Ixed f (Value a) instance Gettable f => Contains f (Value a) instance Functor f => Each f (Value a) (Value b) a b instance Field1 (Value a) (Value b) a b instance Ord a => Tabular (Identity a) instance (Profunctor p, Functor f, p ~ q) => HasValue p q f (Identity a) (Identity b) a b instance Ord k => Tabular (k, v) instance (Indexable k p, q ~ (->), Functor f) => HasValue p q f (k, a) (k, b) a b instance Tabular (Auto a) instance Comonad Auto instance TraversableWithIndex Int Auto instance FoldableWithIndex Int Auto instance FunctorWithIndex Int Auto instance (Indexable Int p, q ~ (->), Functor f) => HasValue p q f (Auto a) (Auto b) a b instance (a ~ Int, b ~ Int, Applicative f) => Each f (Auto a) (Auto b) a b instance Field2 (Auto a) (Auto b) a b instance Field1 (Auto a) (Auto a) Int Int instance (Eq a, Hashable a) => IsKeyType InvertedHash (HashSet a) instance a ~ [Int] => IsKeyType InvertedInt IntSet instance Ord a => IsKeyType Inverted (Set a) instance (Eq a, Hashable a) => IsKeyType SupplementalHash a instance a ~ Int => IsKeyType SupplementalInt a instance Ord a => IsKeyType Supplemental a instance (Eq a, Hashable a) => IsKeyType CandidateHash a instance a ~ Int => IsKeyType CandidateInt a instance Ord a => IsKeyType Candidate a instance Ord a => IsKeyType Primary a instance With (Key SupplementalHash t) t instance With (Key SupplementalInt t) t instance With (Key Supplemental t) t instance With (Key CandidateHash t) t instance With (Key CandidateInt t) t instance With (Key Candidate t) t instance With (Key Primary t) t instance With ((->) t) t instance (Eq a, Hashable a) => Withal (Key InvertedHash t (HashSet a)) [a] t instance Withal (Key InvertedInt t IntSet) [Int] t instance Ord a => Withal (Key Inverted t (Set a)) [a] t instance Ord a => Withal (t -> [a]) [a] t instance (Applicative f, Gettable f) => Group f (Key InvertedHash t (HashSet a)) t a instance (Applicative f, Gettable f, a ~ Int) => Group f (Key InvertedInt t IntSet) t a instance (Applicative f, Gettable f) => Group f (Key Inverted t (Set a)) t a instance Applicative f => Group f (Key SupplementalHash t a) t a instance (Applicative f, a ~ Int) => Group f (Key SupplementalInt t a) t a instance Applicative f => Group f (Key Supplemental t a) t a instance Applicative f => Group f (Key CandidateHash t a) t a instance (Applicative f, a ~ Int) => Group f (Key CandidateInt t a) t a instance Applicative f => Group f (Key Candidate t a) t a instance Applicative f => Group f (Key Primary t a) t a instance Applicative f => Group f (t -> a) t a instance (Tabular b, Applicative f, PKT a ~ PKT b) => Each f (Table a) (Table b) a b instance Tabular t => At (Table t) instance Applicative f => Ixed f (Table t) instance Gettable f => Contains f (Table t) instance Foldable Table instance (Tabular t, Read t) => Read (Table t) instance Show t => Show (Table t) instance Ord t => Ord (Table t) instance Eq t => Eq (Table t) instance Monoid (Table t) instance (Tabular t, Data t) => Data (Table t)