# @tabular-state/database

> A database adapter for [@tabular-state/store](../store/README.md) to persist state in IndexedDB.

Latest version **1.0.1-alpha.4** (published 2023-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tabular-state/database
pnpm add @tabular-state/database
yarn add @tabular-state/database
bun add @tabular-state/database
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1-alpha.4 |
| Published | 2023-03-27 |
| First published | 2023-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Gridventures GmbH |
| Maintainers | ps73 |

## Links

- npm: https://www.npmjs.com/package/@tabular-state/database
- Repository: https://github.com/gridventures/tabular-state
- Homepage: https://github.com/gridventures/tabular-state#readme
- Issues: https://github.com/gridventures/tabular-state/issues
- npm.io page: https://npm.io/package/@tabular-state/database

## Dependencies (2)

- [idb-keyval](https://npm.io/package/idb-keyval.md) ^6.2.0
- [@tabular-state/store](https://npm.io/package/@tabular-state/store.md) ^1.0.1-alpha.4

## Recent versions

- 1.0.1-alpha.4 (latest) — 2023-03-27
- 1.0.1-alpha.3 — 2023-03-20
- 1.0.1-alpha.2 — 2023-03-04
- 1.0.1-alpha.1 — 2023-03-02
- 1.0.1-alpha.0 — 2023-02-27
- 1.0.0-alpha.0 — 2023-02-27
- 0.5.0-alpha.0 — 2023-02-09
- 0.3.0-alpha.0 — 2023-02-09
- 0.1.0-alpha.0 — 2023-02-07

## README

# @tabular-state/database

A database adapter for [@tabular-state/store](../store/README.md) to persist state in IndexedDB.

> **Warning**
> Persisting state is currently only supported in browsers with indexeddb support.

```ts
import { createStore } from '@tabular-state/store';

const store = createStore<Tables>();
```

## Using IndexedDB

Uses [idb-keyval](https://npmjs.com/package/idb-keyval) under the hood.

```bash
npm install @tabular-state/database idb-keyval
```

```bash
pnpm install @tabular-state/database idb-keyval
```

```bash
yarn add @tabular-state/database idb-keyval
```

```ts
import { createIndexedDbAdapter } from '@tabular-state/database';

const database = ceateIndexedDbAdapter({
  autoPersistTables: [['users', 'id']],
  checkAutoPersistTables(tableName) {
    if (tableName === 'any-dynamic-database') {
      return 'customIdField';
    }
    return false;
  },
  onRevalidate(table, ids) {
    // do something when persisted state has been revalidated
  },
});
// or with specific namespace
const database = ceateIndexedDbAdapter({
  namespace: 'account-1',
  // ...
});

store.plugin(database);
```

## Namespaces

It is possible to implement splitted databases by switching the database namespace. A possible use case is an application where the user can switch between multiple accounts and or workspaces.

```ts
database.setNamespace('account-2');
// this will clear current store and reload persisted state from account-2
```

---
_Source: https://npm.io/package/@tabular-state/database · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
