git.iko.soy/purescript-indexed-DB
on master help sign in
add documentation to IDBDatabase
commit5ec6af3d40676283104ca6beb8db307502539336 authorKtorZ <matthias.benkort@gmail.com> dateThu 6 Jul 2017, 14:06 (9 years ago) parente3e8c10
1 file changed+87−20
src/Database/IndexedDB/IDBDatabase.purs+87−20
src/Database/IndexedDB/IDBDatabase.purs+87−20
@@ -1,3 +1,5 @@
1+-- | Each origin has an associated set of databases. A database has zero or more object
2+-- | stores which hold the data stored in the database.
13module Database.IndexedDB.IDBDatabase
24 ( class IDBDatabase, close, createObjectStore, deleteObjectStore, transaction
35 , StoreName
@@ -16,7 +18,7 @@ import Control.Monad.Aff (Aff)
1618import Control.Monad.Eff (Eff)
1719import Control.Monad.Eff.Exception (Error)
1820import Data.Function.Uncurried as Fn
19−import Data.Function.Uncurried (Fn2, Fn3, Fn4)
21+import Data.Function.Uncurried (Fn2, Fn3)
2022
2123import Database.IndexedDB.Core
2224import Database.IndexedDB.IDBObjectStore (IDBObjectStoreParameters)
@@ -25,10 +27,23 @@ import Database.IndexedDB.IDBObjectStore (IDBObjectStoreParameters)
2527--------------------
2628-- INTERFACE
2729--
30+-- | The IDBDatabase interface represents a connection to a database.
2831class IDBDatabase db where
32+ -- | Closes the connection once all running transactions have finished.
2933 close :: forall e. db -> Aff (idb :: IDB | e) Unit
34+
35+ -- | Creates a new object store with the given name and options and returns a new IDBObjectStore.
36+ -- |
37+ -- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction
3038 createObjectStore :: forall e. db -> StoreName -> IDBObjectStoreParameters -> Aff (idb :: IDB | e) ObjectStore
39+
40+ -- | Deletes the object store with the given name.
41+ -- |
42+ -- | Throws a "InvalidStateError" DOMException if not called within an upgrade transaction.
3143 deleteObjectStore :: forall e. db -> StoreName -> Aff (idb :: IDB | e) ObjectStore
44+
45+ -- | Returns a new transaction with the given mode (ReadOnly|ReadWrite)
46+ -- | and scope which in the form of an array of object store names.
3247 transaction :: forall e. db -> Array StoreName -> TransactionMode -> Aff (idb :: IDB | e) Transaction
3348
3449
@@ -38,17 +53,26 @@ type StoreName = String
3853--------------------
3954-- ATTRIBUTES
4055--
41−name :: Database -> String
56+-- | Returns the name of the database.
57+name
58+ :: Database
59+ -> String
4260name =
4361 _name
4462
4563
46−objectStoreNames :: Database -> Array String
64+-- | Returns a list of the names of object stores in the database.
65+objectStoreNames
66+ :: Database
67+ -> Array String
4768objectStoreNames =
4869 _objectStoreNames
4970
5071
51−version :: Database -> Int
72+-- | Returns the version of the database
73+version
74+ :: Database
75+ -> Int
5276version =
5377 _version
5478
@@ -56,27 +80,47 @@ version =
5680--------------------
5781-- EVENT HANDLERS
5882--
59−onAbort :: forall e e'. Database -> Eff ( | e') Unit -> Aff (idb :: IDB | e) Unit
83+-- | Event handler for the `abort` event
84+onAbort
85+ :: forall e e'
86+ . Database
87+ -> Eff ( | e') Unit
88+ -> Aff (idb :: IDB | e) Unit
6089onAbort db f =
6190 Fn.runFn2 _onAbort db f
6291
6392
64−onClose :: forall e e'. Database -> Eff ( | e') Unit -> Aff (idb :: IDB | e) Unit
93+-- | Event handler for the `close` event
94+onClose
95+ :: forall e e'
96+ . Database
97+ -> Eff ( | e') Unit
98+ -> Aff (idb :: IDB | e) Unit
6599onClose db f =
66100 Fn.runFn2 _onClose db f
67101
68102
69−onError :: forall e e'. Database -> (Error -> Eff ( | e') Unit) -> Aff (idb :: IDB | e) Unit
103+-- | Event handler for the `error` event
104+onError
105+ :: forall e e'
106+ . Database
107+ -> (Error -> Eff ( | e') Unit)
108+ -> Aff (idb :: IDB | e) Unit
70109onError db f =
71110 Fn.runFn2 _onError db f
72111
73112
74−onVersionChange :: forall e e'. Database -> ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) -> Aff (idb :: IDB | e) Unit
113+-- | Event handler for the `versionchange` event
114+onVersionChange
115+ :: forall e e'
116+ . Database
117+ -> ({ oldVersion :: Int, newVersion :: Int }
118+ -> Eff ( | e') Unit)
119+ -> Aff (idb :: IDB | e) Unit
75120onVersionChange db f =
76121 Fn.runFn2 _onVersionChange db f
77122
78123
79−
80124--------------------
81125-- INSTANCES
82126--
@@ -97,34 +141,57 @@ instance idbDatabaseDatabase :: IDBDatabase Database where
97141--------------------
98142-- FFI
99143--
100−foreign import _close :: forall db e. db -> Aff (idb :: IDB | e) Unit
144+foreign import _close
145+ :: forall db e
146+ . db
147+ -> Aff (idb :: IDB | e) Unit
101148
102149
103−foreign import _createObjectStore :: forall db e. Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Aff (idb :: IDB | e) ObjectStore)
150+foreign import _createObjectStore
151+ :: forall db e
152+ . Fn3 db String { keyPath :: Array String, autoIncrement :: Boolean } (Aff (idb :: IDB | e) ObjectStore)
104153
105154
106−foreign import _deleteObjectStore :: forall db e. Fn2 db String (Aff (idb :: IDB | e) ObjectStore)
155+foreign import _deleteObjectStore
156+ :: forall db e
157+ . Fn2 db String (Aff (idb :: IDB | e) ObjectStore)
107158
108159
109−foreign import _name :: Database -> String
160+foreign import _name
161+ :: Database
162+ -> String
110163
111164
112−foreign import _objectStoreNames :: Database -> Array String
165+foreign import _objectStoreNames
166+ :: Database
167+ -> Array String
113168
114169
115−foreign import _onAbort :: forall db e e'. Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
170+foreign import _onAbort
171+ :: forall db e e'
172+ . Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
116173
117174
118−foreign import _onClose :: forall db e e'. Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
175+foreign import _onClose
176+ :: forall db e e'
177+ . Fn2 db (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
119178
120179
121−foreign import _onError :: forall db e e'. Fn2 db (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
180+foreign import _onError
181+ :: forall db e e'
182+ . Fn2 db (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
122183
123184
124−foreign import _onVersionChange :: forall db e e'. Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
185+foreign import _onVersionChange
186+ :: forall db e e'
187+ . Fn2 db ({ oldVersion :: Int, newVersion :: Int } -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
125188
126189
127−foreign import _transaction :: forall db e. Fn3 db (Array String) String (Aff (idb :: IDB | e) Transaction)
190+foreign import _transaction
191+ :: forall db e
192+ . Fn3 db (Array String) String (Aff (idb :: IDB | e) Transaction)
128193
129194
130−foreign import _version :: Database -> Int
195+foreign import _version
196+ :: Database
197+ -> Int