hmemdb 0.1.0.0 → 0.1.0.1
raw patch · 10 files changed
+36/−30 lines, 10 filesdep −mtlPVP ok
version bump matches the API change (PVP)
Dependencies removed: mtl
API changes (from Hackage documentation)
Files
- hmemdb.cabal +3/−3
- src/Data/HMemDb/Bin.hs +1/−1
- src/Data/HMemDb/CreateTable.hs +6/−4
- src/Data/HMemDb/ForeignKeys.hs +4/−4
- src/Data/HMemDb/KeyBackends.hs +1/−1
- src/Data/HMemDb/References.hs +1/−1
- src/Data/HMemDb/Specs.hs +8/−8
- src/Data/HMemDb/TableVars.hs +4/−3
- src/Data/HMemDb/Tables.hs +7/−4
- src/Data/HMemDb/Utils.hs +1/−1
hmemdb.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: hmemdb -version: 0.1.0.0 +version: 0.1.0.1 synopsis: In-memory relational database description: Library that provides a sort of relational database in memory (which could be saved to the disk, however). Very untested. license: BSD3 @@ -10,7 +10,7 @@ author: Miguel Mitrofanov maintainer: miguelimo38@yandex.ru -- copyright: -category: Data +category: Data, Database build-type: Simple cabal-version: >=1.8 @@ -29,5 +29,5 @@ Data.HMemDb.CreateTable, Data.HMemDb.Binary, Data.HMemDb.Bin - build-depends: base ==4.6.*, TypeCompose ==0.9.*, mtl ==2.1.*, transformers ==0.3.*, stm ==2.4.*, containers ==0.5.*, binary ==0.5.* + build-depends: base ==4.6.*, TypeCompose ==0.9.*, transformers ==0.3.*, stm ==2.4.*, containers ==0.5.*, binary ==0.5.* hs-source-dirs: src
src/Data/HMemDb/Bin.hs view
@@ -9,7 +9,7 @@ import Control.Applicative (liftA2, (<$>)) import Control.Compose (Id, unId, (:.)) import Control.Concurrent.STM (TVar, readTVar) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Data.Binary (Binary(get, put), Get, Put) import qualified Data.Map as M (Map, lookup) import Data.HMemDb.Binary (MS)
src/Data/HMemDb/CreateTable.hs view
@@ -15,7 +15,7 @@ makeRC, (:+:)((:+:))) import Data.HMemDb.Tables (PreTable(PreTable, tabContent, tabConv, tabCount, tabIndices), Table(Table)) --- | This is a class of sets of @KeySpec@'s and @ForeignKey@'s +-- | This is a class of sets of 'Data.HMemDb.KeySpec's and 'Data.HMemDb.ForeignKey's class CreateTable u where makeTable :: Bin r => PreRefConv r a a -> u a KeySpec -> STM (PreTable r a, u a ForeignKey) @@ -43,9 +43,11 @@ instance (CreateTable u, IsKeySpec ks) => CreateTable (u :+: ks) where makeTable = makeTableKS createTable :: CreateTable u => FullSpec a u -> STM (Table a, u a ForeignKey) --- ^ This function creates an empty table, given the table structure (@TableSpec@) --- and the set of keys (@KeySpec@). +-- ^ This function creates an empty table, +-- given the table structure ('Data.HMemDb.TableSpec') +-- and the set of keys ('Data.HMemDb.KeySpec'). -- It returns the table itself, accompanied with the same set of foreign keys, --- allowing one to search through the table quickly, or to make a new @TableSpec@. +-- allowing one to search through the table quickly, +-- or to make a new 'Data.HMemDb.TableSpec'. createTable (FullSpec {tabSpec = TableSpec cs, keySpec = ks}) = case makeRC cs of RefConv _ pr -> first Table <$> makeTable pr ks
src/Data/HMemDb/ForeignKeys.hs view
@@ -4,7 +4,7 @@ import Control.Compose (Id, unId) import Control.Concurrent.STM (STM, TVar, readTVar) import Control.Monad (void) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Maybe (runMaybeT) import Data.Foldable (Foldable) import qualified Data.Map as M (Map, lookup) @@ -16,8 +16,8 @@ import Data.HMemDb.TableVars (TableVarS(TableVar), deleteTV, forTV, modifyTV) import Data.HMemDb.Utils (liftMaybe) -- | This is a type of foreign keys. Each foreign key points to one table. --- It is used to find the values in this table using @select@. --- Foreign keys are created at the same time @Table@'s are. +-- It is used to find the values in this table using 'select'. +-- Foreign keys are created at the same time 'Table's are. -- They can't be added afterwards. data ForeignKey s i a where ForeignKey :: @@ -27,7 +27,7 @@ select :: Ord i => ForeignKey s i a -> i -> MS (TableVarS s a) -- ^ This function searches for some particular index in the table. -- It fails if there is no value with that index. Empty set of values is never returned. --- For non-unique indices it returns the set of @TableVar@'s. +-- For non-unique indices it returns the set of 'Data.HMemDb.TableVar's. select (ForeignKey pt tv) i = do mp <- lift $ readTVar tv s <- liftMaybe $ M.lookup i mp
src/Data/HMemDb/KeyBackends.hs view
@@ -9,7 +9,7 @@ ) where import Control.Concurrent.STM (STM, TVar, modifyTVar', readTVar, writeTVar) import Control.Monad (guard, void) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Cont (ContT(runContT)) import Control.Monad.Trans.Maybe (runMaybeT) import Data.Foldable (for_)
src/Data/HMemDb/References.hs view
@@ -2,7 +2,7 @@ module Data.HMemDb.References (CRef(CRef), Ref(Ref, refContent, refIndex), deCRef, deRef) where import Control.Concurrent.STM (TVar, readTVar) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Data.Function (on) import Data.HMemDb.Binary (MS) import Data.HMemDb.Utils (liftMaybe)
src/Data/HMemDb/Specs.hs view
@@ -22,7 +22,7 @@ import Data.HMemDb.RefConverter (PreRefConv(PreRefConv, rcFrom, rcTo), RefConv(RefConv)) import Data.HMemDb.References (deCRef) import Data.HMemDb.Tables (Table(Table), tabContent, tabConv) --- | This is the internal of the @TableSpec@ type. +-- | This is the internal of the 'TableSpec' type. data ColSpec input output where CSEnd :: output -> ColSpec input output CSVal :: @@ -48,12 +48,12 @@ -- It instructs the library to store one part of the value. val h = CSVal h $ pure id key :: Ord i => ForeignKey Id i col -> (input -> i) -> ColSpec input col --- ^ This function specifies one column in the table. Unlike @val@, it doesn't +-- ^ This function specifies one column in the table. Unlike 'val', it doesn't -- store some part of the value; instead it stores the reference to some other table. key k h = CSKey h k $ pure id newtype TableSpec a = TableSpec (ColSpec a a) -- ^ This type represents the table structure. It can be generated using the --- @Applicative@ interface of the @ColSpec@ like this: +-- 'Applicative' interface of the 'ColSpec' like this: -- -- > data MyData = {myField1 :: Integer, myField2 :: String} -- > tabSpec = TableSpec (MyData <$> val myField1 <*> val myField2) @@ -70,7 +70,7 @@ in makeRC c <*> RefConv (TRVar $ tgd) (PreRefConv {rcFrom = getCRef f . g, rcTo = deCRef}) data KeySpec (s :: * -> *) i a = KeySpec (a -> i) --- ^ This is the specification of one @ForeignKey@. It could be unique or non-unique. +-- ^ This is the specification of one 'ForeignKey'. It could be unique or non-unique. unique :: (a -> i) -> KeySpec Id i a -- ^ This function specifies a unique key. unique = KeySpec @@ -78,10 +78,10 @@ -- ^ This function specifies a non-unique key. nonunique = KeySpec data Keys a (h :: (* -> *) -> * -> * -> *) = Keys --- ^ This type represents an empty set of @KeySpec@'s or @ForeignKey@'s. +-- ^ This type represents an empty set of 'KeySpec's or 'ForeignKey's. data (u :+: ks) a h where (:+:) :: u a h -> h s i a -> (u :+: KeySpec s i) a h --- ^ This type operator adds one more @KeySpec@ to the set, --- or to get a @ForeignKey@ back with pattern-matching. Use it like this: +-- ^ This type operator adds one more 'KeySpec' to the set, +-- or allows to get a 'ForeignKey' back with pattern-matching. Use it like this: -- -- > do (table, ... :+: foreignKey) -- > <- createTable $ FullSpec {..., keySpec = ... :+: unique myKey} @@ -89,4 +89,4 @@ infixl 4 :+: data FullSpec a u = FullSpec {tabSpec :: TableSpec a, keySpec :: u a KeySpec} -- ^ This is the full specification, of both table and set of keys, --- which should be fed to @createTable@ and @getTable@ functions. +-- which should be fed to 'Data.HMemDb.createTable' and 'Data.HMemDb.getTable' functions.
src/Data/HMemDb/TableVars.hs view
@@ -15,7 +15,7 @@ TableVar :: s (Ref r) -> PreTable r a -> TableVarS s a type TableVar = TableVarS Id -- ^ This type represents references to individual values in the table. --- It is returned by @insert@ and @select@ functions. +-- It is returned by 'insert' and 'Data.HMemDb.select' functions. readTV :: TableVar a -> MS a -- ^ This function reads the value from the table. -- It fails if the value was removed before or became invalid. @@ -26,7 +26,8 @@ deleteTV :: TableVar a -> MS a -- ^ This function removes the value from whatever table it's in. -- It returnes the original value, provided that it wasn't removed before --- or invalidated by removing some other value this one references with @ForeignKey@. +-- or invalidated by removing some other value this one references +-- with 'Data.HMemDb.ForeignKey'. deleteTV (TableVar iref pt) = deleteFromTable (unId iref) pt modifyTV :: a -> TableVar a -> MS a -- ^ This function overrides the value with another one. @@ -34,7 +35,7 @@ -- It fails if the original value was removed before or became invalid. modifyTV new (TableVar iref pt) = modifyInTable new (unId iref) pt insert :: a -> Table a -> MS (TableVar a) --- ^ This function inserts a new value into the table and gives a @TableVar@ back. +-- ^ This function inserts a new value into the table and gives a 'TableVar' back. -- Failure indicates that one of the unique indices for this value -- coincides with the same index of another value already present in the table. -- It won't happen for non-unique indices.
src/Data/HMemDb/Tables.hs view
@@ -9,7 +9,7 @@ modifyInTable ) where import Control.Concurrent.STM (TVar, modifyTVar', newTVar, readTVar, writeTVar) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Maybe (runMaybeT) import qualified Data.Map as M (Map, delete, insert) import Data.HMemDb.Bin (Bin) @@ -28,10 +28,13 @@ } data Table a where Table :: Bin r => PreTable r a -> Table a -- ^ This type represent tables. Each table is the set of values. --- Individual values can be accessed with @TableVar@'s or @ForeignKey@'s. +-- Individual values can be accessed with 'Data.HMemDb.TableVar's +-- or 'Data.HMemDb.ForeignKey's. -- Tables are never created manually, --- they should be generated by @createTable@ or loaded by @getTable@. --- Both functions require the structure of the table to be described as the @FullSpec@. +-- they should be generated by 'Data.HMemDb.createTable' +-- or loaded by 'Data.HMemDb.getTable'. +-- Both functions require the structure of the table to be described +-- as the 'Data.HMemDb.FullSpec'. insertTVarIntoTable :: a -> Integer -> TVar (Maybe r) -> PreTable r a -> MS (Ref r) insertTVarIntoTable a n tv pt = do let ref = Ref {refContent = tv, refIndex = n}
src/Data/HMemDb/Utils.hs view
@@ -13,7 +13,7 @@ ) where import Control.Applicative (Applicative(pure), (<$>), (<*>)) import Control.Compose (oFmap, oPure, unO, (:.)(O)) -import Control.Monad.Trans (lift) +import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Cont (Cont, ContT(ContT), cont) import Control.Monad.Trans.Maybe (MaybeT(MaybeT, runMaybeT)) import Data.Foldable (Foldable, for_)