FeathersJS DB adapter for couchbase
npm install feathersjs-couchbase --save
This library only sanitizes values and does not sanitize any keys. It is a plan to build into the query builder a sanitization layer but for now it's open to attacks. This can be easily mitigated by validating your input and excluding any keys not expected from your input.
{
"; SELECT * FROM `admin`; /*": "*/"
}
const couchbase = require('couchbase-promises')
const cluster = new couchbase.Cluster('couchbase://127.0.0.1')
const bucketName = 'default';
const bucket = cluster.openBucket(bucketName)
const config = {
name: 'users', // Name of service and key prefix (REQUIRED)
bucket: bucketName, // Couchbase bucket name (REQUIRED)
connection: bucket, // Bucket connection, or promise that resolves to connection (REQUIRED)
separator: '::' // optional key separator (defaults to `::`)
couchbase: couchbase, // optional couchbase dependency (OPTIONAL)
id: 'id', // ID field to use (OPTIONAL) (defaults to `uuid`)
paginate: app.get('paginate'), // (OPTIONAL)
};
// Initialize our service with all options it requires
app.use(`/${options.name}`, new Service(options));
const createService = require('feathersjs-couchbase')
// Method 1
app.use('/',createService(config));
// Method 2
const { CouchService } = require('feathersjs-couchbase');
new CouchService(config)
'use strict';
const { CouchService } = require('feathersjs-couchbase');
class Users extends CouchService {
constructor(opts){
super(opts);
}
create(data, params){
return super.create(
Object.assign({ // Your default data here
auth0Id: null,
role: 'default',
}, data) // Data passed in
, params);
}
}
module.exports = Rooms;
The library implements the full feathersjs common api and Query api, see limitations for exceptions.
Finds will not work until an index is built over the bucket you're trying to query
N1QL Consistency special parameter. Consistency Documentation
const { QueryConsistency } = require('feathersjs-couchbase');
Service.find({
$consistency: QueryConsistency.NOT_BOUNDED
...
});
Consistency Levels:
- NOT_BOUNDED
- REQUEST_PLUS
- STATEMENT_PLUS
Omitting $consistency results in the default consistency of 'at_plus';
- Subqueries are not supported
- Only tested with feathers v3
- $selects on Service.find calls pulls all data and removes sections locally
Copyright (c) 2018
Licensed under the MIT license.