Skip to content

Commit 749ea07

Browse files
committed
Update readme
1 parent d0277ac commit 749ea07

File tree

2 files changed

+61
-46
lines changed

2 files changed

+61
-46
lines changed

README.md

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# feathers-nedb
22

3-
> :warning: **DEPRECATED**: Not compatible with Feathers v5. Please use [another adapter instead](https://www.npmjs.com/search?ranking=optimal&q=FeathersJS%20database%20adapter).
4-
53
[![Download Status](https://img.shields.io/npm/dm/feathers-nedb.svg?style=flat-square)](https://www.npmjs.com/package/feathers-nedb)
64

75
[feathers-nedb](https://github.com/feathersjs-ecosystem/feathers-nedb/) is a database service adapter for [NeDB](https://github.com/seald/nedb), an embedded datastore with a [MongoDB](https://www.mongodb.org/) like API. NeDB can store data in-memory or on the filesystem which makes it useful as a persistent storage without a separate database server.
@@ -10,7 +8,7 @@
108
$ npm install --save @seald-io/nedb feathers-nedb
119
```
1210

13-
> __Important:__ `feathers-nedb` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).
11+
> **Important:** `feathers-nedb` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).
1412
1513
## API
1614

@@ -19,61 +17,72 @@ $ npm install --save @seald-io/nedb feathers-nedb
1917
Returns a new service instance initialized with the given options. `Model` has to be an NeDB database instance.
2018

2119
```js
22-
const NeDB = require('@seald-io/nedb');
23-
const service = require('feathers-nedb');
20+
const NeDB = require("@seald-io/nedb");
21+
const service = require("feathers-nedb");
2422

2523
// Create a NeDB instance
2624
const Model = new NeDB({
27-
filename: './data/messages.db',
28-
autoload: true
25+
filename: "./data/messages.db",
26+
autoload: true,
2927
});
3028

31-
app.use('/messages', service({ Model }));
32-
app.use('/messages', service({ Model, id, events, paginate }));
29+
app.use("/messages", service({ Model }));
30+
app.use("/messages", service({ Model, id, events, paginate }));
3331
```
3432

35-
__Options:__
33+
**Options:**
3634

3735
- `Model` (**required**) - The NeDB database instance. See the [NeDB API](https://github.com/seald/nedb#documentation) for more information.
38-
- `id` (*optional*, default: `'_id'`) - The name of the id field property. By design, NeDB will always add an `_id` property.
39-
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service
40-
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size
41-
- `whitelist` (*optional*) - A list of additional query parameters to allow (e.g. `[ '$regex' ]`)
42-
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` null to change multiple items. Can be `true` for all methods or an array of multi methods (e.g. `[ 'remove', 'create' ]`)
36+
- `id` (_optional_, default: `'_id'`) - The name of the id field property. By design, NeDB will always add an `_id` property.
37+
- `events` (_optional_) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service
38+
- `paginate` (_optional_) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size
39+
- `whitelist` (_optional_) - A list of additional query parameters to allow (e.g. `[ '$regex' ]`)
40+
- `multi` (_optional_) - Allow `create` with arrays and `update` and `remove` with `id` null to change multiple items. Can be `true` for all methods or an array of multi methods (e.g. `[ 'remove', 'create' ]`)
4341

4442
### params.nedb
4543

4644
When making a [service method](https://docs.feathersjs.com/api/services.html) call, `params` can contain an `nedb` property which allows to pass additional [NeDB options](https://github.com/seald/nedb#updating-documents), for example to allow `upsert`:
4745

4846
```js
49-
app.service('messages').update('someid', {
50-
text: 'This message will be either created or updated'
51-
}, {
52-
nedb: { upsert: true }
53-
});
47+
app.service("messages").update(
48+
"someid",
49+
{
50+
text: "This message will be either created or updated",
51+
},
52+
{
53+
nedb: { upsert: true },
54+
}
55+
);
5456
```
5557

5658
### use of params on client
59+
5760
On client you can't pass anything other than a query as the parameter. So you need to do it like this.
5861

5962
```js
6063
// client side
61-
app.service('messages').update('someid', {
62-
text: 'This message will be either created or updated'
63-
}, {
64-
query: {nedb: { upsert: true }}
65-
});
64+
app.service("messages").update(
65+
"someid",
66+
{
67+
text: "This message will be either created or updated",
68+
},
69+
{
70+
query: { nedb: { upsert: true } },
71+
}
72+
);
6673
```
74+
6775
then add a hook to the service to move the nedb options to the params object
76+
6877
```js
69-
ctx => {
78+
(ctx) => {
7079
const nedb = ctx.params.query.nedb;
7180
if (nedb) {
7281
ctx.params.nedb = nedb;
7382
delete ctx.params.query.nedb;
7483
}
7584
return ctx;
76-
}
85+
};
7786
```
7887

7988
## Example
@@ -87,43 +96,49 @@ $ npm install @feathersjs/feathers @feathersjs/errors @feathersjs/express @feath
8796
In `app.js`:
8897

8998
```js
90-
const feathers = require('@feathersjs/feathers');
91-
const express = require('@feathersjs/express');
92-
const socketio = require('@feathersjs/socketio');
99+
const feathers = require("@feathersjs/feathers");
100+
const express = require("@feathersjs/express");
101+
const socketio = require("@feathersjs/socketio");
93102

94-
const NeDB = require('@seald-io/nedb');
95-
const service = require('feathers-nedb');
103+
const NeDB = require("@seald-io/nedb");
104+
const service = require("feathers-nedb");
96105

97106
const db = new NeDB({
98-
filename: './db-data/messages',
99-
autoload: true
107+
filename: "./db-data/messages",
108+
autoload: true,
100109
});
101110

102111
// Create an Express compatible Feathers application instance.
103112
const app = express(feathers());
104113
// Turn on JSON parser for REST services
105114
app.use(express.json());
106115
// Turn on URL-encoded parser for REST services
107-
app.use(express.urlencoded({extended: true}));
116+
app.use(express.urlencoded({ extended: true }));
108117
// Enable REST services
109118
app.configure(express.rest());
110119
// Enable Socket.io services
111120
app.configure(socketio());
112121
// Connect to the db, create and register a Feathers service.
113-
app.use('/messages', service({
114-
Model: db,
115-
paginate: {
116-
default: 2,
117-
max: 4
118-
}
119-
}));
122+
app.use(
123+
"/messages",
124+
service({
125+
Model: db,
126+
paginate: {
127+
default: 2,
128+
max: 4,
129+
},
130+
})
131+
);
120132
// Set up default error handler
121133
app.use(express.errorHandler());
122134

123135
// Create a dummy Message
124-
app.service('messages').create({
125-
text: 'Message created on server'
126-
}).then(message => console.log('Created message', message));
136+
app
137+
.service("messages")
138+
.create({
139+
text: "Message created on server",
140+
})
141+
.then((message) => console.log("Created message", message));
127142

128143
// Start the server.
129144
const port = 3030;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
]
5353
},
5454
"engines": {
55-
"node": ">= 14"
55+
"node": ">= 16"
5656
},
5757
"dependencies": {
5858
"@feathersjs/adapter-commons": "^5.0.11",

0 commit comments

Comments
 (0)