Moleculer adapter to import feathers services. That includes:
- MongoDB
- Blob store
- Bookshelf
- CouchDB
- Elasticsearch
- Knex
- Mongoose
- NeDB
- RethinkDB
- Sequalize
- Waterline
- and many others
$ npm install moleculer-adapter-feathers --save
const Feathers = require("moleculer-adapter-feathers");
const { ServiceBroker } = require("moleculer");
const feathersKnex = require("feathers-knex");
const knex = require("knex");
const broker = new ServiceBroker();
// Create a DB service via knex for `user` entities
broker.createService({
name: "users",
mixins: [Feathers],
settings: {
feathers: {
adapter: feathersKnex,
options: {
name: "users",
Model: new knex({
client: "pg",
connection: { ... },
}),
},
},
},
});
broker.start()
// Create a new user
.then(() => broker.call("users.create", {
username: "john",
email: "john@doe.com",
}))
// Get all users
.then(() => broker.call("users.find").then(console.log));
Property | Type | Default | Description |
---|---|---|---|
adapter |
`Object | Function` | required |
hooks |
Object |
{} |
Object containing before and after hooks. |
options |
Object |
{} |
Options passed to Feathers service adapter. |
Hooks work just as they do in Feathers. They are passed down to a service in settings.feathers.hooks
.
module.exports = {
...
settings: {
feathers: {
adapter: feathersKnex,
hooks: require('./hooks'),
options: {
name: "users",
Model: new knex({
client: "pg",
connection: { ... },
}),
},
},
},
...
}
module.exports = {
before: {
create: [
hook => {
console.log('create hook')
return hook
},
],
find: [],
get: [],
update: [],
patch: [],
remove: [],
},
after: {
create: [],
find: [],
get: [],
update: [],
patch: [],
remove: [],
},
}
Standard Feathers actions are exposed: create
, get
, find
, update
, patch
, remove
with all the standard Feathers parameters. Actions can be overwritten.
Feathers service methods can be accessed directly via this.create
, this.find
and etc.
Create an object in a service.
Property | Type | Default | Description |
---|---|---|---|
* |
Any |
{} |
Object to be created. |
Type: Object
Created object (or any other service response).
Find objects by a provided query, if any.
Property | Type | Default | Description |
---|---|---|---|
* |
Any |
{} |
Query specified by the service. |
Type: Array[Object]
Array of results.
Get object in the service by a provided (unique) ID.
Property | Type | Default | Description |
---|---|---|---|
id |
`String | Number` | required |
Type: Object
Object found by the ID.
Changes the properties of an object.
Property | Type | Default | Description |
---|---|---|---|
id |
`String | Number` | required |
* |
Any |
{} |
Values to be patched. |
Type: Object
Object patched.
Overwrites an object's properties.
Property | Type | Default | Description |
---|---|---|---|
id |
`String | Number` | required |
* |
Any |
{} |
Rest of the object. |
Type: Object
Object updated.
Remove object by ID.
Property | Type | Default | Description |
---|---|---|---|
id |
`String | Number` | required |
Type: Object
Object removed.