# keya

> A simple, universal document store

Latest version **2.0.0** (published 2020-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install keya
pnpm add keya
yarn add keya
bun add keya
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-05-22 |
| First published | 2018-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 121.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Brendan McGuire |
| Maintainers | mayormonty |

## Links

- npm: https://www.npmjs.com/package/keya
- Repository: https://github.com/MayorMonty/keya
- Homepage: https://github.com/MayorMonty/keya#readme
- Issues: https://github.com/MayorMonty/keya/issues
- npm.io page: https://npm.io/package/keya

## Dependencies (5)

- [sqlite](https://npm.io/package/sqlite.md) ^4.0.7
- [sqlite3](https://npm.io/package/sqlite3.md) ^4.2.0
- [@types/sqlite3](https://npm.io/package/@types/sqlite3.md) ^3.1.6
- [better-sqlite3](https://npm.io/package/better-sqlite3.md) ^7.0.1
- [@types/better-sqlite3](https://npm.io/package/@types/better-sqlite3.md) ^5.4.0

## Recent versions

- 2.0.0 (latest) — 2020-05-22
- 1.1.3 — 2019-06-08
- 1.1.2 — 2019-06-08
- 1.1.1 — 2019-06-08
- 1.1.0 — 2019-06-08
- 1.0.1 — 2019-04-19
- 1.0.0 — 2019-04-19
- 0.0.6 — 2018-05-15
- 0.0.5 — 2018-05-15
- 0.0.4 — 2018-05-14
- 0.0.3 — 2018-05-14
- 0.0.2 — 2018-05-14
- 0.0.1 — 2018-05-14
- 0.0.0 — 2018-05-14

## README

# Keya

A simple, universal document store. Keya supports the following storage mediums:

- SQLite (Nodejs)
- IndexedDB (Browser)
- LocalStorage (Browser, backup)

## API

In general `keya` stores can be thought of as a `Map` that acts asynchronously.

Import

```javascript
import * as keya from "keya";
// Or, if not using modules:
const keya = require("keya");
```

### Access a store

> If the store does not exist when you call this, it will be created automatically for you

```javascript
const store = await keya.store("records");
```

> Note: Store names need to follow SQLite Table name rules/should generally only be alphanumeric characters without spaces. Beyond that can lead to unexpected issues and undocumented behavior

#### Hydration

`keya` supports an optional Hydration Function to be passed to `.store` when initalizing. This defaults to `JSON.parse`. The hydration function will be passed the stored string and should return the appropriate value. An example is shown below that allows `keya` to store Maps long-term.

```JavaScript

// Add a custom hydration function
const store = await keya.store("calls");

// Custom conversion functions stores a map by it's entry list
store.stringify = map => JSON.stringify([...map.entries()]);
store.hydrate = string => new Map(JSON.parse(string));

// Construct the Map to be stored
const map = new Map([
  [32, "a"],
  [45, "b"]
])

store.set("map", map);

// In another session

const map = store.get("map");
```

### Set a value

```javascript
await store.set("document", { value: 345 });
```

### Get a value

```javascript
const record = await store.get("document");
```

### Find values

```javascript
const records = store.find(
  (value, name) => name.includes("e") && value.v == 12
);
```

### Clear the store

```javascript
store.clear();
```

### Get all values

```javascript
store.all(); // [ {key: "hello", value: 43 }, { key: "world", value: 12 } ]
```

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