@@ -1,12 +1,15 @@
1+-- | Database objects are accessed through methods on the IDBFactory interface.
2+-- | A single object implementing this interface is present in the global scope
3+-- | of environments that support Indexed DB operations.
14module Database.IndexedDB.IDBFactory where
25
3−import Prelude (Unit)
6+import Prelude (Unit)
47
5−import Control.Monad.Aff (Aff)
6−import Control.Monad.Eff (Eff)
7−import Data.Function.Uncurried as Fn
8−import Data.Function.Uncurried (Fn4)
9−import Data.Maybe (Maybe, fromMaybe)
8+import Control.Monad.Aff (Aff)
9+import Control.Monad.Eff (Eff)
10+import Data.Function.Uncurried as Fn
11+import Data.Function.Uncurried (Fn4)
12+import Data.Maybe (Maybe, fromMaybe)
1013
1114import Database.IndexedDB.Core
1215
@@ -14,18 +17,46 @@ import Database.IndexedDB.Core
1417--------------------
1518-- INTERFACE
1619--
20+-- Type alias for binding listeners to an initial open action
1721type OpenRequest e =
1822 { onBlocked :: Maybe (Eff (| e) Unit)
1923 , onUpgradeNeeded :: Maybe (Database -> Transaction -> Eff (| e) Unit)
2024 }
2125
2226
23−deleteDatabase :: forall e. String -> Aff (idb :: IDB | e) Int
27+-- | Type alias for DatabaseName
28+type DatabaseName = String
29+
30+
31+-- | Type alias for Version
32+type Version = Int
33+
34+
35+-- | Attempts to delete the named database. If the database already exists
36+-- | and there are open connections that don’t close in response to a
37+-- | `versionchange` event, the request will be blocked until all they close.
38+deleteDatabase
39+ :: forall e
40+ . DatabaseName
41+ -> Aff (idb :: IDB | e) Int
2442deleteDatabase =
2543 _deleteDatabase
2644
2745
28−open :: forall e e'. String -> Maybe Int -> OpenRequest e' -> Aff (idb :: IDB | e) Database
46+-- | Attempts to open a connection to the named database with the specified version.
47+-- | If the database already exists with a lower version and there are open connections
48+-- | that don’t close in response to a versionchange event, the request will be blocked
49+-- | until all they close, then an upgrade will occur. If the database already exists with
50+-- | a higher version the request will fail.
51+-- |
52+-- | When the version isn't provided (`Nothing`), attempts to open a connection to the
53+-- | named database with the current version, or 1 if it does not already exist.
54+open
55+ :: forall e e'
56+ . DatabaseName
57+ -> Maybe Version
58+ -> OpenRequest e'
59+ -> Aff (idb :: IDB | e) Database
2960open name mver req =
3061 Fn.runFn4 _open fromMaybe name mver req
3162
@@ -33,7 +64,12 @@ open name mver req =
3364--------------------
3465-- FFI
3566--
36−foreign import _deleteDatabase :: forall e. String -> Aff (idb :: IDB | e) Int
67+foreign import _deleteDatabase
68+ :: forall e
69+ . String
70+ -> Aff (idb :: IDB | e) Int
3771
3872
39−foreign import _open :: forall a e e'. Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest e') (Aff (idb :: IDB | e) Database)
73+foreign import _open
74+ :: forall a e e'
75+ . Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest e') (Aff (idb :: IDB | e) Database)