git.iko.soy/purescript-indexed-DB
on master help sign in
add documentation to IDBTransaction + complete db and objectStoreNames accessor
commitcd93ad676ebe1eee70c4991766a62ee1100843ff authorKtorZ <matthias.benkort@gmail.com> dateThu 6 Jul 2017, 15:17 (9 years ago) parent6f7562f
2 files changed+91−14
src/Database/IndexedDB/IDBTransaction.js+8 src/Database/IndexedDB/IDBTransaction.purs+83−14
src/Database/IndexedDB/IDBTransaction.js+8
@@ -9,6 +9,10 @@ exports._abort = function _abort(tx) {
99 };
1010};
1111
12+exports._db = function _db(tx) {
13+ return tx.db;
14+};
15+
1216exports._error = function _error(tx) {
1317 return tx.error == null
1418 ? null
@@ -36,6 +40,10 @@ exports._objectStore = function _objectStore(tx, name) {
3640 };
3741};
3842
43+exports._objectStoreNames = function _objectStoreNames(tx) {
44+ return tx.objectStoreNames;
45+};
46+
3947exports._onAbort = function _onAbort(tx, f) {
4048 return function aff(success) {
4149 tx.onabort = function onabort() {
src/Database/IndexedDB/IDBTransaction.purs+83−14
@@ -1,3 +1,5 @@
1+-- | A Transaction is used to interact with the data in a database.
2+-- | Whenever data is read or written to the database it is done by using a transaction.
13module Database.IndexedDB.IDBTransaction
24 (class IDBTransaction, abort, objectStore
35 , error
@@ -17,44 +19,86 @@ import Data.Function.Uncurried (Fn2, Fn4)
1719import Data.Maybe (Maybe)
1820import Data.Nullable (Nullable, toMaybe)
1921
20−import Database.IndexedDB.Core (IDB, ObjectStore, Transaction, TransactionMode(..))
22+import Database.IndexedDB.Core (IDB, Database, ObjectStore, Transaction, TransactionMode(..))
2123
2224
2325--------------------
2426-- INTERFACES
2527--
28+-- | The IDBtransaction interface.
2629class IDBTransaction tx where
30+ -- | Aborts the transaction. All pending requests will fail with a "AbortError"
31+ -- | DOMException and all changes made to the database will be reverted.
2732 abort :: forall e. tx -> Aff (idb :: IDB | e) Unit
33+
34+ -- | Returns an IDBObjectStore in the transaction's scope.
2835 objectStore :: forall e. tx -> String -> Aff (idb :: IDB | e) ObjectStore
2936
3037
3138--------------------
3239-- ATTRIBUTES
3340--
34−error :: Transaction -> Maybe Error
41+-- | Returns the transaction’s connection.
42+db
43+ :: Transaction
44+ -> Database
45+db =
46+ _db
47+
48+
49+-- | If the transaction was aborted, returns the error (a DOMException) providing the reason.
50+error
51+ :: Transaction
52+ -> Maybe Error
3553error =
3654 _error >>> toMaybe
3755
38−
39−mode :: Transaction -> TransactionMode
56+-- | Returns the mode the transaction was created with (`ReadOnly|ReadWrite`)
57+-- | , or `VersionChange` for an upgrade transaction.
58+mode
59+ :: Transaction
60+ -> TransactionMode
4061mode =
4162 Fn.runFn4 _mode ReadOnly ReadWrite VersionChange
4263
4364
65+-- | Returns a list of the names of object stores in the transaction’s scope.
66+-- | For an upgrade transaction this is all object stores in the database.
67+objectStoreNames
68+ :: Transaction
69+ -> Array String
70+objectStoreNames =
71+ _objectStoreNames
72+
4473--------------------
4574-- EVENT HANDLERS
4675--
47−onAbort :: forall e e'. Transaction -> Eff ( | e') Unit -> Aff (idb :: IDB | e) Unit
76+-- | Event handler for the `abort` event.
77+onAbort
78+ :: forall e e'
79+ . Transaction
80+ -> Eff ( | e') Unit
81+ -> Aff (idb :: IDB | e) Unit
4882onAbort db f =
4983 Fn.runFn2 _onAbort db f
5084
5185
52−onComplete :: forall e e'. Transaction -> Eff ( | e') Unit -> Aff (idb :: IDB | e) Unit
86+-- | Event handler for the `complete` event.
87+onComplete
88+ :: forall e e'
89+ . Transaction
90+ -> Eff ( | e') Unit
91+ -> Aff (idb :: IDB | e) Unit
5392onComplete db f =
5493 Fn.runFn2 _onComplete db f
5594
5695
57−onError :: forall e e'. Transaction -> (Error -> Eff ( | e') Unit) -> Aff (idb :: IDB | e) Unit
96+-- | Event handler for the `error` event.
97+onError
98+ :: forall e e'
99+ . Transaction
100+ -> (Error -> Eff ( | e') Unit)
101+ -> Aff (idb :: IDB | e) Unit
58102onError db f =
59103 Fn.runFn2 _onError db f
60104
@@ -73,22 +117,47 @@ instance idbTransactionTransaction :: IDBTransaction Transaction where
73117--------------------
74118-- FFI
75119--
76−foreign import _abort :: forall tx e. tx -> Aff (idb :: IDB | e) Unit
120+foreign import _abort
121+ :: forall tx e
122+ . tx
123+ -> Aff (idb :: IDB | e) Unit
124+
125+
126+foreign import _db
127+ :: Transaction
128+ -> Database
129+
130+
131+foreign import _error
132+ :: Transaction
133+ -> (Nullable Error)
134+
77135
136+foreign import _mode
137+ :: Fn4 TransactionMode TransactionMode TransactionMode Transaction TransactionMode
78138
79−foreign import _error :: Transaction -> (Nullable Error)
80139
140+foreign import _objectStoreNames
141+ :: Transaction
142+ -> Array String
81143
82−foreign import _mode :: Fn4 TransactionMode TransactionMode TransactionMode Transaction TransactionMode
83144
145+foreign import _objectStore
146+ :: forall tx e
147+ . Fn2 tx String (Aff (idb :: IDB | e) ObjectStore)
84148
85−foreign import _objectStore :: forall tx e. Fn2 tx String (Aff (idb :: IDB | e) ObjectStore)
86149
150+foreign import _onAbort
151+ :: forall tx e e'
152+ . Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
87153
88−foreign import _onAbort :: forall tx e e'. Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
89154
155+foreign import _onComplete
156+ :: forall tx e e'
157+ . Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
90158
91−foreign import _onComplete :: forall tx e e'. Fn2 tx (Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
92159
160+foreign import _onError
161+ :: forall tx e e'
162+ . Fn2 tx (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)
93163
94−foreign import _onError :: forall tx e e'. Fn2 tx (Error -> Eff ( | e') Unit) (Aff (idb :: IDB | e) Unit)