Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
feathers-levelup
Advanced tools
Table of Contents
npm install feathers-levelup --save
Please refer to the Feathers database adapter documentation for more details or directly at:
Creating a LevelUP service:
npm install levelup leveldown feathers-levelup --save
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 for more information on configuring your database, including selecting a backing store.
Here's a complete example of a Feathers server with a message
levelup service.
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. 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.
By default, LevelDB stores entries lexicographically sorted by key. 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:
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);
{ task: 'Buy groceries',
_createdAt: 1457923734510,
id: '1457923734510:0:d06afc7e-f4cf-4381-a9f9-9013a6955562' }
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.
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)
}
}
})
1.0.0
Copyright (c) 2016
Licensed under the MIT license.
v1.1.0 (2016-06-18)
Closed issues:
Merged pull requests:
FAQs
LevelDB adapter for Feathers via LevelUP
The npm package feathers-levelup receives a total of 2 weekly downloads. As such, feathers-levelup popularity was classified as not popular.
We found that feathers-levelup demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.