packages feed

hmemdb 0.3.0.1 → 0.3.1.0

raw patch · 2 files changed

+23/−34 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.HMemDb: cKeys :: Created t r k a -> k (Key t a)
- Data.HMemDb: cTable :: Created t r k a -> Table t r a
+ Data.HMemDb: splitKey :: (ks :+: KeyRef i u) f -> (ks f, f i u)
+ Data.HMemDb: splitRef :: (rs :&: Ref t a u) f -> (rs f, f t a u)
- Data.HMemDb: Created :: Table t r a -> k (Key t a) -> Created t r k a
+ Data.HMemDb: Created :: Table t r a -> k (Key t a) -> Created r k a
- Data.HMemDb: createTable :: (KeysC k, Monad m, MonadSTM m, RefsC r) => Spec r k a -> (forall t. Created t r k a -> m b) -> m b
+ Data.HMemDb: createTable :: (KeysC k, RefsC r) => Spec r k a -> STM (Created r k a)
- Data.HMemDb: data Created t r k a
+ Data.HMemDb: data Created r k a

Files

hmemdb.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                hmemdb
-version:             0.3.0.1
+version:             0.3.1.0
 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
src/Data/HMemDb.hs view
@@ -14,12 +14,12 @@      Spec (Spec, sRefs, sKeys),
 -- ** Foreign table references
      TableRef, only, some,
-     RefsC, Refs (Refs), RefsComponent, Ref, (:&:)((:&:)),
+     RefsC, Refs (Refs), RefsComponent, Ref, (:&:)((:&:)), splitRef,
 -- ** Keys
      KeySpec, single, multiple, single_, multiple_,
-     KeysC, Keys (Keys), KeysComponent, KeyRef, (:+:)((:+:)),
+     KeysC, Keys (Keys), KeysComponent, KeyRef, (:+:)((:+:)), splitKey,
 -- * Table manipulation
-     Created (Created, cTable, cKeys),
+     Created (Created),
      createTable, select, select_, selectBetween, insert, update, update_, delete,
 -- * Persistence
      getTable, getTable_, getTable__,
@@ -122,6 +122,9 @@ -- | Combining operator for key specifications.
 data (ks :+: k) f where (:+:) :: ks f -> f i u -> (ks :+: KeyRef i u) f
 infixl 5 :+:
+-- | Splitting keys.
+splitKey :: (ks :+: KeyRef i u) f -> (ks f, f i u)
+splitKey (ksf :+: fiu) = (ksf, fiu)
 -- | Class of the part of key specification, corresponding to one key.
 class KeysComponent k where
     forKeysComponent
@@ -157,6 +160,9 @@ -- | Combining operator for reference specifications.
 data (rs :&: r) f where (:&:) :: rs f -> f t a u -> (rs :&: Ref t a u) f
 infix 5 :&:
+-- | Splitting references.
+splitRef :: (rs :&: Ref t a u) f -> (rs f, f t a u)
+splitRef (rsf :&: ftau) = (rsf, ftau)
 -- | Class of the part of reference specification, corresponding to one reference.
 class RefsComponent r where
     putRefsComponent
@@ -235,13 +241,8 @@       -- by values of this one.
       sKeys :: k (KeySpec r a) -- ^ Keys for the table-to-be
     }
--- | Output of the 'createTable' function.
-data Created t r k a =
-    Created
-    {
-      cTable :: Table t r a, -- ^ The table itself
-      cKeys :: k (Key t a) -- ^ Keys for the table
-    }
+-- | Output of the 'createTable' function. Contains the created table and the keys to it.
+data Created r k a where Created :: Table t r a -> k (Key t a) -> Created r k a
 data KeyProcess r a i u =
     KeyProcess
     {
@@ -260,29 +261,17 @@     -> m ()
 forKeys_ ks action = forKeys ks (\k -> action k >> return k) >> return ()
 -- | Function that creates the table (along with keys and everything) based on a 'Spec'.
--- Instead of returning the table, it uses continuation-based approach to ensure
--- that there is only one 'Table' with this exact 't' argument,
--- and that this argument doesn't escape.
-createTable
-    :: (KeysC k, Monad m, MonadSTM m, RefsC r) =>
-       Spec r k a
-    -> (forall t. Created t r k a -> m b)
-    -> m b
-createTable s action = liftSTM created >>= action where
-    created =
-        do counter <- newTVar 0
-           tm <- newTVar M.empty
-           tk <-
-               forKeys (sKeys s) $ \ks ->
-                   do kbm <- newTVar M.empty
-                      return KeyBack {kbMap = kbm, kbKey = ksVal ks}
-           let result =
-                   Created
-                   {
-                     cTable = Table PreTable {tMap = tm, tKey = tk} counter,
-                     cKeys = runIdentity $ forKeys tk $ Identity . Key . kbMap
-                   }
-           return result
+createTable :: (KeysC k, RefsC r) => Spec r k a -> STM (Created r k a)
+createTable s = 
+    do counter <- newTVar 0
+       tm <- newTVar M.empty
+       tk <-
+           forKeys (sKeys s) $ \ks ->
+               do kbm <- newTVar M.empty
+                  return KeyBack {kbMap = kbm, kbKey = ksVal ks}
+       let cTable = Table PreTable {tMap = tm, tKey = tk} counter
+           cKeys = runIdentity $ forKeys tk $ Identity . Key . kbMap
+       return $ Created cTable cKeys
 -- | Function that selects one value from a 'Key'.
 -- Note that the value is not returned directly.
 -- Instead, a reference to it is returned, which allows to get other references,