BuckleScript bindings for idb-keyval
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"]
}
let store = IdbKeyVal.createStore("custom-db-name", "custom-store-name");
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();
});
IdbKeyVal.get("key", store)
|> Js.Promise.then_(value => {
// logs: "value"
Js.log(value);
Js.Promise.resolve();
});
IdbKeyVal.keys(store)
|> Js.Promise.then_(keys => {
// logs: ["key"]
Js.log(keys);
Js.Promise.resolve();
});
IdbKeyVal.delete("key", store)
|> Js.Promise.then_(keys => {
Js.log("deleted");
Js.Promise.resolve();
});
IdbKeyVal.clear(store)
|> Js.Promise.then_(keys => {
Js.log("cleared");
Js.Promise.resolve();
});