# cache-database

> cache database

Latest version **1.3.3** (published 2020-03-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install cache-database
pnpm add cache-database
yarn add cache-database
bun add cache-database
```

## 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 | 1.3.3 |
| Published | 2020-03-21 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Polozov Nikita |
| Maintainers | polozownikita |
| Keywords | cache, db |

## Links

- npm: https://www.npmjs.com/package/cache-database
- Repository: https://github.com/polozov-nikita/cache-database
- Issues: https://github.com/polozov-nikita/cache-database/issues
- npm.io page: https://npm.io/package/cache-database

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.3.3 (latest) — 2020-03-21
- 1.3.2 — 2020-03-10
- 1.3.1 — 2020-03-10
- 1.3.0 — 2020-01-11
- 1.2.9 — 2019-12-27
- 1.2.8 — 2019-12-19
- 1.2.7 — 2019-12-10
- 1.2.6 — 2019-12-02
- 1.2.5 — 2019-12-02
- 1.2.4 — 2019-12-01
- 1.2.3 — 2019-12-01
- 1.2.2 — 2019-12-01
- 1.2.1 — 2019-12-01
- 1.2.0 — 2019-12-01
- 1.1.4 — 2019-11-29
- … 16 more at https://npm.io/package/cache-database/versions

## README

# cache-database

## Connection
```
  const cache = require('cache-database');
```
## Collections

### Create
```
  const collection = cache.create('collection');
```
## Documents

### Create
```
  //Return Promise.
  collection.create({a: 1, b: 2, c: 3})
    .then(() => console.log('ok'))
    .catch(error => console.log(error))
```
### Find

* Find all
```
  //Find all documents
  collection.find()
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */
  
```
* Find params
```
  //Find for documents where a == 1;
  collection.find({a: 1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find for documents where a == 1, b == 2
  collection.find({a: 1, b: 2})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find for documents where a == 1, a == 2, a == 3
  collection.find({a: {$in: [1,2,3]}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find for documents where a >= 1 and a <= 4
  collection.find({a: {$gte: 1, $lte:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find for documents where a > 1 and a < 4
  collection.find({a: {$gt: 1, $lt:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find all documents and skip fields b in documents
  collection.find({}, {b: 0})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find all documents and sorting field a
  collection.find({}, {}, {a: 1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  //AND REVERSE
  collection.find({}, {}, {}, {a: -1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Find for documents starting at 30 and limit output to 10 documents
  collection.find({}, {}, 30, 10)
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */
```
### Search
```
  //Full-text document search
  collection.search('test')
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search where a == 1
  collection.search('test', {a: 1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search where a == 1, a == 2, a == 3
  collection.search('test', {a: {$in: [1,2,3]}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search where a >= 1 and a <= 4
  collection.search('test', {a: {$gte: 1, $lte:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search where a > 1 and a < 4
  collection.search('test', {a: {$gt: 1, $lt:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search and skip fields b in documents
  collection.search('test', {}, {b: 0})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document search and sorting field a
  collection.search('test', {}, {}, {a: 1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  //AND REVERSE
  collection.search('test', {}, {}, {a: -1})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */

  //Full-text document starting at 30 and limit output to 10 documents
  collection.search('test', {}, {}, 30, 10)
    .then(data => console.log(data))
    .catch(err => console.log(err));
  /*
    Return Promise. Resolve return Object, type:
    {
      data: Array,
      search: Array,
      skip: Array,
      sort: Array,
      records: {
        all: Number,
        skip: Number || null,
        limit: Number || null,
      },
    }
  */
```
### Find One
```
  //Find document where a == 1;
  //Return Promise. Resolve return document
  collection.findOne({a: 1})
    .then(data => console.log(data))
    .catch(err => console.log(err));

  //Find document where a == 1, b == 2
  //Return Promise. Resolve return document
  collection.findOne({a: 1, b: 2})
    .then(data => console.log(data))
    .catch(err => console.log(err));

  //Find document where a == 1, a == 2, a == 3
  //Return Promise. Resolve return document
  collection.findOne({a: {$in: [1,2,3]}})
    .then(data => console.log(data))
    .catch(err => console.log(err));

  //Find document where a >= 1 and a <= 4
  //Return Promise. Resolve return document
  collection.findOne({a: {$gte: 1, $lte:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));

  //Find document where a > 1 and a < 4
  //Return Promise. Resolve return document
  collection.findOne({a: {$gt: 1, $lt:4}})
    .then(data => console.log(data))
    .catch(err => console.log(err));

  //Find document and skip fields b in documents
  //Return Promise. Resolve return document
  collection.find({}, {b: 0})
    .then(data => console.log(data))
    .catch(err => console.log(err));
```
### Update
```
  //Return Promise.
  collection.findAndUpdate({a: 1}, {x: 10})
    .then(() => console.log('ok'))
    .catch(err => console.log(err));
```
### Delete
```
  //Return Promise.
  collection.findAndDelete({a: 1})
    .then(() => console.log('ok'))
    .catch(err => console.log(err));
```

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