mirror of
https://github.com/ilyakooo0/purescript-indexedDB.git
synced 2024-09-11 06:55:48 +03:00
complete methods for Transaction API
This commit is contained in:
parent
86afd03dbe
commit
a41af095e7
@ -45,6 +45,5 @@ exports._showIDBTransaction = function _showIDBTransaction(tx) {
|
||||
return '(IDBTransaction ' +
|
||||
'{ error: ' + tx.error +
|
||||
', mode: ' + tx.mode +
|
||||
', objectStoreNames: [' + exports.toArray(tx.objectStoreNames).join(', ') + ']' +
|
||||
' })';
|
||||
};
|
||||
|
@ -4,7 +4,10 @@ import Prelude
|
||||
import Data.Maybe(Maybe)
|
||||
import Control.Monad.Aff(Aff)
|
||||
import Control.Monad.Eff(kind Effect, Eff)
|
||||
import Control.Monad.Eff.Exception(EXCEPTION)
|
||||
|
||||
type Synchronous eff a = Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) a
|
||||
type Asynchronous eff a = Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) a
|
||||
|
||||
foreign import data INDEXED_DB :: Effect
|
||||
|
||||
|
@ -3,9 +3,8 @@ module Database.IndexedDB.IDBDatabase where
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff(Aff)
|
||||
import Control.Monad.Eff(kind Effect, Eff)
|
||||
import Control.Monad.Eff(Eff)
|
||||
import Control.Monad.Eff.Exception(EXCEPTION)
|
||||
import Control.Monad.Eff.Console as Console
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried(Fn2, Fn3)
|
||||
import Data.Maybe(Maybe)
|
||||
@ -13,17 +12,17 @@ import Data.Maybe(Maybe)
|
||||
import Database.IndexedDB.Core
|
||||
|
||||
|
||||
foreign import close :: forall eff. IDBDatabase -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
|
||||
foreign import close :: forall eff. IDBDatabase -> Synchronous eff Unit
|
||||
|
||||
|
||||
foreign import _createObjectStore :: forall eff. Fn3 IDBDatabase String { keyPath :: Maybe String, autoIncrement :: Boolean } (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore)
|
||||
createObjectStore :: forall eff . IDBDatabase -> String -> { keyPath :: Maybe String, autoIncrement :: Boolean } -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore
|
||||
foreign import _createObjectStore :: forall eff. Fn3 IDBDatabase String { keyPath :: Maybe String, autoIncrement :: Boolean } (Synchronous eff IDBObjectStore)
|
||||
createObjectStore :: forall eff . IDBDatabase -> String -> { keyPath :: Maybe String, autoIncrement :: Boolean } -> Synchronous eff IDBObjectStore
|
||||
createObjectStore db name opts =
|
||||
Fn.runFn3 _createObjectStore db name opts
|
||||
|
||||
|
||||
foreign import _deleteObjectStore :: forall eff. Fn2 IDBDatabase String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore)
|
||||
deleteObjectStore :: forall eff . IDBDatabase -> String -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore
|
||||
foreign import _deleteObjectStore :: forall eff. Fn2 IDBDatabase String (Synchronous eff IDBObjectStore)
|
||||
deleteObjectStore :: forall eff . IDBDatabase -> String -> Synchronous eff IDBObjectStore
|
||||
deleteObjectStore db name =
|
||||
Fn.runFn2 _deleteObjectStore db name
|
||||
|
||||
@ -34,8 +33,8 @@ foreign import name :: IDBDatabase -> String
|
||||
foreign import objectStoreNames :: IDBDatabase -> Array String
|
||||
|
||||
|
||||
foreign import _transaction :: forall eff. Fn3 IDBDatabase (Array String) IDBTransactionMode (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBTransaction)
|
||||
transaction :: forall eff. IDBDatabase -> Array String -> IDBTransactionMode -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBTransaction
|
||||
foreign import _transaction :: forall eff. Fn3 IDBDatabase (Array String) IDBTransactionMode (Synchronous eff IDBTransaction)
|
||||
transaction :: forall eff. IDBDatabase -> Array String -> IDBTransactionMode -> Synchronous eff IDBTransaction
|
||||
transaction db stores mode =
|
||||
Fn.runFn3 _transaction db stores mode
|
||||
|
||||
|
@ -3,7 +3,7 @@ module Database.IndexedDB.IDBFactory where
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff(Aff)
|
||||
import Control.Monad.Eff(kind Effect, Eff)
|
||||
import Control.Monad.Eff(Eff)
|
||||
import Control.Monad.Eff.Exception(EXCEPTION)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried(Fn3)
|
||||
|
39
src/Database/IndexedDB/IDBTransaction.js
Normal file
39
src/Database/IndexedDB/IDBTransaction.js
Normal file
@ -0,0 +1,39 @@
|
||||
const Maybe = require('Data.Maybe');
|
||||
const Core = require('Database.IndexedDB.Core');
|
||||
|
||||
|
||||
exports.abort = function abort(tx) {
|
||||
return function eff() {
|
||||
try {
|
||||
tx.abort();
|
||||
} catch (e) {
|
||||
throw new Error(e.name);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.error = function error(tx) {
|
||||
return tx.error == null
|
||||
? Maybe.Nothing()
|
||||
: Maybe.Just(new Error(tx.error.name));
|
||||
};
|
||||
|
||||
exports.mode = function mode(tx) {
|
||||
if (tx.mode === 'readwrite') {
|
||||
return Core.ReadWrite();
|
||||
} else if (tx.mode === 'versionchange') {
|
||||
return Core.VersionChange();
|
||||
}
|
||||
|
||||
return Core.ReadOnly();
|
||||
};
|
||||
|
||||
exports._objectStore = function _objectStore(tx, name) {
|
||||
return function eff() {
|
||||
try {
|
||||
return tx.objectStore(name);
|
||||
} catch (e) {
|
||||
throw new Error(e.name);
|
||||
}
|
||||
};
|
||||
};
|
27
src/Database/IndexedDB/IDBTransaction.purs
Normal file
27
src/Database/IndexedDB/IDBTransaction.purs
Normal file
@ -0,0 +1,27 @@
|
||||
module Database.IndexedDB.IDBTransaction where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Aff(Aff)
|
||||
import Control.Monad.Eff(Eff)
|
||||
import Control.Monad.Eff.Exception(EXCEPTION, Error)
|
||||
import Data.Function.Uncurried as Fn
|
||||
import Data.Function.Uncurried(Fn2)
|
||||
import Data.Maybe(Maybe)
|
||||
|
||||
import Database.IndexedDB.Core
|
||||
|
||||
|
||||
foreign import abort :: forall eff. IDBTransaction -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
|
||||
|
||||
|
||||
foreign import _objectStore :: forall eff. Fn2 IDBTransaction String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore)
|
||||
objectStore :: forall eff. IDBTransaction -> String -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore
|
||||
objectStore tx name =
|
||||
Fn.runFn2 _objectStore tx name
|
||||
|
||||
|
||||
foreign import mode :: IDBTransaction -> IDBTransactionMode
|
||||
|
||||
|
||||
foreign import error :: IDBTransaction -> Maybe Error
|
Loading…
Reference in New Issue
Block a user