nc-db-handler
The DS-Handler is the Module that handles the handling of the Data Store connections (PG and Elastic).
Installation
npm install --save nc-db-handler
Usage
var NcDbHandler = ;var dsHandler = ;var config = 'write-store': db1: 'postgres://postgres:postgres@localhost/db1' db2: 'postgres://postgres:postgres@localhost/db1' 'read-store': index1: 'https://user:pass@localhost' index2: 'https://user:pass@localhost' ; dsHandler; dsHandler;
Method Summary
Write-Store Methods (PG)
Read-Store Methods (Elastic)
Write-Store Methods
Create
This methods hits PG
ncDbHandler;
Read
This methods hits PG
ncDbHandler; /* Other query examplesquery: { or : { { 'native': 'id IN (13,123,1234)' }, { and : { { 'meta->address->>street': 'Anderson"' }, { 'meta->>always': 1 } } }, { 'meta->>email' : [ 'joe.doe@gmail.com', 'jane.doe@gmail.com', ] } }} === WHERE id IN (13,123,1234) OR (meta->address->>street = "Anderson" AND meta->>always = 1) OR (meta->>email = "joe.doe@gmail.com" OR meta->>email = "jane.doe@gmail.com")*/ /*query: [ { 'meta->>reviewer': 123 }, { 'meta->>profile': 45 }] === WHERE meta->>reviewer = 123 AND meta->>profile = 45*/
Remove
This methods hits PG
ncDbHandler;
SoftRemove
This methods hits PG
ncDbHandler;
Update
This methods hits PG
ncDbHandler;
Count
This methods hits PG
ncDbHandler;
PG
This methods hits PG
ncDbHandler ;
Read-Store Methods
Search
This methods hits Elastic
ncDbHandler;
Index
This methods hits Elastic
ncDbHandlerindex dataSource: 'reviews.reviews' /* {String} | required | format: "index.type" */ logQuery: true /* {Boolean} | optional | default: false */ payload: /* {Object|Array} | required */ id: 'UUID' /* required */ user: 'some user name' content: 'some content here' id: 'UUID' /* required */ user: 'another user' content: 'some content here' mapping: /* {Function} | optional */ payloadSchema: /* {Object} | optional | Joi validation schema applied on the result of the mapping */ id: Joi... replaceData: false /* {Boolean} | optional | defaults: false */;
ReIndex
This methods hits Elastic
ncDbHandler;
UnIndex
This methods hits Elastic
ncDbHandler;
ES
This methods hits Elastic
ncDbHandler;
Development
On your machine, we can initialize some data store dependencies to facilitate integration test.
Mocha Integration Test
Creates a docker compose environment with Elasticsearch and Postgres with a container testing code in watch mode.
make run
Install Packages
Removes node_modules folder and reinstalls from shrinkwrap or package.json
make install
Create New Shrinkwrap From Scratch
Removes node_modules folder and npm_shrinkwrap.json and recreates from package.json using the latest from npm.
make clean
Test with Mocha
Initiate mocha in watch mode on your local machine. This will not boot up any docker resources so your integration test will fail. But if you have postgres and elasticsearch containers running and hosted correctly, then these test will work.
make test
Maintenance
Docker Build
Docker image build process for containerizing code and test.
make docker-build