@tatchi/bs-idb-keyval
v0.2.0
Published
BuckleScript bindings for idb-keyval
Downloads
7
Maintainers
Readme
bs-idb-keyval
BuckleScript bindings for idb-keyval
Installation
npm install --save @tatchi/bs-idb-keyval
Then add @tatchi/bs-idb-keyval
to bs-dependencies
in your bsconfig.json
:
{
...
"bs-dependencies": ["@tatchi/bs-idb-keyval"]
}
Usage
Create store:
let store = IdbKeyVal.createStore("custom-db-name", "custom-store-name");
set:
IdbKeyVal.set("key", "value", store)
|> Js.Promise.then_(() => {
Js.log("It worked!");
Js.Promise.resolve();
})
|> Js.Promise.catch(err => {
Js.log2("It failed!!", err);
Js.Promise.resolve();
});
get:
IdbKeyVal.get("key", store)
|> Js.Promise.then_(value => {
// logs: "value"
Js.log(value);
Js.Promise.resolve();
});
keys:
IdbKeyVal.keys(store)
|> Js.Promise.then_(keys => {
// logs: ["key"]
Js.log(keys);
Js.Promise.resolve();
});
delete:
IdbKeyVal.delete("key", store)
|> Js.Promise.then_(keys => {
Js.log("deleted");
Js.Promise.resolve();
});
clear:
IdbKeyVal.clear(store)
|> Js.Promise.then_(keys => {
Js.log("cleared");
Js.Promise.resolve();
});