# feathers-levelup

> LevelDB adapter for Feathers via LevelUP

Latest version **1.1.1** (published 2016-07-21) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install feathers-levelup
pnpm add feathers-levelup
yarn add feathers-levelup
bun add feathers-levelup
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-07-21 |
| First published | 2016-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.12.0 |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Feathers contributors |
| Maintainers | daffl, dcw_ca, ekryski |
| Keywords | feathers, feathers-plugin |

## Links

- npm: https://www.npmjs.com/package/feathers-levelup
- Repository: https://github.com/feathersjs/feathers-levelup
- Issues: https://github.com/feathersjs/feathers-levelup/issues
- npm.io page: https://npm.io/package/feathers-levelup

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) ^2.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.6.1
- [levelup](https://npm.io/package/levelup.md) ^1.3.1
- [uberproto](https://npm.io/package/uberproto.md) ^1.2.0
- [feathers-errors](https://npm.io/package/feathers-errors.md) ^2.0.1
- [feathers-query-filters](https://npm.io/package/feathers-query-filters.md) ^2.0.0

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [stockfish](https://npm.io/package/stockfish.md) — 27.0K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2016-07-21
- 1.1.0 — 2016-06-18
- 1.0.1 — 2016-03-25

## README

# feathers-levelup

> A service adapter for [LevelUP](https://github.com/Level/levelup), an interface to [LevelDB](http://leveldb.org/).

[![Build Status](https://travis-ci.org/feathersjs/feathers-levelup.png?branch=master)](https://travis-ci.org/derek-watson/feathers-levelup)

**Table of Contents**

- [feathers-levelup](#feathers-levelup)
  - [Installation](#installation)
  - [Documentation](#documentation)
  - [Getting Started](#getting-started)
    - [Complete Example](#complete-example)
  - [Key Generation and Sort Order](#key-generation-and-sort-order)
  - [Efficient Range Queries](#efficient-range-queries)
  - [Authors](#authors)
  - [Changelog](#changelog)
  - [License](#license)


## Installation

```bash
npm install feathers-levelup --save
```

## Documentation

Please refer to the [Feathers database adapter documentation](http://docs.feathersjs.com/databases/readme.html) for more details or directly at:

- [LevelUP](http://docs.feathersjs.com/databases/levelup.html) - The detailed documentation for this adapter
- [Extending](http://docs.feathersjs.com/databases/extending.html) - How to extend a database adapter
- [Pagination and Sorting](http://docs.feathersjs.com/databases/pagination.html) - How to use pagination and sorting for the database adapter
- [Querying](http://docs.feathersjs.com/databases/querying.html) - The common adapter querying mechanism


## Getting Started

Creating a LevelUP service:

```bash
npm install levelup leveldown feathers-levelup --save
```

```js
const levelup = require('levelup');
const levelupService = require('feathers-levelup');

const db = levelup('./todos', { valueEncoding: 'json' });

app.use('/todos', levelupService({ db: db }));
```

See the [LevelUP Guide](https://github.com/Level/levelup) for more information on configuring your database, including selecting a backing store.

### Complete Example

Here's a complete example of a Feathers server with a `message` levelup service.

```js
const service = require('./lib');
const levelup = require('levelup');
const feathers = require('feathers');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');

// Create a feathers instance.
const app = feathers()
  // Enable Socket.io
  .configure(socketio())
  // Enable REST services
  .configure(rest())
  // Turn on JSON parser for REST services
  .use(bodyParser.json())
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({extended: true}));

// Connect to the db, create and register a Feathers service.
app.use('messages', service({
  db: levelup('./messages', { valueEncoding: 'json' }),
  paginate: {
    default: 2,
    max: 4
  }
}));

app.listen(3030);
console.log('Feathers Message levelup service running on 127.0.0.1:3030');
```

You can run this example by using `npm start` and going to [localhost:3030/messages](http://localhost:3030/messages). You should see an empty array. That's because you don't have any messages yet but you now have full CRUD for your new message service.

## Key Generation and Sort Order

By default, LevelDB stores entries lexicographically [sorted by key](http://leveldb.org/). The sorting is one of the main distinguishing features of LevelDB.

When feathers-levelup services `create` records, a key is generated based on a the value of `options.sortField`, plus a uuid. `_createdAt` is set and used by default, which is a good fit for time series data.

Change the `sortField` option to the field of your choice to configure key ordering:

```js
app.use('todos', service({
  db: db,
  sortField: '_createdAt' // this field value will be prepended to the db key
  paginate: {
    default: 2,
    max: 4
  }
}));

const todos = app.service('todos');

todos
  .create({task: 'Buy groceries'})
  .then(console.log);
```

```js
{ task: 'Buy groceries',
  _createdAt: 1457923734510,
  id: '1457923734510:0:d06afc7e-f4cf-4381-a9f9-9013a6955562' }
```

## Efficient Range Queries

Avoid memory-hungry `_find` calls that load the entire key set for processing by not specifying `$sort`, or by setting it to the same field as `options.sortField`. This way `_find` can take advantage of the natural sort order of the keys in the database to traverse the fewest rows.

Use `$gt`, `$gte`, `$lt`, `$lte` and `$limit` to perform fast range queries over your data.

```js
app.use('todos', service({
  db: db,
  sortField: '_createdAt' // db keys are sorted by this field value
  paginate: {
    default: 2,
    max: 4
  }
}));

const todos = app.service('todos');

todos
  .find({
    query: {
      _createdAt: {
        $gt: '1457923734510'    // keys starting with this _createdAt
      },
      $limit: 10,               // load the first ten
      $sort: {
        _createdAt: 1           // sort by options.sortField (or don't pass $sort at all)
      }
    }
  })
```

## Authors

- [Derek Watson](http://twg.ca)

## License

Copyright (c) 2016

Licensed under the [MIT license](LICENSE).

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