# somewhere

> Small in-memory database for Node.js that persists on disk

Latest version **1.0.1** (published 2014-10-03) · MIT license · 0 weekly downloads

## Install

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

## 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.0.1 |
| Published | 2014-10-03 |
| First published | 2014-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @dreyacosta |
| Maintainers | dreyacosta |
| Keywords | database, memory, JSON, file, functional |

## Links

- npm: https://www.npmjs.com/package/somewhere
- Repository: https://github.com:dreyacosta/somewhere.js
- Homepage: https://github.com/dreyacosta/somewhere.js
- Issues: https://github.com/dreyacosta/somewhere.js/issues
- npm.io page: https://npm.io/package/somewhere

## Dependencies (1)

- [coffee-script](https://npm.io/package/coffee-script.md) ^1.8.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-10-03
- 1.0.0 — 2014-09-24
- 0.2.1 — 2014-08-31
- 0.2.0 — 2014-08-31
- 0.1.2 — 2014-06-13
- 0.1.1 — 2014-05-12
- 0.1.0 — 2014-05-12
- 0.0.1 — 2014-05-03

## README

# somewhere.js [![Build Status](https://travis-ci.org/dreyacosta/somewhere.js.svg?branch=master)](https://travis-ci.org/dreyacosta/somewhere.js)
Small in-memory database for Node.js that persists on disk

## Installation
```sh
$ npm install somewhere
```

## Usage

### Load
```js
var Database = require('somewhere');
```

### Create database
```js
var onlyMemoryDb = new Database();
var memoryDiskDb = new Database('./database.json');
```

### Database connection
```js
var db = new Database('./database.json');
```

### Save
```js
db.save('collection', data);
```

```js
var movie = {
  title: "Die Hard",
  genre: "Action",
  director: "John McTiernan",
  description: "John McClane, officer of the NYPD, tries to save wife Holly
  Gennaro and several others, taken hostage by German terrorist Hans Gruber
  during a Christmas party at the Nakatomi Plaza in Los Angeles."
};

db.save('movies', movie);

/** Result: Saved Object (autogenerated id)
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    title: "Die Hard",
    genre: "Action",
    director: "John McTiernan",
    description: "John McClane, officer of the NYPD, tries to save wife Holly
    Gennaro and several others, taken hostage by German terrorist Hans Gruber
    during a Christmas party at the Nakatomi Plaza in Los Angeles."
  }
*/
```

### Find one
```js
db.findOne('collection', query);
```

```js
db.findOne('movies', { title: 'Die Hard' });

/** Result: Object
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    title: "Die Hard",
    genre: "Action",
    director: "John McTiernan",
    description: "John McClane, officer of the NYPD, tries to save wife Holly
    Gennaro and several others, taken hostage by German terrorist Hans Gruber
    during a Christmas party at the Nakatomi Plaza in Los Angeles."
  }
*/
```

### Find all
```js
db.find('movies', query);
```

```js
db.find('movies', { genre: 'Action' });

/** Result: Objects array
  [{
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    title: "Die Hard",
    genre: "Action",
    director: "John McTiernan",
    description: "John McClane, officer of the NYPD, tries to save wife Holly
    Gennaro and several others, taken hostage by German terrorist Hans Gruber
    during a Christmas party at the Nakatomi Plaza in Los Angeles."
  }]
*/
```

### Update
```js
db.update('movies', id, data);
```

```js
db.update('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1', { genre: "Action/Thriller" });

/** Result: Updated Object
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    title: "Die Hard",
    genre: "Action/Thriller",
    director: "John McTiernan",
    description: "John McClane, officer of the NYPD, tries to save wife Holly
    Gennaro and several others, taken hostage by German terrorist Hans Gruber
    during a Christmas party at the Nakatomi Plaza in Los Angeles."
  }
*/
```

### Remove
```js
db.remove('movies', id);
```

```js
db.remove('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1');
/** Result: Boolean
  true
*/
```

### Clear database
```js
db.clear()
```

## License
This software is free to use under the MIT license.

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