Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swan-io/indexed-db

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swan-io/indexed-db

A resilient, Future-based key-value store for IndexedDB

  • 0.4.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@swan-io/indexed-db

Tests mit licence npm version bundlephobia

A resilient, Future-based key-value store for IndexedDB.

Installation

$ yarn add @swan-io/indexed-db
# --- or ---
$ npm install --save @swan-io/indexed-db

Quickstart

const store = openStore("myDatabaseName", "myStoreName");

store
  .setMany({
    firstName: "Mathieu",
    lastName: "Breton",
  })
  .flatMap(() => store.getMany(["firstName", "lastName"]))
  .flatMap(({ firstName, lastName }) => {
    console.log({
      firstName,
      lastName,
    });

    return store.clear();
  })
  .tap(() => {
    console.log("✅");
  });

API

Open a database, create a store if needed and returns methods to manipulate it.
Note that you can open multiple databases / stores, with different names.

const store = await openStore("myDatabaseName", "myStoreName", {
  transactionRetries: 2, // retry failed transactions (default: 2)
  transactionTimeout: 500, // timeout a transaction when it takes too long (default: 500ms)
  onDatabaseError: (error: Error) => console.error(error), // called with idb errors (default: noop)
});

store.getMany

Get many values at once. Resolves with a record.

store
  .getMany(["firstName", "lastName"])
  .map(({ firstName, lastName }) => console.log({ firstName, lastName }));

store.setMany

Set many key-value pairs at once.

store
  .setMany({ firstName: "Mathieu", lastName: "Breton" })
  .tap(() => console.log("✅"));

store.clear

Clear all values in the store.

store.clear().tap(() => console.log("✅"));

🙌 Acknowledgements

Keywords

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc